st: clean up some if-statment code
[mesa.git] / src / mesa / state_tracker / st_cb_rasterpos.c
index 9e20e94dc7cee4fa25e8c08eb413fcf2921cabd6..7dd235273998705eac5e3c00402cf3e34829ba1b 100644 (file)
 
 #include "main/imports.h"
 #include "main/macros.h"
+#include "main/feedback.h"
 
 #include "st_context.h"
 #include "st_atom.h"
 #include "st_draw.h"
 #include "st_cb_rasterpos.h"
 #include "st_draw.h"
-#include "pipe/draw/draw_context.h"
-#include "pipe/draw/draw_private.h"
+#include "draw/draw_context.h"
+#include "draw/draw_pipe.h"
 #include "shader/prog_instruction.h"
 #include "vbo/vbo.h"
 
@@ -73,13 +74,7 @@ rastpos_stage( struct draw_stage *stage )
 }
 
 static void
-rastpos_begin( struct draw_stage *stage )
-{
-   /* no-op */
-}
-
-static void
-rastpos_end( struct draw_stage *stage )
+rastpos_flush( struct draw_stage *stage, unsigned flags )
 {
    /* no-op */
 }
@@ -107,7 +102,7 @@ rastpos_line( struct draw_stage *stage, struct prim_header *prim )
 static void
 rastpos_destroy(struct draw_stage *stage)
 {
-   free(stage);
+   _mesa_free(stage);
 }
 
 
@@ -140,7 +135,7 @@ rastpos_point(struct draw_stage *stage, struct prim_header *prim)
    struct rastpos_stage *rs = rastpos_stage(stage);
    GLcontext *ctx = rs->ctx;
    struct st_context *st = ctx->st;
-   const GLfloat height = ctx->DrawBuffer->Height;
+   const GLfloat height = (GLfloat) ctx->DrawBuffer->Height;
    const GLuint *outputMapping = st->vertex_result_to_slot;
    const GLfloat *pos;
    GLuint i;
@@ -151,7 +146,10 @@ rastpos_point(struct draw_stage *stage, struct prim_header *prim)
    /* update raster pos */
    pos = prim->v[0]->data[0];
    ctx->Current.RasterPos[0] = pos[0];
-   ctx->Current.RasterPos[1] = height - 1 - pos[1];
+   if (st_fb_orientation(ctx->DrawBuffer) == Y_0_TOP)
+      ctx->Current.RasterPos[1] = height - pos[1]; /* invert Y */
+   else
+      ctx->Current.RasterPos[1] = pos[1];
    ctx->Current.RasterPos[2] = pos[2];
    ctx->Current.RasterPos[3] = pos[3];
 
@@ -164,11 +162,15 @@ rastpos_point(struct draw_stage *stage, struct prim_header *prim)
                  ctx->Current.RasterSecondaryColor,
                  VERT_RESULT_COL1, VERT_ATTRIB_COLOR1);
 
-   for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
+   for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
       update_attrib(ctx, outputMapping, prim->v[0],
                     ctx->Current.RasterTexCoords[i],
                     VERT_RESULT_TEX0 + i, VERT_ATTRIB_TEX0 + i);
    }
+
+   if (ctx->RenderMode == GL_SELECT) {
+      _mesa_update_hitflag( ctx, ctx->Current.RasterPos[2] );
+   }
 }
 
 
@@ -178,16 +180,15 @@ rastpos_point(struct draw_stage *stage, struct prim_header *prim)
 static struct rastpos_stage *
 new_draw_rastpos_stage(GLcontext *ctx, struct draw_context *draw)
 {
-   struct rastpos_stage *rs = CALLOC_STRUCT(rastpos_stage);
+   struct rastpos_stage *rs = ST_CALLOC_STRUCT(rastpos_stage);
    GLuint i;
 
    rs->stage.draw = draw;
    rs->stage.next = NULL;
-   rs->stage.begin = rastpos_begin;
    rs->stage.point = rastpos_point;
    rs->stage.line = rastpos_line;
    rs->stage.tri = rastpos_tri;
-   rs->stage.end = rastpos_end;
+   rs->stage.flush = rastpos_flush;
    rs->stage.destroy = rastpos_destroy;
    rs->stage.reset_stipple_counter = rastpos_reset_stipple_counter;
    rs->stage.destroy = rastpos_destroy;