Drop GLcontext typedef and use struct gl_context instead
[mesa.git] / src / mesa / vbo / vbo_rebase.c
index 3bf7ef580fc273be2c29bacf4c63614b70e1debc..9068ae240a6bae1361dc8e3ebbc1352825edc9e5 100644 (file)
@@ -85,6 +85,18 @@ GLboolean vbo_all_varyings_in_vbos( const struct gl_client_array *arrays[] )
    return GL_TRUE;
 }
 
+GLboolean vbo_any_varyings_in_vbos( const struct gl_client_array *arrays[] )
+{
+   GLuint i;
+
+   for (i = 0; i < VERT_ATTRIB_MAX; i++)
+      if (arrays[i]->StrideB &&
+         arrays[i]->BufferObj->Name != 0)
+        return GL_TRUE;
+
+   return GL_FALSE;
+}
+
 /* Adjust primitives, indices and vertex definitions so that min_index
  * becomes zero. There are lots of reasons for wanting to do this, eg:
  *
@@ -104,7 +116,7 @@ GLboolean vbo_all_varyings_in_vbos( const struct gl_client_array *arrays[] )
  *    - can't save time by trying to upload half a vbo - typically it is
  *      all or nothing.
  */
-void vbo_rebase_prims( GLcontext *ctx,
+void vbo_rebase_prims( struct gl_context *ctx,
                       const struct gl_client_array *arrays[],
                       const struct _mesa_prim *prim,
                       GLuint nr_prims,
@@ -124,9 +136,25 @@ void vbo_rebase_prims( GLcontext *ctx,
    assert(min_index != 0);
 
    if (0)
-      _mesa_printf("%s %d..%d\n", __FUNCTION__, min_index, max_index);
+      printf("%s %d..%d\n", __FUNCTION__, min_index, max_index);
+
 
-   if (ib) {
+   /* XXX this path is disabled for now.
+    * There's rendering corruption in some apps when it's enabled.
+    */
+   if (0 && ib && ctx->Extensions.ARB_draw_elements_base_vertex) {
+      /* If we can just tell the hardware or the TNL to interpret our
+       * indices with a different base, do so.
+       */
+      tmp_prims = (struct _mesa_prim *)malloc(sizeof(*prim) * nr_prims);
+
+      for (i = 0; i < nr_prims; i++) {
+        tmp_prims[i] = prim[i];
+        tmp_prims[i].basevertex -= min_index;
+      }
+
+      prim = tmp_prims;
+   } else if (ib) {
       /* Unfortunately need to adjust each index individually.
        */
       GLboolean map_ib = ib->obj->Name && !ib->obj->Pointer;
@@ -171,7 +199,7 @@ void vbo_rebase_prims( GLcontext *ctx,
    else {
       /* Otherwise the primitives need adjustment.
        */
-      tmp_prims = (struct _mesa_prim *)_mesa_malloc(sizeof(*prim) * nr_prims);
+      tmp_prims = (struct _mesa_prim *)malloc(sizeof(*prim) * nr_prims);
 
       for (i = 0; i < nr_prims; i++) {
         /* If this fails, it could indicate an application error:
@@ -213,10 +241,10 @@ void vbo_rebase_prims( GLcontext *ctx,
         max_index - min_index );
    
    if (tmp_indices)
-      _mesa_free(tmp_indices);
+      free(tmp_indices);
    
    if (tmp_prims)
-      _mesa_free(tmp_prims);
+      free(tmp_prims);
 }