]> git.cworth.org Git - apitrace/blobdiff - helpers/glsize.hpp
gltrace: Respect all string length parameters.
[apitrace] / helpers / glsize.hpp
index 77ff8f09fdff65609e71c58a138f224f6a99aa09..9821b8fb40cb5166f316d27dca9bfbd6cd7a614a 100644 (file)
@@ -816,31 +816,44 @@ _glClearBuffer_size(GLenum buffer)
 }
 
 
-template<class T>
+/**
+ * Helper function for determining the string lengths for glShaderSource and
+ * glShaderSourceARB, which is a tad too complex to inline in the specs.
+ */
+template<class Char>
 static inline size_t
-_glStrLen(const T * string, GLsizei length)
+_glShaderSource_length(const Char * const * string, const GLint *length, GLsizei index)
 {
-    if (length >= 0) {
-        return length;
+    if (length != NULL && length[index] >= 0) {
+        return (size_t)length[index];
     } else {
-        return strlen(string);
+        return strlen(string[index]);
     }
 }
 
-
 /**
- * Helper function for determining the string lengths for glShaderSource and
- * glShaderSourceARB, which is a tad too complex to inline in the specs.
+ * Helper function for determining the string lengths for glGetDebugMessageLog*.
  */
-template<class T>
+template<class Char>
 static inline size_t
-_glShaderSource_length(const T * const * string, const GLint *length, GLsizei index)
+_glGetDebugMessageLog_length(const Char * string, const GLsizei *lengths, GLuint count)
 {
-    if (length != NULL && length[index] >= 0) {
-        return (size_t)length[index];
+    size_t size = 0;
+    GLuint index;
+    if (lengths) {
+        for (index = 0; index < count; ++index) {
+            size += lengths[index];
+        }
     } else {
-        return strlen(string[index]);
+        for (index = 0; index < count; ++index) {
+            size += strlen(&string[size]) + 1;
+        }
     }
+    if (size) {
+        // Remove the last null terminator
+        --size;
+    }
+    return size;
 }
 
 /*