Move compiler.h and imports.h/c from src/mesa/main into src/util
[mesa.git] / src / mesa / state_tracker / st_cb_rasterpos.c
index 747b41464ae9dace1ca11744c3941f9c4f146065..823fb2005876d37c709d55278d70b786ee6ed1c1 100644 (file)
  */
 
 
-#include "main/imports.h"
+#include "util/imports.h"
 #include "main/macros.h"
+#include "main/arrayobj.h"
 #include "main/feedback.h"
 #include "main/rastpos.h"
+#include "main/state.h"
+#include "main/varray.h"
 
 #include "st_context.h"
 #include "st_atom.h"
 #include "st_draw.h"
+#include "st_program.h"
 #include "st_cb_rasterpos.h"
+#include "st_util.h"
 #include "draw/draw_context.h"
 #include "draw/draw_pipe.h"
 #include "vbo/vbo.h"
@@ -59,8 +64,7 @@ struct rastpos_stage
    struct gl_context *ctx;            /**< Rendering context */
 
    /* vertex attrib info we can setup once and re-use */
-   struct gl_client_array array[VERT_ATTRIB_MAX];
-   const struct gl_client_array *arrays[VERT_ATTRIB_MAX];
+   struct gl_vertex_array_object *VAO;
    struct _mesa_prim prim;
 };
 
@@ -100,6 +104,8 @@ rastpos_line( struct draw_stage *stage, struct prim_header *prim )
 static void
 rastpos_destroy(struct draw_stage *stage)
 {
+   struct rastpos_stage *rstage = (struct rastpos_stage*)stage;
+   _mesa_reference_vao(rstage->ctx, &rstage->VAO, NULL);
    free(stage);
 }
 
@@ -109,7 +115,7 @@ rastpos_destroy(struct draw_stage *stage)
  * else copy the current attrib.
  */
 static void
-update_attrib(struct gl_context *ctx, const GLuint *outputMapping,
+update_attrib(struct gl_context *ctx, const ubyte *outputMapping,
               const struct vertex_header *vert,
               GLfloat *dest,
               GLuint result, GLuint defaultAttrib)
@@ -134,7 +140,8 @@ rastpos_point(struct draw_stage *stage, struct prim_header *prim)
    struct gl_context *ctx = rs->ctx;
    struct st_context *st = st_context(ctx);
    const GLfloat height = (GLfloat) ctx->DrawBuffer->Height;
-   const GLuint *outputMapping = st->vertex_result_to_slot;
+   struct st_vertex_program *stvp = (struct st_vertex_program *)st->vp;
+   const ubyte *outputMapping = stvp->result_to_output;
    const GLfloat *pos;
    GLuint i;
 
@@ -179,7 +186,6 @@ static struct rastpos_stage *
 new_draw_rastpos_stage(struct gl_context *ctx, struct draw_context *draw)
 {
    struct rastpos_stage *rs = ST_CALLOC_STRUCT(rastpos_stage);
-   GLuint i;
 
    rs->stage.draw = draw;
    rs->stage.next = NULL;
@@ -192,24 +198,15 @@ new_draw_rastpos_stage(struct gl_context *ctx, struct draw_context *draw)
    rs->stage.destroy = rastpos_destroy;
    rs->ctx = ctx;
 
-   for (i = 0; i < ARRAY_SIZE(rs->array); i++) {
-      rs->array[i].Size = 4;
-      rs->array[i].Type = GL_FLOAT;
-      rs->array[i].Format = GL_RGBA;
-      rs->array[i].Stride = 0;
-      rs->array[i].StrideB = 0;
-      rs->array[i].Ptr = (GLubyte *) ctx->Current.Attrib[i];
-      rs->array[i].Enabled = GL_TRUE;
-      rs->array[i].Normalized = GL_TRUE;
-      rs->array[i].BufferObj = NULL;
-      rs->arrays[i] = &rs->array[i];
-   }
+   rs->VAO = _mesa_new_vao(ctx, ~((GLuint)0));
+   _mesa_vertex_attrib_binding(ctx, rs->VAO, VERT_ATTRIB_POS, 0);
+   _mesa_update_array_format(ctx, rs->VAO, VERT_ATTRIB_POS, 4, GL_FLOAT,
+                             GL_RGBA, GL_FALSE, GL_FALSE, GL_FALSE, 0);
+   _mesa_enable_vertex_array_attrib(ctx, rs->VAO, 0);
 
    rs->prim.mode = GL_POINTS;
-   rs->prim.indexed = 0;
    rs->prim.begin = 1;
    rs->prim.end = 1;
-   rs->prim.weak = 0;
    rs->prim.start = 0;
    rs->prim.count = 1;
 
@@ -221,9 +218,11 @@ static void
 st_RasterPos(struct gl_context *ctx, const GLfloat v[4])
 {
    struct st_context *st = st_context(ctx);
-   struct draw_context *draw = st->draw;
+   struct draw_context *draw = st_get_draw_context(st);
    struct rastpos_stage *rs;
-   const struct gl_client_array **saved_arrays = ctx->Array._DrawArrays;
+
+   if (!st->draw)
+      return;
 
    if (ctx->VertexProgram._Current == NULL ||
        ctx->VertexProgram._Current == ctx->VertexProgram._TnlProgram) {
@@ -248,7 +247,7 @@ st_RasterPos(struct gl_context *ctx, const GLfloat v[4])
    draw_set_rasterize_stage(st->draw, st->rastpos_stage);
 
    /* make sure everything's up to date */
-   st_validate_state(st);
+   st_validate_state(st, ST_PIPELINE_RENDER);
 
    /* This will get set only if rastpos_point(), above, gets called */
    ctx->Current.RasterPosValid = GL_FALSE;
@@ -256,16 +255,13 @@ st_RasterPos(struct gl_context *ctx, const GLfloat v[4])
    /* All vertex attribs but position were previously initialized above.
     * Just plug in position pointer now.
     */
-   rs->array[0].Ptr = (GLubyte *) v;
-
-   /* Draw the point.
-    *
-    * Don't set DriverFlags.NewArray.
-    * st_feedback_draw_vbo doesn't check for that flag. */
-   ctx->Array._DrawArrays = rs->arrays;
-   st_feedback_draw_vbo(ctx, &rs->prim, 1, NULL, GL_TRUE, 0, 1,
-                        NULL, 0, NULL);
-   ctx->Array._DrawArrays = saved_arrays;
+   rs->VAO->VertexAttrib[VERT_ATTRIB_POS].Ptr = (GLubyte *) v;
+   rs->VAO->NewArrays |= VERT_BIT_POS;
+   _mesa_set_draw_vao(ctx, rs->VAO, VERT_BIT_POS);
+
+   /* Draw the point. */
+   st_feedback_draw_vbo(ctx, &rs->prim, 1, NULL, GL_TRUE, 0, 1, 1, 0,
+                        NULL, 0);
 
    /* restore draw's rasterization stage depending on rendermode */
    if (ctx->RenderMode == GL_FEEDBACK) {