Merge commit 'origin/gallium-0.1' into gallium-0.2
[mesa.git] / src / mesa / vbo / vbo_exec_draw.c
index 1d095c772f959cf42d1850d87f16e6fdb93fbe08..5bf3d836db57224b8bc11d45ccc12cdc2c613e93 100644 (file)
@@ -150,6 +150,7 @@ static void vbo_exec_bind_arrays( GLcontext *ctx )
    GLubyte *data = exec->vtx.buffer_map;
    const GLuint *map;
    GLuint attr;
+   GLbitfield varying_inputs = 0x0;
 
    /* Install the default (ie Current) attributes first, then overlay
     * all active ones.
@@ -188,7 +189,18 @@ static void vbo_exec_bind_arrays( GLcontext *ctx )
          /* override the default array set above */
          exec->vtx.inputs[attr] = &arrays[attr];
 
-        arrays[attr].Ptr = (void *)data;
+         if (exec->vtx.bufferobj->Name) {
+            /* a real buffer obj: Ptr is an offset, not a pointer*/
+            int offset;
+            assert(exec->vtx.bufferobj->Pointer);  /* buf should be mapped */
+            offset = (GLbyte *) data - (GLbyte *) exec->vtx.bufferobj->Pointer;
+            assert(offset >= 0);
+            arrays[attr].Ptr = (void *) offset;
+         }
+         else {
+            /* Ptr into ordinary app memory */
+            arrays[attr].Ptr = (void *) data;
+         }
         arrays[attr].Size = exec->vtx.attrsz[src];
         arrays[attr].StrideB = exec->vtx.vertex_size * sizeof(GLfloat);
         arrays[attr].Stride = exec->vtx.vertex_size * sizeof(GLfloat);
@@ -200,8 +212,11 @@ static void vbo_exec_bind_arrays( GLcontext *ctx )
         arrays[attr]._MaxElement = count; /* ??? */
 
         data += exec->vtx.attrsz[src] * sizeof(GLfloat);
+         varying_inputs |= 1<<attr;
       }
    }
+
+   _mesa_set_varying_vp_inputs( ctx, varying_inputs );
 }
 
 
@@ -231,8 +246,14 @@ void vbo_exec_vtx_flush( struct vbo_exec_context *exec )
          */
         vbo_exec_bind_arrays( ctx );
 
-        ctx->Driver.UnmapBuffer(ctx, target, exec->vtx.bufferobj);
-        exec->vtx.buffer_map = NULL;
+         if (ctx->NewState)
+            _mesa_update_state( ctx );
+
+         /* if using a real VBO, unmap it before drawing */
+         if (exec->vtx.bufferobj->Name) {
+            ctx->Driver.UnmapBuffer(ctx, target, exec->vtx.bufferobj);
+            exec->vtx.buffer_map = NULL;
+         }
 
         vbo_context(ctx)->draw_prims( ctx, 
                                       exec->vtx.inputs, 
@@ -242,11 +263,12 @@ void vbo_exec_vtx_flush( struct vbo_exec_context *exec )
                                       0,
                                       exec->vtx.vert_count - 1);
 
-        /* Get new data:
-         */
-        ctx->Driver.BufferData(ctx, target, size, NULL, usage, exec->vtx.bufferobj);
-        exec->vtx.buffer_map
-           = ctx->Driver.MapBuffer(ctx, target, access, exec->vtx.bufferobj);
+        /* If using a real VBO, get new storage */
+         if (exec->vtx.bufferobj->Name) {
+            ctx->Driver.BufferData(ctx, target, size, NULL, usage, exec->vtx.bufferobj);
+            exec->vtx.buffer_map = 
+               ctx->Driver.MapBuffer(ctx, target, access, exec->vtx.bufferobj);
+         }
       }
    }