Merge branch 'mesa_7_5_branch'
[mesa.git] / src / gallium / auxiliary / draw / draw_pipe_wide_point.c
index ed08573382d5f115d72fe47e5176506bbe25d9ec..49034ae86a2de3160e027e3400191f9f51850905 100644 (file)
@@ -28,7 +28,8 @@
 /* Authors:  Keith Whitwell <keith@tungstengraphics.com>
  */
 
-#include "pipe/p_util.h"
+#include "util/u_math.h"
+#include "util/u_memory.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_shader_tokens.h"
 #include "draw_vs.h"
@@ -50,6 +51,8 @@ struct widepoint_stage {
    uint num_texcoords;
 
    int psize_slot;
+
+   int point_coord_fs_input;  /**< input for pointcoord (and fog) */
 };
 
 
@@ -84,6 +87,13 @@ static void set_texcoords(const struct widepoint_stage *wide,
          v->data[j][3] = tc[3];
       }
    }
+
+   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];
+   }
 }
 
 
@@ -96,6 +106,7 @@ static void widepoint_point( struct draw_stage *stage,
                              struct prim_header *header )
 {
    const struct widepoint_stage *wide = widepoint_stage(stage);
+   const unsigned pos = stage->draw->vs.position_output;
    const boolean sprite = (boolean) stage->draw->rasterizer->point_sprite;
    float half_size;
    float left_adj, right_adj, bot_adj, top_adj;
@@ -108,10 +119,10 @@ static void widepoint_point( struct draw_stage *stage,
    struct vertex_header *v2 = dup_vert(stage, header->v[0], 2);
    struct vertex_header *v3 = dup_vert(stage, header->v[0], 3);
 
-   float *pos0 = v0->data[0];
-   float *pos1 = v1->data[0];
-   float *pos2 = v2->data[0];
-   float *pos3 = v3->data[0];
+   float *pos0 = v0->data[pos];
+   float *pos1 = v1->data[pos];
+   float *pos2 = v2->data[pos];
+   float *pos3 = v3->data[pos];
 
    /* point size is either per-vertex or fixed size */
    if (wide->psize_slot >= 0) {
@@ -197,7 +208,7 @@ static void widepoint_first_point( struct draw_stage *stage,
 
    if (draw->rasterizer->point_sprite) {
       /* find vertex shader texcoord outputs */
-      const struct draw_vertex_shader *vs = draw->vertex_shader;
+      const struct draw_vertex_shader *vs = draw->vs.vertex_shader;
       uint i, j = 0;
       for (i = 0; i < vs->info.num_outputs; i++) {
          if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_GENERIC) {
@@ -207,12 +218,24 @@ 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! */
+
+      /* setup extra vp output (point coord implemented as a texcoord) */
+      draw->extra_vp_outputs.semantic_name = TGSI_SEMANTIC_GENERIC;
+      draw->extra_vp_outputs.semantic_index = 0;
+      draw->extra_vp_outputs.slot = draw->vs.num_vs_outputs;
+   }
+   else {
+      wide->point_coord_fs_input = -1;
+      draw->extra_vp_outputs.slot = 0;
    }
 
    wide->psize_slot = -1;
    if (draw->rasterizer->point_size_per_vertex) {
       /* find PSIZ vertex output */
-      const struct draw_vertex_shader *vs = draw->vertex_shader;
+      const struct draw_vertex_shader *vs = draw->vs.vertex_shader;
       uint i;
       for (i = 0; i < vs->info.num_outputs; i++) {
          if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_PSIZE) {
@@ -256,6 +279,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;