]> git.notmuchmail.org Git - apitrace/blobdiff - glsize.hpp
Implement getTime for OS X
[apitrace] / glsize.hpp
index a042a140c97785cb97664388413ce103532bea15..d81cdf1fe6071db14ac6853b6d4a3a5fa3405d62 100644 (file)
@@ -60,6 +60,7 @@ __gl_type_size(GLenum type)
     case GL_UNSIGNED_INT:
     case GL_FLOAT:
     case GL_4_BYTES:
+    case GL_FIXED:
         return 4;
     case GL_DOUBLE:
         return 8;
@@ -581,7 +582,7 @@ _align(X x, Y y) {
 }
 
 static inline size_t
-__gl_image_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth) {
+__gl_image_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth, GLboolean has_unpack_subimage) {
     unsigned num_channels = __gl_format_channels(format);
 
     unsigned bits_per_pixel;
@@ -644,12 +645,14 @@ __gl_image_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsiz
     GLint skip_pixels = 0;
     GLint skip_images = 0;
 
-    __glGetIntegerv(GL_UNPACK_ALIGNMENT,    &alignment);
-    __glGetIntegerv(GL_UNPACK_ROW_LENGTH,   &row_length);
-    __glGetIntegerv(GL_UNPACK_IMAGE_HEIGHT, &image_height);
-    __glGetIntegerv(GL_UNPACK_SKIP_ROWS,    &skip_rows);
-    __glGetIntegerv(GL_UNPACK_SKIP_PIXELS,  &skip_pixels);
-    __glGetIntegerv(GL_UNPACK_SKIP_IMAGES,  &skip_images);
+    __glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);
+    if (has_unpack_subimage) {
+        __glGetIntegerv(GL_UNPACK_ROW_LENGTH,   &row_length);
+        __glGetIntegerv(GL_UNPACK_IMAGE_HEIGHT, &image_height);
+        __glGetIntegerv(GL_UNPACK_SKIP_ROWS,    &skip_rows);
+        __glGetIntegerv(GL_UNPACK_SKIP_PIXELS,  &skip_pixels);
+        __glGetIntegerv(GL_UNPACK_SKIP_IMAGES,  &skip_images);
+    }
 
     if (row_length <= 0) {
         row_length = width;
@@ -681,9 +684,10 @@ __gl_image_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsiz
     return size;
 }
 
-#define __glTexImage3D_size(format, type, width, height, depth) __gl_image_size(format, type, width, height, depth)
-#define __glTexImage2D_size(format, type, width, height)        __gl_image_size(format, type, width, height, 1)
-#define __glTexImage1D_size(format, type, width)                __gl_image_size(format, type, width, 1, 1)
+// note that can_unpack_subimage() is generated by gltrace.py
+#define __glTexImage3D_size(format, type, width, height, depth) __gl_image_size(format, type, width, height, depth, can_unpack_subimage())
+#define __glTexImage2D_size(format, type, width, height)        __gl_image_size(format, type, width, height, 1, can_unpack_subimage())
+#define __glTexImage1D_size(format, type, width)                __gl_image_size(format, type, width, 1, 1, can_unpack_subimage())
 
 #define __glTexSubImage3D_size(format, type, width, height, depth) __glTexImage3D_size(format, type, width, height, depth)
 #define __glTexSubImage2D_size(format, type, width, height)        __glTexImage2D_size(format, type, width, height)
@@ -740,18 +744,18 @@ __glClearBuffer_size(GLenum buffer)
 }
 
 /* 
- * 0 terminated integer/float attribute list.
+ * attribute list, terminated by the given terminator.
  */
 template<class T>
 static inline size_t
-__AttribList_size(const T *pAttribList)
+__AttribList_size(const T *pAttribList, const T terminator = static_cast<T>(0))
 {
     size_t size = 0;
 
     if (pAttribList) {
         do {
             ++size;
-        } while (*pAttribList++);
+        } while (*pAttribList++ != terminator);
     }
 
     return size;
@@ -763,15 +767,16 @@ __AttribList_size(const T *pAttribList)
  */
 template<class T>
 static inline size_t
-__AttribList_size(const T *pAttribList, T terminator)
+__AttribPairList_size(const T *pAttribList, const T terminator = static_cast<T>(0))
 {
     size_t size = 0;
 
     if (pAttribList) {
-        while (pAttribList[size] != terminator)
+        while (pAttribList[size] != terminator) {
             size += 2;
+        }
         // terminator also counts
-        size++;
+        ++size;
     }
 
     return size;