Go to the source code of this file.
Data Structures | |
struct | offset_stage |
polygon offset state More... | |
Functions | |
static struct offset_stage * | offset_stage (struct draw_stage *stage) |
static void | do_offset_tri (struct draw_stage *stage, struct prim_header *header) |
Offset tri Z. | |
static void | offset_tri (struct draw_stage *stage, struct prim_header *header) |
static void | offset_first_tri (struct draw_stage *stage, struct prim_header *header) |
static void | offset_flush (struct draw_stage *stage, unsigned flags) |
static void | offset_reset_stipple_counter (struct draw_stage *stage) |
static void | offset_destroy (struct draw_stage *stage) |
struct draw_stage * | draw_offset_stage (struct draw_context *draw) |
Create polygon offset drawing stage. |
static void do_offset_tri | ( | struct draw_stage * | stage, | |
struct prim_header * | header | |||
) | [static] |
Offset tri Z.
Some hardware can handle this, but not usually when doing unfilled rendering.
Definition at line 63 of file draw_pipe_offset.c.
References CLAMP, vertex_header::data, prim_header::det, draw_stage::draw, MAX2, draw_stage::next, offset(), offset_stage(), draw_context::position_output, offset_stage::scale, draw_stage::tri, offset_stage::units, prim_header::v, and draw_context::vs.
00065 { 00066 const unsigned pos = stage->draw->vs.position_output; 00067 struct offset_stage *offset = offset_stage(stage); 00068 float inv_det = 1.0f / header->det; 00069 00070 /* Window coords: 00071 */ 00072 float *v0 = header->v[0]->data[pos]; 00073 float *v1 = header->v[1]->data[pos]; 00074 float *v2 = header->v[2]->data[pos]; 00075 00076 /* edge vectors e = v0 - v2, f = v1 - v2 */ 00077 float ex = v0[0] - v2[0]; 00078 float ey = v0[1] - v2[1]; 00079 float ez = v0[2] - v2[2]; 00080 float fx = v1[0] - v2[0]; 00081 float fy = v1[1] - v2[1]; 00082 float fz = v1[2] - v2[2]; 00083 00084 /* (a,b) = cross(e,f).xy */ 00085 float a = ey*fz - ez*fy; 00086 float b = ez*fx - ex*fz; 00087 00088 float dzdx = fabsf(a * inv_det); 00089 float dzdy = fabsf(b * inv_det); 00090 00091 float zoffset = offset->units + MAX2(dzdx, dzdy) * offset->scale; 00092 00093 /* 00094 * Note: we're applying the offset and clamping per-vertex. 00095 * Ideally, the offset is applied per-fragment prior to fragment shading. 00096 */ 00097 v0[2] = CLAMP(v0[2] + zoffset, 0.0f, 1.0f); 00098 v1[2] = CLAMP(v1[2] + zoffset, 0.0f, 1.0f); 00099 v2[2] = CLAMP(v2[2] + zoffset, 0.0f, 1.0f); 00100 00101 stage->next->tri( stage->next, header ); 00102 }
struct draw_stage* draw_offset_stage | ( | struct draw_context * | draw | ) | [read] |
Create polygon offset drawing stage.
Definition at line 160 of file draw_pipe_offset.c.
References CALLOC_STRUCT, draw_stage::destroy, draw_stage::draw, draw_alloc_temp_verts(), draw_pipe_passthrough_line(), draw_pipe_passthrough_point(), draw_stage::flush, draw_stage::line, draw_stage::next, offset(), offset_destroy(), offset_first_tri(), offset_flush(), offset_reset_stipple_counter(), draw_stage::point, draw_stage::reset_stipple_counter, offset_stage::stage, and draw_stage::tri.
00161 { 00162 struct offset_stage *offset = CALLOC_STRUCT(offset_stage); 00163 if (offset == NULL) 00164 goto fail; 00165 00166 draw_alloc_temp_verts( &offset->stage, 3 ); 00167 00168 offset->stage.draw = draw; 00169 offset->stage.next = NULL; 00170 offset->stage.point = draw_pipe_passthrough_point; 00171 offset->stage.line = draw_pipe_passthrough_line; 00172 offset->stage.tri = offset_first_tri; 00173 offset->stage.flush = offset_flush; 00174 offset->stage.reset_stipple_counter = offset_reset_stipple_counter; 00175 offset->stage.destroy = offset_destroy; 00176 00177 return &offset->stage; 00178 00179 fail: 00180 if (offset) 00181 offset->stage.destroy( &offset->stage ); 00182 00183 return NULL; 00184 }
static void offset_destroy | ( | struct draw_stage * | stage | ) | [static] |
Definition at line 150 of file draw_pipe_offset.c.
References draw_free_temp_verts(), and FREE.
00151 { 00152 draw_free_temp_verts( stage ); 00153 FREE( stage ); 00154 }
static void offset_first_tri | ( | struct draw_stage * | stage, | |
struct prim_header * | header | |||
) | [static] |
Definition at line 121 of file draw_pipe_offset.c.
References draw_stage::draw, draw_context::mrd, offset(), pipe_rasterizer_state::offset_scale, offset_stage(), offset_tri(), pipe_rasterizer_state::offset_units, draw_context::rasterizer, offset_stage::scale, draw_stage::tri, and offset_stage::units.
00123 { 00124 struct offset_stage *offset = offset_stage(stage); 00125 00126 offset->units = (float) (stage->draw->rasterizer->offset_units * stage->draw->mrd); 00127 offset->scale = stage->draw->rasterizer->offset_scale; 00128 00129 stage->tri = offset_tri; 00130 stage->tri( stage, header ); 00131 }
static void offset_flush | ( | struct draw_stage * | stage, | |
unsigned | flags | |||
) | [static] |
Definition at line 136 of file draw_pipe_offset.c.
References draw_stage::flush, draw_stage::next, offset_first_tri(), and draw_stage::tri.
00138 { 00139 stage->tri = offset_first_tri; 00140 stage->next->flush( stage->next, flags ); 00141 }
static void offset_reset_stipple_counter | ( | struct draw_stage * | stage | ) | [static] |
Definition at line 144 of file draw_pipe_offset.c.
References draw_stage::next, and draw_stage::reset_stipple_counter.
00145 { 00146 stage->next->reset_stipple_counter( stage->next ); 00147 }
static struct offset_stage* offset_stage | ( | struct draw_stage * | stage | ) | [static, read] |
Definition at line 50 of file draw_pipe_offset.c.
00051 { 00052 return (struct offset_stage *) stage; 00053 }
static void offset_tri | ( | struct draw_stage * | stage, | |
struct prim_header * | header | |||
) | [static] |
Definition at line 105 of file draw_pipe_offset.c.
References prim_header::det, do_offset_tri(), dup_vert(), prim_header::flags, prim_header::pad, and prim_header::v.
00107 { 00108 struct prim_header tmp; 00109 00110 tmp.det = header->det; 00111 tmp.flags = header->flags; 00112 tmp.pad = header->pad; 00113 tmp.v[0] = dup_vert(stage, header->v[0], 0); 00114 tmp.v[1] = dup_vert(stage, header->v[1], 1); 00115 tmp.v[2] = dup_vert(stage, header->v[2], 2); 00116 00117 do_offset_tri( stage, &tmp ); 00118 }