Go to the source code of this file.
Data Structures | |
struct | cull_stage |
Drawing stage for polygon culling. More... | |
Functions | |
static struct cull_stage * | cull_stage (struct draw_stage *stage) |
static void | cull_tri (struct draw_stage *stage, struct prim_header *header) |
static void | cull_first_tri (struct draw_stage *stage, struct prim_header *header) |
static void | cull_flush (struct draw_stage *stage, unsigned flags) |
static void | cull_reset_stipple_counter (struct draw_stage *stage) |
static void | cull_destroy (struct draw_stage *stage) |
struct draw_stage * | draw_cull_stage (struct draw_context *draw) |
Create a new polygon culling stage. |
static void cull_destroy | ( | struct draw_stage * | stage | ) | [static] |
Definition at line 112 of file draw_pipe_cull.c.
References draw_free_temp_verts(), and FREE.
00113 { 00114 draw_free_temp_verts( stage ); 00115 FREE( stage ); 00116 }
static void cull_first_tri | ( | struct draw_stage * | stage, | |
struct prim_header * | header | |||
) | [static] |
Definition at line 87 of file draw_pipe_cull.c.
References pipe_rasterizer_state::cull_mode, cull_stage(), cull_tri(), draw_stage::draw, draw_context::rasterizer, draw_stage::tri, and cull_stage::winding.
00089 { 00090 struct cull_stage *cull = cull_stage(stage); 00091 00092 cull->winding = stage->draw->rasterizer->cull_mode; 00093 00094 stage->tri = cull_tri; 00095 stage->tri( stage, header ); 00096 }
static void cull_flush | ( | struct draw_stage * | stage, | |
unsigned | flags | |||
) | [static] |
Definition at line 100 of file draw_pipe_cull.c.
References cull_first_tri(), draw_stage::flush, draw_stage::next, and draw_stage::tri.
00101 { 00102 stage->tri = cull_first_tri; 00103 stage->next->flush( stage->next, flags ); 00104 }
static void cull_reset_stipple_counter | ( | struct draw_stage * | stage | ) | [static] |
Definition at line 106 of file draw_pipe_cull.c.
References draw_stage::next, and draw_stage::reset_stipple_counter.
00107 { 00108 stage->next->reset_stipple_counter( stage->next ); 00109 }
static struct cull_stage* cull_stage | ( | struct draw_stage * | stage | ) | [static, read] |
Definition at line 47 of file draw_pipe_cull.c.
00048 { 00049 return (struct cull_stage *)stage; 00050 }
static void cull_tri | ( | struct draw_stage * | stage, | |
struct prim_header * | header | |||
) | [static] |
Definition at line 55 of file draw_pipe_cull.c.
References cull_stage(), vertex_header::data, prim_header::det, draw_stage::draw, draw_stage::next, PIPE_WINDING_CCW, PIPE_WINDING_CW, draw_context::position_output, draw_stage::tri, prim_header::v, draw_context::vs, and cull_stage::winding.
00057 { 00058 const unsigned pos = stage->draw->vs.position_output; 00059 00060 /* Window coords: */ 00061 const float *v0 = header->v[0]->data[pos]; 00062 const float *v1 = header->v[1]->data[pos]; 00063 const float *v2 = header->v[2]->data[pos]; 00064 00065 /* edge vectors e = v0 - v2, f = v1 - v2 */ 00066 const float ex = v0[0] - v2[0]; 00067 const float ey = v0[1] - v2[1]; 00068 const float fx = v1[0] - v2[0]; 00069 const float fy = v1[1] - v2[1]; 00070 00071 /* det = cross(e,f).z */ 00072 header->det = ex * fy - ey * fx; 00073 00074 if (header->det != 0) { 00075 /* if (det < 0 then Z points toward camera and triangle is 00076 * counter-clockwise winding. 00077 */ 00078 unsigned winding = (header->det < 0) ? PIPE_WINDING_CCW : PIPE_WINDING_CW; 00079 00080 if ((winding & cull_stage(stage)->winding) == 0) { 00081 /* triangle is not culled, pass to next stage */ 00082 stage->next->tri( stage->next, header ); 00083 } 00084 } 00085 }
struct draw_stage* draw_cull_stage | ( | struct draw_context * | draw | ) | [read] |
Create a new polygon culling stage.
Definition at line 122 of file draw_pipe_cull.c.
References CALLOC_STRUCT, cull_destroy(), cull_first_tri(), cull_flush(), cull_reset_stipple_counter(), 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, draw_stage::point, draw_stage::reset_stipple_counter, cull_stage::stage, and draw_stage::tri.
00123 { 00124 struct cull_stage *cull = CALLOC_STRUCT(cull_stage); 00125 if (cull == NULL) 00126 goto fail; 00127 00128 if (!draw_alloc_temp_verts( &cull->stage, 0 )) 00129 goto fail; 00130 00131 cull->stage.draw = draw; 00132 cull->stage.next = NULL; 00133 cull->stage.point = draw_pipe_passthrough_point; 00134 cull->stage.line = draw_pipe_passthrough_line; 00135 cull->stage.tri = cull_first_tri; 00136 cull->stage.flush = cull_flush; 00137 cull->stage.reset_stipple_counter = cull_reset_stipple_counter; 00138 cull->stage.destroy = cull_destroy; 00139 00140 return &cull->stage; 00141 00142 fail: 00143 if (cull) 00144 cull->stage.destroy( &cull->stage ); 00145 00146 return NULL; 00147 }