gallium: rename pipe_buffer_handle to pipe_buffer, rework pipebuffer/ code
[mesa.git] / src / mesa / pipe / draw / draw_unfilled.c
index 8ee23d7493b8201777c4095b4b1cd9e95fa306d4..786826b33c1af7ffadb5430bd56affc20e72fad4 100644 (file)
 /* Authors:  Keith Whitwell <keith@tungstengraphics.com>
  */
 
-#include "main/imports.h"
+#include "pipe/p_util.h"
 #include "pipe/p_defines.h"
 #include "draw_private.h"
 
 
 struct unfilled_stage {
-   struct prim_stage stage;
+   struct draw_stage stage;
 
    /** [0] = front face, [1] = back face.
     * legal values:  PIPE_POLYGON_MODE_FILL, PIPE_POLYGON_MODE_LINE,
     * and PIPE_POLYGON_MODE_POINT,
     */
-   GLuint mode[2];
+   unsigned mode[2];
 };
 
 
-static INLINE struct unfilled_stage *unfilled_stage( struct prim_stage *stage )
+static INLINE struct unfilled_stage *unfilled_stage( struct draw_stage *stage )
 {
    return (struct unfilled_stage *)stage;
 }
 
 
-static void unfilled_begin( struct prim_stage *stage )
+static void unfilled_begin( struct draw_stage *stage )
 {
    struct unfilled_stage *unfilled = unfilled_stage(stage);
 
-   unfilled->mode[0] = stage->draw->setup.fill_ccw; /* front */
-   unfilled->mode[1] = stage->draw->setup.fill_cw;  /* back */
+   unfilled->mode[0] = stage->draw->rasterizer->fill_ccw; /* front */
+   unfilled->mode[1] = stage->draw->rasterizer->fill_cw;  /* back */
 
    stage->next->begin( stage->next );
 }
 
-static void point( struct prim_stage *stage,
+static void point( struct draw_stage *stage,
                   struct vertex_header *v0 )
 {
    struct prim_header tmp;
@@ -73,7 +73,7 @@ static void point( struct prim_stage *stage,
    stage->next->point( stage->next, &tmp );
 }
 
-static void line( struct prim_stage *stage,
+static void line( struct draw_stage *stage,
                  struct vertex_header *v0,
                  struct vertex_header *v1 )
 {
@@ -84,29 +84,35 @@ static void line( struct prim_stage *stage,
 }
 
 
-static void points( struct prim_stage *stage,
+static void points( struct draw_stage *stage,
                    struct prim_header *header )
 {
    struct vertex_header *v0 = header->v[0];
    struct vertex_header *v1 = header->v[1];
    struct vertex_header *v2 = header->v[2];
 
-   if (v0->edgeflag) point( stage, v0 );
-   if (v1->edgeflag) point( stage, v1 );
-   if (v2->edgeflag) point( stage, v2 );
+   if (header->edgeflags & 0x1) point( stage, v0 );
+   if (header->edgeflags & 0x2) point( stage, v1 );
+   if (header->edgeflags & 0x4) point( stage, v2 );
 }
 
 
-static void lines( struct prim_stage *stage,
+static void lines( struct draw_stage *stage,
                   struct prim_header *header )
 {
    struct vertex_header *v0 = header->v[0];
    struct vertex_header *v1 = header->v[1];
    struct vertex_header *v2 = header->v[2];
 
-   if (v0->edgeflag) line( stage, v0, v1 );
-   if (v1->edgeflag) line( stage, v1, v2 );
-   if (v2->edgeflag) line( stage, v2, v0 );
+#if 0
+   assert(((header->edgeflags & 0x1) >> 0) == header->v[0]->edgeflag);
+   assert(((header->edgeflags & 0x2) >> 1) == header->v[1]->edgeflag);
+   assert(((header->edgeflags & 0x4) >> 2) == header->v[2]->edgeflag);
+#endif
+
+   if (header->edgeflags & 0x1) line( stage, v0, v1 );
+   if (header->edgeflags & 0x2) line( stage, v1, v2 );
+   if (header->edgeflags & 0x4) line( stage, v2, v0 );
 }
 
 
@@ -115,11 +121,11 @@ static void lines( struct prim_stage *stage,
  * Note edgeflags in the vertex struct is not sufficient as we will
  * need to manipulate them when decomposing primitives???
  */
-static void unfilled_tri( struct prim_stage *stage,
+static void unfilled_tri( struct draw_stage *stage,
                          struct prim_header *header )
 {
    struct unfilled_stage *unfilled = unfilled_stage(stage);
-   GLuint mode = unfilled->mode[header->det > 0.0];
+   unsigned mode = unfilled->mode[header->det >= 0.0];
   
    switch (mode) {
    case PIPE_POLYGON_MODE_FILL:
@@ -136,30 +142,47 @@ static void unfilled_tri( struct prim_stage *stage,
    }   
 }
 
-static void unfilled_line( struct prim_stage *stage,
+static void unfilled_line( struct draw_stage *stage,
                            struct prim_header *header )
 {
    stage->next->line( stage->next, header );
 }
 
 
-static void unfilled_point( struct prim_stage *stage,
+static void unfilled_point( struct draw_stage *stage,
                             struct prim_header *header )
 {
    stage->next->point( stage->next, header );
 }
 
 
-static void unfilled_end( struct prim_stage *stage )
+static void unfilled_end( struct draw_stage *stage )
 {
    stage->next->end( stage->next );
 }
 
-struct prim_stage *prim_unfilled( struct draw_context *draw )
+
+static void unfilled_reset_stipple_counter( struct draw_stage *stage )
+{
+   stage->next->reset_stipple_counter( stage->next );
+}
+
+
+static void unfilled_destroy( struct draw_stage *stage )
+{
+   draw_free_tmps( stage );
+   FREE( stage );
+}
+
+
+/**
+ * Create unfilled triangle stage.
+ */
+struct draw_stage *draw_unfilled_stage( struct draw_context *draw )
 {
    struct unfilled_stage *unfilled = CALLOC_STRUCT(unfilled_stage);
 
-   prim_alloc_tmps( &unfilled->stage, 0 );
+   draw_alloc_tmps( &unfilled->stage, 0 );
 
    unfilled->stage.draw = draw;
    unfilled->stage.next = NULL;
@@ -169,6 +192,8 @@ struct prim_stage *prim_unfilled( struct draw_context *draw )
    unfilled->stage.line = unfilled_line;
    unfilled->stage.tri = unfilled_tri;
    unfilled->stage.end = unfilled_end;
+   unfilled->stage.reset_stipple_counter = unfilled_reset_stipple_counter;
+   unfilled->stage.destroy = unfilled_destroy;
 
    return &unfilled->stage;
 }