draw_pipe.h File Reference

Include dependency graph for draw_pipe.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  prim_header
 Basic info for a point/line/triangle primitive. More...
struct  draw_stage
 Base class for all primitive drawing stages. More...

Functions

struct draw_stagedraw_unfilled_stage (struct draw_context *context)
 Create unfilled triangle stage.
struct draw_stagedraw_twoside_stage (struct draw_context *context)
 Create twoside pipeline stage.
struct draw_stagedraw_offset_stage (struct draw_context *context)
 Create polygon offset drawing stage.
struct draw_stagedraw_clip_stage (struct draw_context *context)
 Allocate a new clipper stage.
struct draw_stagedraw_flatshade_stage (struct draw_context *context)
 Create flatshading drawing stage.
struct draw_stagedraw_cull_stage (struct draw_context *context)
 Create a new polygon culling stage.
struct draw_stagedraw_stipple_stage (struct draw_context *context)
 Create line stippler stage.
struct draw_stagedraw_wide_line_stage (struct draw_context *context)
struct draw_stagedraw_wide_point_stage (struct draw_context *context)
struct draw_stagedraw_validate_stage (struct draw_context *context)
 Create validate pipeline stage.
void draw_free_temp_verts (struct draw_stage *stage)
boolean draw_alloc_temp_verts (struct draw_stage *stage, unsigned nr)
 Allocate space for temporary post-transform vertices, such as for clipping.
void draw_reset_vertex_ids (struct draw_context *draw)
void draw_pipe_passthrough_tri (struct draw_stage *stage, struct prim_header *header)
void draw_pipe_passthrough_line (struct draw_stage *stage, struct prim_header *header)
void draw_pipe_passthrough_point (struct draw_stage *stage, struct prim_header *header)
static struct vertex_headerdup_vert (struct draw_stage *stage, const struct vertex_header *vert, unsigned idx)
 Get a writeable copy of a vertex.


Function Documentation

boolean draw_alloc_temp_verts ( struct draw_stage stage,
unsigned  nr 
)

Allocate space for temporary post-transform vertices, such as for clipping.

Definition at line 69 of file draw_pipe_util.c.

References assert, FALSE, FREE, MALLOC, MAX_VERTEX_SIZE, draw_stage::nr_tmps, draw_stage::tmp, and TRUE.

00070 {
00071    assert(!stage->tmp);
00072 
00073    stage->tmp = NULL;
00074    stage->nr_tmps = nr;
00075 
00076    if (nr != 0)
00077    {
00078       unsigned i;
00079       ubyte *store = (ubyte *) MALLOC( MAX_VERTEX_SIZE * nr );
00080 
00081       if (store == NULL)
00082          return FALSE;
00083 
00084       stage->tmp = (struct vertex_header **) MALLOC( sizeof(struct vertex_header *) * nr );
00085       if (stage->tmp == NULL) {
00086          FREE(store);
00087          return FALSE;
00088       }
00089          
00090       for (i = 0; i < nr; i++)
00091          stage->tmp[i] = (struct vertex_header *)(store + i * MAX_VERTEX_SIZE);
00092    }
00093 
00094    return TRUE;
00095 }

struct draw_stage* draw_clip_stage ( struct draw_context draw  )  [read]

Allocate a new clipper stage.

Returns:
pointer to new stage object

Definition at line 489 of file draw_pipe_clip.c.

References CALLOC_STRUCT, clip_destroy(), clip_first_line(), clip_first_tri(), clip_flush(), clip_point(), clip_reset_stipple_counter(), draw_stage::destroy, draw_stage::draw, draw_alloc_temp_verts(), draw_stage::flush, draw_stage::line, MAX_CLIPPED_VERTICES, draw_context::plane, clipper::plane, draw_stage::point, draw_stage::reset_stipple_counter, clipper::stage, and draw_stage::tri.

00490 {
00491    struct clipper *clipper = CALLOC_STRUCT(clipper);
00492    if (clipper == NULL)
00493       goto fail;
00494 
00495    if (!draw_alloc_temp_verts( &clipper->stage, MAX_CLIPPED_VERTICES+1 ))
00496       goto fail;
00497 
00498    clipper->stage.draw = draw;
00499    clipper->stage.point = clip_point;
00500    clipper->stage.line = clip_first_line;
00501    clipper->stage.tri = clip_first_tri;
00502    clipper->stage.flush = clip_flush;
00503    clipper->stage.reset_stipple_counter = clip_reset_stipple_counter;
00504    clipper->stage.destroy = clip_destroy;
00505 
00506    clipper->plane = draw->plane;
00507 
00508    return &clipper->stage;
00509 
00510  fail:
00511    if (clipper)
00512       clipper->stage.destroy( &clipper->stage );
00513 
00514    return NULL;
00515 }

struct draw_stage* draw_cull_stage ( struct draw_context context  )  [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 }

struct draw_stage* draw_flatshade_stage ( struct draw_context context  )  [read]

Create flatshading drawing stage.

Definition at line 254 of file draw_pipe_flatshade.c.

References CALLOC_STRUCT, draw_stage::destroy, draw_stage::draw, draw_alloc_temp_verts(), draw_pipe_passthrough_point(), flatshade_destroy(), flatshade_first_line(), flatshade_first_tri(), flatshade_flush(), flatshade_reset_stipple_counter(), draw_stage::flush, draw_stage::line, draw_stage::next, draw_stage::point, draw_stage::reset_stipple_counter, flat_stage::stage, and draw_stage::tri.

00255 {
00256    struct flat_stage *flatshade = CALLOC_STRUCT(flat_stage);
00257    if (flatshade == NULL)
00258       goto fail;
00259 
00260    if (!draw_alloc_temp_verts( &flatshade->stage, 2 ))
00261       goto fail;
00262 
00263    flatshade->stage.draw = draw;
00264    flatshade->stage.next = NULL;
00265    flatshade->stage.point = draw_pipe_passthrough_point;
00266    flatshade->stage.line = flatshade_first_line;
00267    flatshade->stage.tri = flatshade_first_tri;
00268    flatshade->stage.flush = flatshade_flush;
00269    flatshade->stage.reset_stipple_counter = flatshade_reset_stipple_counter;
00270    flatshade->stage.destroy = flatshade_destroy;
00271 
00272    return &flatshade->stage;
00273 
00274  fail:
00275    if (flatshade)
00276       flatshade->stage.destroy( &flatshade->stage );
00277 
00278    return NULL;
00279 }

void draw_free_temp_verts ( struct draw_stage stage  ) 

Definition at line 98 of file draw_pipe_util.c.

References FREE, and draw_stage::tmp.

00099 {
00100    if (stage->tmp) {
00101       FREE( stage->tmp[0] );
00102       FREE( stage->tmp );
00103       stage->tmp = NULL;
00104    }
00105 }

struct draw_stage* draw_offset_stage ( struct draw_context context  )  [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 }

void draw_pipe_passthrough_line ( struct draw_stage stage,
struct prim_header header 
)

Definition at line 46 of file draw_pipe_util.c.

References draw_stage::line, and draw_stage::next.

00047 {
00048    stage->next->line(stage->next, header);
00049 }

void draw_pipe_passthrough_point ( struct draw_stage stage,
struct prim_header header 
)

Definition at line 40 of file draw_pipe_util.c.

References draw_stage::next, and draw_stage::point.

00041 {
00042    stage->next->point(stage->next, header);
00043 }

void draw_pipe_passthrough_tri ( struct draw_stage stage,
struct prim_header header 
)

Definition at line 52 of file draw_pipe_util.c.

References draw_stage::next, and draw_stage::tri.

00053 {
00054    stage->next->tri(stage->next, header);
00055 }

void draw_reset_vertex_ids ( struct draw_context draw  ) 

Definition at line 112 of file draw_pipe_util.c.

References draw_context::first, draw_stage::next, draw_stage::nr_tmps, draw_context::pipeline, stride(), draw_stage::tmp, UNDEFINED_VERTEX_ID, draw_context::vertex_count, vertex_header::vertex_id, draw_context::vertex_stride, and draw_context::verts.

00113 {
00114    struct draw_stage *stage = draw->pipeline.first;
00115    
00116    while (stage) {
00117       unsigned i;
00118 
00119       for (i = 0; i < stage->nr_tmps; i++)
00120          stage->tmp[i]->vertex_id = UNDEFINED_VERTEX_ID;
00121 
00122       stage = stage->next;
00123    }
00124 
00125    if (draw->pipeline.verts)
00126    {
00127       unsigned i;
00128       char *verts = draw->pipeline.verts;
00129       unsigned stride = draw->pipeline.vertex_stride;
00130 
00131       for (i = 0; i < draw->pipeline.vertex_count; i++) {
00132          ((struct vertex_header *)verts)->vertex_id = UNDEFINED_VERTEX_ID;
00133          verts += stride;
00134       }
00135    }
00136 }

struct draw_stage* draw_stipple_stage ( struct draw_context context  )  [read]

Create line stippler stage.

Definition at line 234 of file draw_pipe_stipple.c.

References CALLOC_STRUCT, draw_stage::destroy, draw_stage::draw, draw_alloc_temp_verts(), draw_stage::flush, draw_stage::line, draw_stage::next, draw_stage::point, reset_stipple_counter(), draw_stage::reset_stipple_counter, stipple_stage::stage, stipple_destroy(), stipple_first_line(), stipple_flush(), stipple_reset_point(), stipple_reset_tri(), and draw_stage::tri.

00235 {
00236    struct stipple_stage *stipple = CALLOC_STRUCT(stipple_stage);
00237 
00238    draw_alloc_temp_verts( &stipple->stage, 2 );
00239 
00240    stipple->stage.draw = draw;
00241    stipple->stage.next = NULL;
00242    stipple->stage.point = stipple_reset_point;
00243    stipple->stage.line = stipple_first_line;
00244    stipple->stage.tri = stipple_reset_tri;
00245    stipple->stage.reset_stipple_counter = reset_stipple_counter;
00246    stipple->stage.flush = stipple_flush;
00247    stipple->stage.destroy = stipple_destroy;
00248 
00249    return &stipple->stage;
00250 }

struct draw_stage* draw_twoside_stage ( struct draw_context context  )  [read]

Create twoside pipeline stage.

Definition at line 174 of file draw_pipe_twoside.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, draw_stage::point, draw_stage::reset_stipple_counter, twoside_stage::stage, draw_stage::tri, twoside_destroy(), twoside_first_tri(), twoside_flush(), and twoside_reset_stipple_counter().

00175 {
00176    struct twoside_stage *twoside = CALLOC_STRUCT(twoside_stage);
00177    if (twoside == NULL)
00178       goto fail;
00179 
00180    if (!draw_alloc_temp_verts( &twoside->stage, 3 ))
00181       goto fail;
00182 
00183    twoside->stage.draw = draw;
00184    twoside->stage.next = NULL;
00185    twoside->stage.point = draw_pipe_passthrough_point;
00186    twoside->stage.line = draw_pipe_passthrough_line;
00187    twoside->stage.tri = twoside_first_tri;
00188    twoside->stage.flush = twoside_flush;
00189    twoside->stage.reset_stipple_counter = twoside_reset_stipple_counter;
00190    twoside->stage.destroy = twoside_destroy;
00191 
00192    return &twoside->stage;
00193 
00194  fail:
00195    if (twoside)
00196       twoside->stage.destroy( &twoside->stage );
00197 
00198    return NULL;
00199 }

struct draw_stage* draw_unfilled_stage ( struct draw_context context  )  [read]

Create unfilled triangle stage.

Definition at line 177 of file draw_pipe_unfilled.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, draw_stage::point, draw_stage::reset_stipple_counter, unfilled_stage::stage, draw_stage::tmp, draw_stage::tri, unfilled_destroy(), unfilled_first_tri(), unfilled_flush(), and unfilled_reset_stipple_counter().

00178 {
00179    struct unfilled_stage *unfilled = CALLOC_STRUCT(unfilled_stage);
00180    if (unfilled == NULL)
00181       goto fail;
00182 
00183    if (!draw_alloc_temp_verts( &unfilled->stage, 0 ))
00184       goto fail;
00185 
00186    unfilled->stage.draw = draw;
00187    unfilled->stage.next = NULL;
00188    unfilled->stage.tmp = NULL;
00189    unfilled->stage.point = draw_pipe_passthrough_point;
00190    unfilled->stage.line = draw_pipe_passthrough_line;
00191    unfilled->stage.tri = unfilled_first_tri;
00192    unfilled->stage.flush = unfilled_flush;
00193    unfilled->stage.reset_stipple_counter = unfilled_reset_stipple_counter;
00194    unfilled->stage.destroy = unfilled_destroy;
00195 
00196    return &unfilled->stage;
00197 
00198  fail:
00199    if (unfilled)
00200       unfilled->stage.destroy( &unfilled->stage );
00201 
00202    return NULL;
00203 }

struct draw_stage* draw_validate_stage ( struct draw_context context  )  [read]

Create validate pipeline stage.

Definition at line 314 of file draw_pipe_validate.c.

References CALLOC_STRUCT, draw_stage::destroy, draw_stage::draw, draw_stage::flush, draw_stage::line, draw_stage::next, draw_stage::point, draw_stage::reset_stipple_counter, draw_stage::tri, validate_destroy(), validate_flush(), validate_line(), validate_point(), validate_reset_stipple_counter(), and validate_tri().

00315 {
00316    struct draw_stage *stage = CALLOC_STRUCT(draw_stage);
00317    if (stage == NULL)
00318       return NULL;
00319 
00320    stage->draw = draw;
00321    stage->next = NULL;
00322    stage->point = validate_point;
00323    stage->line = validate_line;
00324    stage->tri = validate_tri;
00325    stage->flush = validate_flush;
00326    stage->reset_stipple_counter = validate_reset_stipple_counter;
00327    stage->destroy = validate_destroy;
00328 
00329    return stage;
00330 }

struct draw_stage* draw_wide_line_stage ( struct draw_context context  )  [read]

Definition at line 164 of file draw_pipe_wide_line.c.

References CALLOC_STRUCT, draw_stage::destroy, draw_stage::draw, draw_alloc_temp_verts(), draw_pipe_passthrough_point(), draw_pipe_passthrough_tri(), draw_stage::flush, draw_stage::line, draw_stage::next, draw_stage::point, draw_stage::reset_stipple_counter, wideline_stage::stage, draw_stage::tri, wideline_destroy(), wideline_flush(), wideline_line(), and wideline_reset_stipple_counter().

00165 {
00166    struct wideline_stage *wide = CALLOC_STRUCT(wideline_stage);
00167 
00168    draw_alloc_temp_verts( &wide->stage, 4 );
00169 
00170    wide->stage.draw = draw;
00171    wide->stage.next = NULL;
00172    wide->stage.point = draw_pipe_passthrough_point;
00173    wide->stage.line = wideline_line;
00174    wide->stage.tri = draw_pipe_passthrough_tri;
00175    wide->stage.flush = wideline_flush;
00176    wide->stage.reset_stipple_counter = wideline_reset_stipple_counter;
00177    wide->stage.destroy = wideline_destroy;
00178 
00179    return &wide->stage;
00180 }

struct draw_stage* draw_wide_point_stage ( struct draw_context context  )  [read]

Definition at line 272 of file draw_pipe_wide_point.c.

References CALLOC_STRUCT, draw_stage::destroy, draw_stage::draw, draw_alloc_temp_verts(), draw_pipe_passthrough_line(), draw_pipe_passthrough_tri(), draw_stage::flush, draw_stage::line, draw_stage::next, draw_stage::point, draw_stage::reset_stipple_counter, widepoint_stage::stage, draw_stage::tri, widepoint_destroy(), widepoint_first_point(), widepoint_flush(), and widepoint_reset_stipple_counter().

00273 {
00274    struct widepoint_stage *wide = CALLOC_STRUCT(widepoint_stage);
00275    if (wide == NULL)
00276       goto fail;
00277 
00278    if (!draw_alloc_temp_verts( &wide->stage, 4 ))
00279       goto fail;
00280 
00281    wide->stage.draw = draw;
00282    wide->stage.next = NULL;
00283    wide->stage.point = widepoint_first_point;
00284    wide->stage.line = draw_pipe_passthrough_line;
00285    wide->stage.tri = draw_pipe_passthrough_tri;
00286    wide->stage.flush = widepoint_flush;
00287    wide->stage.reset_stipple_counter = widepoint_reset_stipple_counter;
00288    wide->stage.destroy = widepoint_destroy;
00289 
00290    return &wide->stage;
00291 
00292  fail:
00293    if (wide)
00294       wide->stage.destroy( &wide->stage );
00295    
00296    return NULL;
00297 }

static struct vertex_header* dup_vert ( struct draw_stage stage,
const struct vertex_header vert,
unsigned  idx 
) [static, read]

Get a writeable copy of a vertex.

Parameters:
stage drawing stage info
vert the vertex to copy (source)
idx index into stage's tmp[] array to put the copy (dest)
Returns:
pointer to the copied vertex

Definition at line 113 of file draw_pipe.h.

References draw_stage::tmp, UNDEFINED_VERTEX_ID, and vertex_header::vertex_id.

00116 {   
00117    struct vertex_header *tmp = stage->tmp[idx];
00118    const uint vsize = sizeof(struct vertex_header)
00119       + stage->draw->vs.num_vs_outputs * 4 * sizeof(float);
00120    memcpy(tmp, vert, vsize);
00121    tmp->vertex_id = UNDEFINED_VERTEX_ID;
00122    return tmp;
00123 }


Generated on Tue Sep 29 06:25:19 2009 for Gallium3D by  doxygen 1.5.4