draw_pipe_wide_line.c File Reference

Include dependency graph for draw_pipe_wide_line.c:

Go to the source code of this file.

Data Structures

struct  wideline_stage

Functions

static struct wideline_stagewideline_stage (struct draw_stage *stage)
static void wideline_line (struct draw_stage *stage, struct prim_header *header)
 Draw a wide line by drawing a quad (two triangles).
static void wideline_flush (struct draw_stage *stage, unsigned flags)
static void wideline_reset_stipple_counter (struct draw_stage *stage)
static void wideline_destroy (struct draw_stage *stage)
struct draw_stagedraw_wide_line_stage (struct draw_context *draw)


Function Documentation

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

static void wideline_destroy ( struct draw_stage stage  )  [static]

Definition at line 157 of file draw_pipe_wide_line.c.

References draw_free_temp_verts(), and FREE.

00158 {
00159    draw_free_temp_verts( stage );
00160    FREE( stage );
00161 }

static void wideline_flush ( struct draw_stage stage,
unsigned  flags 
) [static]

Definition at line 145 of file draw_pipe_wide_line.c.

References draw_stage::flush, and draw_stage::next.

00146 {
00147    stage->next->flush( stage->next, flags );
00148 }

static void wideline_line ( struct draw_stage stage,
struct prim_header header 
) [static]

Draw a wide line by drawing a quad (two triangles).

XXX need to disable polygon stipple.

Definition at line 58 of file draw_pipe_wide_line.c.

References vertex_header::data, prim_header::det, draw_stage::draw, dup_vert(), pipe_rasterizer_state::line_width, draw_stage::next, draw_context::position_output, draw_context::rasterizer, draw_stage::tri, prim_header::v, and draw_context::vs.

00060 {
00061    /*const struct wideline_stage *wide = wideline_stage(stage);*/
00062    const unsigned pos = stage->draw->vs.position_output;
00063    const float half_width = 0.5f * stage->draw->rasterizer->line_width;
00064 
00065    struct prim_header tri;
00066 
00067    struct vertex_header *v0 = dup_vert(stage, header->v[0], 0);
00068    struct vertex_header *v1 = dup_vert(stage, header->v[0], 1);
00069    struct vertex_header *v2 = dup_vert(stage, header->v[1], 2);
00070    struct vertex_header *v3 = dup_vert(stage, header->v[1], 3);
00071 
00072    float *pos0 = v0->data[pos];
00073    float *pos1 = v1->data[pos];
00074    float *pos2 = v2->data[pos];
00075    float *pos3 = v3->data[pos];
00076 
00077    const float dx = fabsf(pos0[0] - pos2[0]);
00078    const float dy = fabsf(pos0[1] - pos2[1]);
00079 
00080    /* small tweak to meet GL specification */
00081    const float bias = 0.125f;
00082 
00083    /*
00084     * Draw wide line as a quad (two tris) by "stretching" the line along
00085     * X or Y.
00086     * We need to tweak coords in several ways to be conformant here.
00087     */
00088 
00089    if (dx > dy) {
00090       /* x-major line */
00091       pos0[1] = pos0[1] - half_width - bias;
00092       pos1[1] = pos1[1] + half_width - bias;
00093       pos2[1] = pos2[1] - half_width - bias;
00094       pos3[1] = pos3[1] + half_width - bias;
00095       if (pos0[0] < pos2[0]) {
00096          /* left to right line */
00097          pos0[0] -= 0.5f;
00098          pos1[0] -= 0.5f;
00099          pos2[0] -= 0.5f;
00100          pos3[0] -= 0.5f;
00101       }
00102       else {
00103          /* right to left line */
00104          pos0[0] += 0.5f;
00105          pos1[0] += 0.5f;
00106          pos2[0] += 0.5f;
00107          pos3[0] += 0.5f;
00108       }
00109    }
00110    else {
00111       /* y-major line */
00112       pos0[0] = pos0[0] - half_width + bias;
00113       pos1[0] = pos1[0] + half_width + bias;
00114       pos2[0] = pos2[0] - half_width + bias;
00115       pos3[0] = pos3[0] + half_width + bias;
00116       if (pos0[1] < pos2[1]) {
00117          /* top to bottom line */
00118          pos0[1] -= 0.5f;
00119          pos1[1] -= 0.5f;
00120          pos2[1] -= 0.5f;
00121          pos3[1] -= 0.5f;
00122       }
00123       else {
00124          /* bottom to top line */
00125          pos0[1] += 0.5f;
00126          pos1[1] += 0.5f;
00127          pos2[1] += 0.5f;
00128          pos3[1] += 0.5f;
00129       }
00130    }
00131 
00132    tri.det = header->det;  /* only the sign matters */
00133    tri.v[0] = v0;
00134    tri.v[1] = v2;
00135    tri.v[2] = v3;
00136    stage->next->tri( stage->next, &tri );
00137 
00138    tri.v[0] = v0;
00139    tri.v[1] = v3;
00140    tri.v[2] = v1;
00141    stage->next->tri( stage->next, &tri );
00142 }

static void wideline_reset_stipple_counter ( struct draw_stage stage  )  [static]

Definition at line 151 of file draw_pipe_wide_line.c.

References draw_stage::next, and draw_stage::reset_stipple_counter.

00152 {
00153    stage->next->reset_stipple_counter( stage->next );
00154 }

static struct wideline_stage* wideline_stage ( struct draw_stage stage  )  [static, read]

Definition at line 47 of file draw_pipe_wide_line.c.

00048 {
00049    return (struct wideline_stage *)stage;
00050 }


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