[Mesa-dev] [PATCH 2/3] st/mesa: upload current attribs using the vbo module

Marek Olšák maraeo at gmail.com
Sun Oct 28 20:18:23 PDT 2012


---
 src/mesa/state_tracker/st_atom_array.c |   38 ++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom_array.c b/src/mesa/state_tracker/st_atom_array.c
index c96f6dc..86328e2 100644
--- a/src/mesa/state_tracker/st_atom_array.c
+++ b/src/mesa/state_tracker/st_atom_array.c
@@ -47,6 +47,7 @@
 
 #include "main/bufferobj.h"
 #include "main/glformats.h"
+#include "vbo/vbo.h"
 
 
 static GLuint double_types[4] = {
@@ -472,7 +473,6 @@ setup_non_interleaved_attribs(struct st_context *st,
       const GLuint mesaAttr = vp->index_to_input[attr];
       const struct gl_client_array *array = arrays[mesaAttr];
       struct gl_buffer_object *bufobj = array->BufferObj;
-      GLsizei stride = array->StrideB;
 
       assert(array->_ElementSize == array->Size * _mesa_sizeof_type(array->Type));
 
@@ -490,30 +490,34 @@ setup_non_interleaved_attribs(struct st_context *st,
          vbuffer[attr].buffer = stobj->buffer;
          vbuffer[attr].user_buffer = NULL;
          vbuffer[attr].buffer_offset = pointer_to_offset(array->Ptr);
+         vbuffer[attr].stride = array->StrideB; /* in bytes */
       }
-      else {
-         /* wrap user data */
-         void *ptr;
+      else if (!array->Ptr ||
+               (GLfloat*)array->Ptr == &ctx->Current.Attrib[mesaAttr][0]) {
+         struct st_buffer_object *stobj;
 
-         if (array->Ptr) {
-            ptr = (void *) array->Ptr;
-         }
-         else {
-            /* no array, use ctx->Current.Attrib[] value */
-            ptr = (void *) ctx->Current.Attrib[mesaAttr];
-            stride = 0;
-         }
+         /* current (zero-stride) attrib */
+         vbo_get_current_attrib_buffer(ctx, mesaAttr, &bufobj,
+                                       &vbuffer[attr].buffer_offset);
 
-         assert(ptr);
+         stobj = st_buffer_object(bufobj);
+         if (!stobj || !stobj->buffer) {
+            return FALSE; /* out-of-memory error probably */
+         }
 
+         vbuffer[attr].buffer = stobj->buffer;
+         vbuffer[attr].user_buffer = NULL;
+         vbuffer[attr].stride = 0;
+      }
+      else {
+         /* user buffer */
          vbuffer[attr].buffer = NULL;
-         vbuffer[attr].user_buffer = ptr;
+         vbuffer[attr].user_buffer = array->Ptr;
          vbuffer[attr].buffer_offset = 0;
+         vbuffer[attr].stride = array->StrideB;
       }
 
       /* common-case setup */
-      vbuffer[attr].stride = stride; /* in bytes */
-
       velements[attr].src_offset = 0;
       velements[attr].instance_divisor = array->InstanceDivisor;
       velements[attr].vertex_buffer_index = attr;
@@ -588,7 +592,7 @@ static void update_array(struct st_context *st)
 const struct st_tracked_state st_update_array = {
    "st_update_array",					/* name */
    {							/* dirty */
-      (_NEW_PROGRAM | _NEW_BUFFER_OBJECT),		/* mesa */
+      (_NEW_PROGRAM | _NEW_BUFFER_OBJECT | _NEW_CURRENT_ATTRIB), /* mesa */
       ST_NEW_VERTEX_ARRAYS | ST_NEW_VERTEX_PROGRAM,     /* st */
    },
    update_array						/* update */
-- 
1.7.9.5



More information about the mesa-dev mailing list