mesa: Only map the necessary buffer range in vbo_get_minmax_index
authorIan Romanick <ian.d.romanick@intel.com>
Mon, 22 Aug 2011 07:14:51 +0000 (00:14 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Tue, 23 Aug 2011 21:52:11 +0000 (14:52 -0700)
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Acked-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/mesa/vbo/vbo_exec_array.c

index 484e1a8..18719d5 100644 (file)
@@ -95,10 +95,25 @@ vbo_get_minmax_index(struct gl_context *ctx,
    GLuint i;
 
    if (_mesa_is_bufferobj(ib->obj)) {
-      const GLvoid *map =
-         ctx->Driver.MapBufferRange(ctx, 0, ib->obj->Size, GL_MAP_READ_BIT,
-                                   ib->obj);
-      indices = ADD_POINTERS(map, ib->ptr);
+      unsigned map_size;
+
+      switch (ib->type) {
+      case GL_UNSIGNED_INT:
+        map_size = count * sizeof(GLuint);
+        break;
+      case GL_UNSIGNED_SHORT:
+        map_size = count * sizeof(GLushort);
+        break;
+      case GL_UNSIGNED_BYTE:
+        map_size = count * sizeof(GLubyte);
+        break;
+      default:
+        assert(0);
+        map_size = 0;
+      }
+
+      indices = ctx->Driver.MapBufferRange(ctx, (GLsizeiptr) ib->ptr, map_size,
+                                          GL_MAP_READ_BIT, ib->obj);
    } else {
       indices = ib->ptr;
    }