Merge branch 'mesa_7_5_branch' into mesa_7_6_branch
[mesa.git] / src / gallium / auxiliary / draw / draw_pipe_wide_point.c
index e1af9e56a24f0b10c41d8d878bfe31458a794745..7d76a7dbf39e32cfc7d385e59826453a23e21f42 100644 (file)
 /* Authors:  Keith Whitwell <keith@tungstengraphics.com>
  */
 
+/**
+ * Notes on wide points and sprite mode:
+ *
+ * In wide point/sprite mode we effectively need to convert each incoming
+ * vertex into four outgoing vertices specifying the corners of a quad.
+ * Since we don't (yet) have geometry shaders, we have to handle this here
+ * in the draw module.
+ *
+ * For sprites, it also means that this is where we have to handle texcoords
+ * for the vertices of the quad.  OpenGL's GL_COORD_REPLACE state specifies
+ * if/how enabled texcoords are automatically generated for sprites.  We pass
+ * that info through gallium in the pipe_rasterizer_state::sprite_coord_mode
+ * array.
+ *
+ * Additionally, GLSL's gl_PointCoord fragment attribute has to be handled
+ * here as well.  This is basically an additional texture/generic attribute
+ * that varies .x from 0 to 1 horizontally across the point and varies .y
+ * vertically from 0 to 1 down the sprite.
+ *
+ * With geometry shaders, the state tracker could create a GS to do
+ * most/all of this.
+ */
+
+
 #include "util/u_math.h"
 #include "util/u_memory.h"
 #include "pipe/p_defines.h"
@@ -52,7 +76,7 @@ struct widepoint_stage {
 
    int psize_slot;
 
-   int point_coord_fs_input;  /**< input for pointcoord (and fog) */
+   int point_coord_fs_input;  /**< input for pointcoord */
 };
 
 
@@ -64,8 +88,6 @@ widepoint_stage( struct draw_stage *stage )
 }
 
 
-
-
 /**
  * Set the vertex texcoords for sprite mode.
  * Coords may be left untouched or set to a right-side-up or upside-down
@@ -89,10 +111,12 @@ static void set_texcoords(const struct widepoint_stage *wide,
    }
 
    if (wide->point_coord_fs_input >= 0) {
-      /* put gl_PointCoord into extra vertex output's zw components */
-      uint k = wide->stage.draw->extra_vp_outputs.slot;
-      v->data[k][2] = tc[0];
-      v->data[k][3] = tc[1];
+      /* put gl_PointCoord into the extra vertex slot */
+      uint slot = wide->stage.draw->extra_vp_outputs.slot;
+      v->data[slot][0] = tc[0];
+      v->data[slot][1] = tc[1];
+      v->data[slot][2] = 0.0F;
+      v->data[slot][3] = 1.0F;
    }
 }
 
@@ -181,6 +205,16 @@ static void widepoint_point( struct draw_stage *stage,
 }
 
 
+static int
+find_pntc_input_attrib(struct draw_context *draw)
+{
+   /* Scan the fragment program's input decls to find the pointcoord
+    * attribute.  The xy components will store the point coord.
+    */
+   return 0; /* XXX fix this */
+}
+
+
 static void widepoint_first_point( struct draw_stage *stage, 
                              struct prim_header *header )
 {
@@ -219,8 +253,8 @@ static void widepoint_first_point( struct draw_stage *stage,
       }
       wide->num_texcoords = j;
 
-      /* find fragment shader PointCoord/Fog input */
-      wide->point_coord_fs_input = 0; /* XXX fix this! */
+      /* find fragment shader PointCoord input */
+      wide->point_coord_fs_input = find_pntc_input_attrib(draw);
 
       /* setup extra vp output (point coord implemented as a texcoord) */
       draw->extra_vp_outputs.semantic_name = TGSI_SEMANTIC_GENERIC;
@@ -253,6 +287,7 @@ static void widepoint_flush( struct draw_stage *stage, unsigned flags )
 {
    stage->point = widepoint_first_point;
    stage->next->flush( stage->next, flags );
+   stage->draw->extra_vp_outputs.slot = 0;
 }
 
 
@@ -279,6 +314,7 @@ struct draw_stage *draw_wide_point_stage( struct draw_context *draw )
       goto fail;
 
    wide->stage.draw = draw;
+   wide->stage.name = "wide-point";
    wide->stage.next = NULL;
    wide->stage.point = widepoint_first_point;
    wide->stage.line = draw_pipe_passthrough_line;