s/Tungsten Graphics/VMware/
[mesa.git] / src / mesa / vbo / vbo_rebase.c
index 799a25fc1cb34a8a1ff5ed18a09f2829aaa9146e..c700621cef201bdcef9aa636720a84fa3414b128 100644 (file)
@@ -1,7 +1,6 @@
 
 /*
  * Mesa 3-D graphics library
- * Version:  6.5
  *
  * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
  *
  * 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 NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR 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.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 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.
  *
  * Authors:
- *    Keith Whitwell <keith@tungstengraphics.com>
+ *    Keith Whitwell <keithw@vmware.com>
  */
 
 /* Helper for drivers which find themselves rendering a range of
@@ -85,6 +85,17 @@ 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]->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 +115,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,
@@ -118,20 +129,24 @@ void vbo_rebase_prims( GLcontext *ctx,
 
    struct _mesa_index_buffer tmp_ib;
    struct _mesa_prim *tmp_prims = NULL;
+   const struct gl_client_array **saved_arrays = ctx->Array._DrawArrays;
    void *tmp_indices = NULL;
    GLuint i;
 
    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 && ctx->Extensions.ARB_draw_elements_base_vertex) {
+   /* 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 *)_mesa_malloc(sizeof(*prim) * nr_prims);
+      tmp_prims = malloc(sizeof(*prim) * nr_prims);
 
       for (i = 0; i < nr_prims; i++) {
         tmp_prims[i] = prim[i];
@@ -146,10 +161,8 @@ void vbo_rebase_prims( GLcontext *ctx,
       void *ptr;
 
       if (map_ib) 
-        ctx->Driver.MapBuffer(ctx, 
-                              GL_ELEMENT_ARRAY_BUFFER,
-                              GL_READ_ONLY_ARB,
-                              ib->obj);
+        ctx->Driver.MapBufferRange(ctx, 0, ib->obj->Size, GL_MAP_READ_BIT,
+                                   ib->obj);
 
 
       ptr = ADD_POINTERS(ib->obj->Pointer, ib->ptr);
@@ -170,9 +183,7 @@ void vbo_rebase_prims( GLcontext *ctx,
       }      
 
       if (map_ib) 
-        ctx->Driver.UnmapBuffer(ctx, 
-                                GL_ELEMENT_ARRAY_BUFFER,
-                                ib->obj);
+        ctx->Driver.UnmapBuffer(ctx, ib->obj);
 
       tmp_ib.obj = ctx->Shared->NullBufferObj;
       tmp_ib.ptr = tmp_indices;
@@ -184,7 +195,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 = malloc(sizeof(*prim) * nr_prims);
 
       for (i = 0; i < nr_prims; i++) {
         /* If this fails, it could indicate an application error:
@@ -216,20 +227,24 @@ void vbo_rebase_prims( GLcontext *ctx,
    
    /* Re-issue the draw call.
     */
+   ctx->Array._DrawArrays = tmp_array_pointers;
+   ctx->NewDriverState |= ctx->DriverFlags.NewArray;
+
    draw( ctx, 
-        tmp_array_pointers, 
-        prim, 
+        prim,
         nr_prims, 
         ib, 
         GL_TRUE,
         0, 
-        max_index - min_index );
+        max_index - min_index,
+        NULL, NULL );
+
+   ctx->Array._DrawArrays = saved_arrays;
+   ctx->NewDriverState |= ctx->DriverFlags.NewArray;
    
-   if (tmp_indices)
-      _mesa_free(tmp_indices);
+   free(tmp_indices);
    
-   if (tmp_prims)
-      _mesa_free(tmp_prims);
+   free(tmp_prims);
 }