]> git.cworth.org Git - apitrace/blobdiff - glsize.hpp
Accept zero valued bitmasks.
[apitrace] / glsize.hpp
index 97d0ee891517739a49ca8331528a1a3471822aae..64b96af25ee61c24728fe6bbec129b0ac513896f 100644 (file)
  *
  **************************************************************************/
 
+/*
+ * Auxiliary functions to compute the size of array/blob arguments, depending.
+ *
+ * Some of these functions were semi-automatically generated with
+ * apigen/glsize.py script from Mesa's XML description of the GL enums.
+ *
+ * Other functions were done by hand.
+ */
+
 #ifndef _GL_HELPERS_HPP_
 #define _GL_HELPERS_HPP_
 
 
-#include <cassert>
-
+#include "os.hpp"
 #include "glimports.hpp"
 
 
 static inline size_t
-__glCallLists_size(GLsizei n, GLenum type)
+__gl_type_size(GLenum type)
 {
-    size_t bytes;
-    switch(type) {
+    switch (type) {
+    case GL_BOOL:
     case GL_BYTE:
     case GL_UNSIGNED_BYTE:
-        bytes = 1;
-        break;
+        return 1;
     case GL_SHORT:
     case GL_UNSIGNED_SHORT:
     case GL_2_BYTES:
     case GL_HALF_FLOAT:
-        bytes = 2;
-        break;
+        return 2;
     case GL_3_BYTES:
-        bytes = 3;
-        break;
+        return 3;
     case GL_INT:
     case GL_UNSIGNED_INT:
     case GL_FLOAT:
     case GL_4_BYTES:
-        bytes = 4;
-        break;
+        return 4;
+    case GL_DOUBLE:
+        return 8;
     default:
-        assert(0);
-        bytes = 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, type);
+        return 0;
+    }
+}
+
+static inline size_t
+__glArrayPointer_size(GLint size, GLenum type, GLsizei stride, GLsizei maxIndex)
+{
+    size_t elementSize = size*__gl_type_size(type);
+    if (!stride) {
+        stride = (GLsizei)elementSize;
+    }
+    return stride*maxIndex + elementSize;
+}
+
+#define __glVertexPointer_size(size, type, stride, maxIndex) __glArrayPointer_size(size, type, stride, maxIndex)
+#define __glNormalPointer_size(type, stride, maxIndex) __glArrayPointer_size(3, type, stride, maxIndex)
+#define __glColorPointer_size(size, type, stride, maxIndex) __glArrayPointer_size(size, type, stride, maxIndex)
+#define __glIndexPointer_size(type, stride, maxIndex) __glArrayPointer_size(1, type, stride, maxIndex)
+#define __glTexCoordPointer_size(size, type, stride, maxIndex) __glArrayPointer_size(size, type, stride, maxIndex)
+#define __glEdgeFlagPointer_size(stride, maxIndex) __glArrayPointer_size(1, GL_BOOL, stride, 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)
+#define __glVertexAttribPointer_size(size, type, normalized, stride, maxIndex) __glArrayPointer_size(size, type, stride, maxIndex)
+
+static inline GLuint
+__glDrawArrays_maxindex(GLint first, GLsizei count)
+{
+    return first + count - 1;
+}
+
+static inline GLuint
+__glDrawElements_maxindex(GLsizei count, GLenum type, const GLvoid *indices)
+{
+    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 *p = (const GLubyte *)indices;
+        for (i = 0; i < count; ++i) {
+            if (p[i] > maxindex) {
+                maxindex = p[i];
+            }
+        }
+    } else if (type == GL_UNSIGNED_SHORT) {
+        const GLushort *p = (const GLushort *)indices;
+        for (i = 0; i < count; ++i) {
+            if (p[i] > maxindex) {
+                maxindex = p[i];
+            }
+        }
+    } else if (type == GL_UNSIGNED_INT) {
+        const GLuint *p = (const GLuint *)indices;
+        for (i = 0; i < count; ++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 n*bytes;
+    return maxindex;
+}
+
+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);
+}
+
+static inline size_t
+__glCallLists_size(GLsizei n, GLenum type)
+{
+    return n*__gl_type_size(type);
 }
 
 static inline size_t
@@ -82,8 +183,8 @@ __glFogfv_size(GLenum pname)
     case GL_FOG_COLOR:
         return 4;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -107,8 +208,8 @@ __glLightfv_size(GLenum pname)
     case GL_POSITION:
         return 4;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -126,8 +227,8 @@ __glLightModelfv_size(GLenum pname)
     case GL_LIGHT_MODEL_AMBIENT:
         return 4;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -148,8 +249,8 @@ __glMaterialfv_size(GLenum pname)
     case GL_AMBIENT_AND_DIFFUSE:
         return 4;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -207,8 +308,8 @@ __glTexParameterfv_size(GLenum pname)
     case GL_POST_TEXTURE_FILTER_SCALE_SGIX:
         return 4;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -247,8 +348,8 @@ __glTexEnvfv_size(GLenum pname)
     case GL_TEXTURE_ENV_COLOR:
         return 4;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -264,8 +365,8 @@ __glTexGendv_size(GLenum pname)
     case GL_EYE_PLANE:
         return 4;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -291,8 +392,8 @@ __glMap1d_size(GLenum pname)
     case GL_MAP1_VERTEX_4:
         return 4;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -316,8 +417,8 @@ __glMap2d_size(GLenum pname)
     case GL_MAP2_VERTEX_4:
         return 4;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -730,6 +831,8 @@ __glGetBooleanv_size(GLenum pname)
     case GL_DEPTH_BOUNDS_TEST_EXT:
     case GL_ARRAY_BUFFER_BINDING_ARB:
     case GL_ELEMENT_ARRAY_BUFFER_BINDING_ARB:
+    case GL_PIXEL_PACK_BUFFER_BINDING:
+    case GL_PIXEL_UNPACK_BUFFER_BINDING:
     case GL_VERTEX_ARRAY_BUFFER_BINDING_ARB:
     case GL_NORMAL_ARRAY_BUFFER_BINDING_ARB:
     case GL_COLOR_ARRAY_BUFFER_BINDING_ARB:
@@ -841,10 +944,13 @@ __glGetBooleanv_size(GLenum pname)
     case GL_MAX_VARYING_FLOATS:
     case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
     case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
+    case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS:
+    case GL_MAX_GEOMETRY_OUTPUT_VERTICES:
+    case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS:
         return 1;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -854,6 +960,8 @@ __glGetBooleanv_size(GLenum pname)
 
 #define __glGetIntegerv_size __glGetBooleanv_size
 
+#define __glGetInteger64v_size __glGetBooleanv_size
+
 #define __glGetLightfv_size __glLightfv_size
 
 #define __glGetLightiv_size __glLightfv_size
@@ -923,8 +1031,8 @@ __glGetTexParameterfv_size(GLenum pname)
     case GL_POST_TEXTURE_FILTER_SCALE_SGIX:
         return 4;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -962,8 +1070,8 @@ __glGetTexLevelParameterfv_size(GLenum pname)
 /*  case GL_TEXTURE_STENCIL_SIZE_EXT:*/
         return 1;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -977,8 +1085,8 @@ __glColorTableParameterfv_size(GLenum pname)
     case GL_COLOR_TABLE_BIAS:
         return 4;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -1009,8 +1117,8 @@ __glGetColorTableParameterfv_size(GLenum pname)
     case GL_COLOR_TABLE_BIAS:
         return 4;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -1031,8 +1139,8 @@ __glConvolutionParameterfv_size(GLenum pname)
 /*  case GL_CONVOLUTION_BORDER_COLOR_HP:*/
         return 4;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -1063,8 +1171,8 @@ __glGetConvolutionParameterfv_size(GLenum pname)
 /*  case GL_CONVOLUTION_BORDER_COLOR_HP:*/
         return 4;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -1084,8 +1192,8 @@ __glGetHistogramParameterfv_size(GLenum pname)
     case GL_HISTOGRAM_SINK:
         return 1;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -1099,8 +1207,8 @@ __glGetMinmaxParameterfv_size(GLenum pname)
     case GL_MINMAX_SINK:
         return 1;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -1155,8 +1263,8 @@ __glGetProgramivARB_size(GLenum pname)
     case GL_MAX_PROGRAM_LOOP_COUNT_NV:
         return 1;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -1173,8 +1281,8 @@ __glGetVertexAttribdvARB_size(GLenum pname)
     case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
         return 1;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -1190,8 +1298,8 @@ __glGetQueryObjectivARB_size(GLenum pname)
     case GL_QUERY_RESULT_AVAILABLE_ARB:
         return 1;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -1205,8 +1313,8 @@ __glGetQueryivARB_size(GLenum pname)
     case GL_CURRENT_QUERY_ARB:
         return 1;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -1231,13 +1339,14 @@ __glPointParameterfvEXT_size(GLenum pname)
 /*  case GL_POINT_DISTANCE_ATTENUATION_SGIS:*/
         return 3;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
 #define __glPointParameterfv_size __glPointParameterfvEXT_size
 #define __glPointParameteriv_size __glPointParameterfvEXT_size
+#define __glPointParameterfvARB_size __glPointParameterfvEXT_size
 #define __glPointParameterivNV_size __glPointParameterfvEXT_size
 
 static inline size_t
@@ -1249,8 +1358,8 @@ __glGetProgramivNV_size(GLenum pname)
     case GL_PROGRAM_RESIDENT_NV:
         return 1;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -1264,8 +1373,8 @@ __glGetVertexAttribdvNV_size(GLenum pname)
     case GL_CURRENT_ATTRIB_NV:
         return 1;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
@@ -1284,16 +1393,15 @@ __glGetFramebufferAttachmentParameterivEXT_size(GLenum pname)
     case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_3D_ZOFFSET_EXT:
         return 1;
     default:
-        assert(0);
-        return 0;
+        OS::DebugMessage("warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);
+        return 1;
     }
 }
 
 #define __glGetFramebufferAttachmentParameteriv_size __glGetFramebufferAttachmentParameterivEXT_size
 
 static inline size_t
-__glTexImage3D_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth, GLint border) {
-    size_t num_channels;
+__gl_format_channels(GLenum format) {
     switch (format) {
     case GL_COLOR_INDEX:
     case GL_RED:
@@ -1301,26 +1409,32 @@ __glTexImage3D_size(GLenum format, GLenum type, GLsizei width, GLsizei height, G
     case GL_BLUE:
     case GL_ALPHA:
     case GL_INTENSITY:
+    case GL_LUMINANCE:
     case GL_DEPTH_COMPONENT:
     case GL_STENCIL_INDEX:
-        num_channels = 1;
+        return 1;
         break;
     case GL_LUMINANCE_ALPHA:
-        num_channels = 2;
+        return 2;
         break;
     case GL_RGB:
     case GL_BGR:
-        num_channels = 3;
+        return 3;
         break;
     case GL_RGBA:
     case GL_BGRA:
-        num_channels = 4;
+        return 4;
         break;
     default:
-        assert(0);
-        num_channels = 0;
+        OS::DebugMessage("warning: %s: unexpected format GLenum 0x%04X\n", __FUNCTION__, format);
+        return 0;
         break;
     }
+}
+
+static inline size_t
+__glTexImage3D_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth, GLint border) {
+    size_t num_channels = __gl_format_channels(format);
 
     size_t bits_per_pixel;
     switch (type) {
@@ -1359,7 +1473,7 @@ __glTexImage3D_size(GLenum format, GLenum type, GLsizei width, GLsizei height, G
         bits_per_pixel = 32;
         break;
     default:
-        assert(0);
+        OS::DebugMessage("warning: %s: unexpected type GLenum 0x%04X\n", __FUNCTION__, type);
         bits_per_pixel = 0;
         break;
     }
@@ -1380,9 +1494,36 @@ __glTexImage3D_size(GLenum format, GLenum type, GLsizei width, GLsizei height, G
 #define __glTexSubImage2D_size(format, type, width, height)        __glTexImage2D_size(format, type, width, height, 0)
 #define __glTexSubImage1D_size(format, type, width)                __glTexImage1D_size(format, type, width, 0)
 
+#define __glTexImage3DEXT_size __glTexImage3D_size
+#define __glTexImage2DEXT_size __glTexImage2D_size
+#define __glTexImage1DEXT_size __glTexImage1D_size
+#define __glTexSubImage3DEXT_size __glTexSubImage3D_size
+#define __glTexSubImage2DEXT_size __glTexSubImage2D_size
+#define __glTexSubImage1DEXT_size __glTexSubImage1D_size
+
 #define __glDrawPixels_size(format, type, width, height) __glTexImage2D_size(format, type, width, height, 0)
 
 #define __glBitmap_size(width, height) __glTexImage2D_size(GL_COLOR_INDEX, GL_BITMAP, width, height, 0)
 #define __glPolygonStipple_size() __glBitmap_size(32, 32)
 
+
+/* 
+ * 0 terminated integer/float attribute list.
+ */
+template<class T>
+static inline size_t
+__AttribList_size(const T *pAttribList)
+{
+    size_t size = 0;
+
+    if (pAttribList) {
+        do {
+            ++size;
+        } while (*pAttribList++);
+    }
+
+    return size;
+}
+
+
 #endif /* _GL_HELPERS_HPP_ */