st/mesa: fix lowered IO - don't call st_nir_assign_vs_in_locations twice
[mesa.git] / src / mesa / state_tracker / st_cb_rasterpos.c
index b73d543653f245e2235df49f4a399750c01c179c..c3684176071030073ce1d4161db7f08af3368417 100644 (file)
@@ -1,8 +1,8 @@
 /**************************************************************************
- * 
+ *
  * Copyright 2007 VMware, Inc.
  * All Rights Reserved.
- * 
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the
  * "Software"), to deal in the Software without restriction, including
  * distribute, sub license, and/or sell copies of the Software, and to
  * permit persons to whom the Software is furnished to do so, subject to
  * the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice (including the
  * next paragraph) shall be included in all copies or substantial portions
  * of the Software.
- * 
+ *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
@@ -22,7 +22,7 @@
  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- * 
+ *
  **************************************************************************/
 
 /**
  */
 
 
-#include "main/imports.h"
+
 #include "main/macros.h"
+#include "main/arrayobj.h"
 #include "main/feedback.h"
 #include "main/rastpos.h"
-#include "glformats.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"
@@ -61,9 +64,7 @@ struct rastpos_stage
    struct gl_context *ctx;            /**< Rendering context */
 
    /* vertex attrib info we can setup once and re-use */
-   struct gl_vertex_buffer_binding binding;
-   struct gl_array_attributes attrib[VERT_ATTRIB_MAX];
-   struct gl_vertex_array array[VERT_ATTRIB_MAX];
+   struct gl_vertex_array_object *VAO;
    struct _mesa_prim prim;
 };
 
@@ -103,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);
 }
 
@@ -137,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 ubyte *outputMapping = st->vp->result_to_output;
+   struct st_vertex_program *stvp = (struct st_vertex_program *)st->vp;
+   const ubyte *outputMapping = stvp->result_to_output;
    const GLfloat *pos;
    GLuint i;
 
@@ -182,8 +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;
-   GLuint elementSize;
 
    rs->stage.draw = draw;
    rs->stage.next = NULL;
@@ -196,26 +198,15 @@ new_draw_rastpos_stage(struct gl_context *ctx, struct draw_context *draw)
    rs->stage.destroy = rastpos_destroy;
    rs->ctx = ctx;
 
-   rs->binding.Stride = 0;
-   rs->binding.BufferObj = NULL;
-
-   elementSize = _mesa_bytes_per_vertex_attrib(4, GL_FLOAT);
-   for (i = 0; i < ARRAY_SIZE(rs->array); i++) {
-      rs->attrib[i].Size = 4;
-      rs->attrib[i].Type = GL_FLOAT;
-      rs->attrib[i].Format = GL_RGBA;
-      rs->attrib[i].Ptr = (GLubyte *) ctx->Current.Attrib[i];
-      rs->attrib[i].Normalized = GL_TRUE;
-      rs->attrib[i]._ElementSize = elementSize;
-      rs->array[i].BufferBinding = &rs->binding;
-      rs->array[i].VertexAttrib = &rs->attrib[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;
 
@@ -229,7 +220,6 @@ st_RasterPos(struct gl_context *ctx, const GLfloat v[4])
    struct st_context *st = st_context(ctx);
    struct draw_context *draw = st_get_draw_context(st);
    struct rastpos_stage *rs;
-   const struct gl_vertex_array *saved_arrays = ctx->Array._DrawArrays;
 
    if (!st->draw)
       return;
@@ -265,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->attrib[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->array;
-   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) {