]> git.cworth.org Git - apitrace/blobdiff - glsize.hpp
Unbreak tracing glDrawElements with VBOs.
[apitrace] / glsize.hpp
index d3df4aaca6ace355040786a5495afbc8ce6976d2..8d46ea512006e4d7f73ccff772b23f408b9e31d8 100644 (file)
@@ -95,49 +95,74 @@ __glArrayPointer_size(GLint size, GLenum type, GLsizei stride, GLsizei maxIndex)
 #define __glFogCoordPointer_size(type, stride, maxIndex) __glArrayPointer_size(1, type, stride, maxIndex)
 #define __glSecondaryColorPointer_size(size, type, stride, maxIndex) __glArrayPointer_size(size, type, stride, maxIndex)
 
-static inline size_t
+static inline GLuint
 __glDrawArrays_maxindex(GLint first, GLsizei count)
 {
     return first + count - 1;
 }
 
-static inline size_t
-__glDrawElements_maxindex(GLsizei count, GLenum type, const GLvoid *_indices)
+static inline GLuint
+__glDrawElements_maxindex(GLsizei count, GLenum type, const GLvoid *indices)
 {
-    size_t maxindex = 0;
-    unsigned i;
+    GLvoid *temp = 0;
+    GLint __element_array_buffer = 0;
+    __glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &__element_array_buffer);
+    if (__element_array_buffer) {
+        // Read indices from index buffer object
+        GLintptr offset = (GLintptr)indices;
+        GLsizeiptr size = count*__gl_type_size(type);
+        GLvoid *temp = malloc(size);
+        if (!temp) {
+            return 0;
+        }
+        memset(temp, 0, size);
+        __glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, size, temp);
+        indices = temp;
+    } else {
+        if (!indices) {
+            return 0;
+        }
+    }
 
+    GLuint maxindex = 0;
+    GLsizei i;
     if (type == GL_UNSIGNED_BYTE) {
-        const GLubyte *indices = (const GLubyte *)_indices;
+        const GLubyte *p = (const GLubyte *)indices;
         for (i = 0; i < count; ++i) {
-            if (indices[i] > maxindex) {
-                maxindex = indices[i];
+            if (p[i] > maxindex) {
+                maxindex = p[i];
             }
         }
     } else if (type == GL_UNSIGNED_SHORT) {
-        const GLushort *indices = (const GLushort *)_indices;
+        const GLushort *p = (const GLushort *)indices;
         for (i = 0; i < count; ++i) {
-            if (indices[i] > maxindex) {
-                maxindex = indices[i];
+            if (p[i] > maxindex) {
+                maxindex = p[i];
             }
         }
     } else if (type == GL_UNSIGNED_INT) {
-        const GLuint *indices = (const GLuint *)_indices;
+        const GLuint *p = (const GLuint *)indices;
         for (i = 0; i < count; ++i) {
-            if (indices[i] > maxindex) {
-                maxindex = indices[i];
+            if (p[i] > maxindex) {
+                maxindex = p[i];
             }
         }
     } else {
         OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, type);
     }
 
+    if (__element_array_buffer) {
+        free(temp);
+    }
+
     return maxindex;
 }
 
-static inline size_t
+static inline GLuint
 __glDrawRangeElements_maxindex(GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid * indices)
 {
+    (void)start;
+    (void)end;
     return __glDrawElements_maxindex(count, type, indices);
 }