]> git.cworth.org Git - apitrace/commitdiff
Check extensions via glGetStringi() on core profile.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Thu, 18 Oct 2012 14:22:41 +0000 (15:22 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Thu, 18 Oct 2012 14:22:41 +0000 (15:22 +0100)
Fixes segfault on MacOSX, given that glGetString() returns NULL there.

retrace/glretrace.hpp
retrace/glretrace_main.cpp
retrace/glretrace_ws.cpp
retrace/glws.cpp
retrace/glws.hpp

index 11f4d27574dd1a05bd7ec88a001a9b64db94d44a..7729ec50a66303047136631745d22b0e34978cbb 100644 (file)
@@ -48,6 +48,12 @@ struct Context {
     glws::Context* wsContext;
     GLuint activeProgram;
     bool used;
+    
+    // Context must be current
+    inline bool
+    hasExtension(const char *extension) const {
+        return wsContext->hasExtension(extension);
+    }
 };
 
 extern bool insideList;
index 1086be9d42e72d5b26084d2964b13457e887207c..05567a22a31b6deb80989475a898effc8ad6791d 100755 (executable)
@@ -230,13 +230,12 @@ endProfile(trace::Call &call, bool isDraw) {
 
 void
 initContext() {
-    const char* extensions = (const char*)glGetString(GL_EXTENSIONS);
-
     /* Ensure we have adequate extension support */
-    supportsTimestamp   = glws::checkExtension("GL_ARB_timer_query", extensions);
-    supportsElapsed     = glws::checkExtension("GL_EXT_timer_query", extensions) || supportsTimestamp;
-    supportsOcclusion   = glws::checkExtension("GL_ARB_occlusion_query", extensions);
-    supportsDebugOutput = glws::checkExtension("GL_ARB_debug_output", extensions);
+    assert(currentContext);
+    supportsTimestamp   = currentContext->hasExtension("GL_ARB_timer_query");
+    supportsElapsed     = currentContext->hasExtension("GL_EXT_timer_query") || supportsTimestamp;
+    supportsOcclusion   = currentContext->hasExtension("GL_ARB_occlusion_query");
+    supportsDebugOutput = currentContext->hasExtension("GL_ARB_debug_output");
 
     /* Check for timer query support */
     if (retrace::profilingGpuTimes) {
index bead54ee10ea0566a471604e2a37c423f1eeb181..ccc70233a73a5b7427148732205f39cff7e51bad 100644 (file)
@@ -132,16 +132,14 @@ makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context)
         return false;
     }
 
-    if (context) {
+    if (drawable && context) {
+        currentDrawable = drawable;
+        currentContext = context;
+        
         if (!context->used) {
             initContext();
             context->used = true;
         }
-    }
-
-    if (drawable && context) {
-        currentDrawable = drawable;
-        currentContext = context;
     } else {
         currentDrawable = NULL;
         currentContext = NULL;
index 4e07ede9d227a856e0bffe091300906638771604..f89f980c5f8094928f0a5d8db391d78db792508b 100644 (file)
@@ -24,6 +24,9 @@
  **************************************************************************/
 
 
+#include <assert.h>
+
+#include "glproc.hpp"
 #include "glws.hpp"
 
 
@@ -33,26 +36,68 @@ namespace glws {
 bool
 checkExtension(const char *extName, const char *extString)
 {
-   const char *p = extString;
-   const char *q = extName;
-   char c;
-   do {
-       c = *p++;
-       if (c == '\0' || c == ' ') {
-           if (q && *q == '\0') {
-               return true;
-           } else {
-               q = extName;
-           }
-       } else {
-           if (q && *q == c) {
-               ++q;
-           } else {
-               q = 0;
-           }
-       }
-   } while (c);
-   return false;
+    assert(extName);
+    assert(extString);
+
+    const char *p = extString;
+    const char *q = extName;
+    char c;
+    do {
+        c = *p++;
+        if (c == '\0' || c == ' ') {
+            if (q && *q == '\0') {
+                return true;
+            } else {
+                q = extName;
+            }
+        } else {
+            if (q && *q == c) {
+                ++q;
+            } else {
+                q = 0;
+            }
+        }
+    } while (c);
+    return false;
+}
+
+
+bool
+Context::hasExtension(const char *string) {
+    if (extensions.empty()) {
+        if (profile == PROFILE_CORE) {
+            // Use glGetStringi
+            GLint num_extensions = 0;
+            glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions);
+            for (int i = 0; i < num_extensions; ++i) {
+                const char *extension = reinterpret_cast<const char *>(glGetStringi(GL_EXTENSIONS, i));
+                if (extension) {
+                    extensions.insert(extension);
+                }
+            }
+        } else {
+            // Use glGetString
+            const char *begin = reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS));
+            do {
+                const char *end = begin;
+                char c = *end;
+                while (c != '\0' && c != ' ') {
+                    ++end;
+                    c = *end;
+                }
+                if (end != begin) {
+                    extensions.insert(std::string(begin, end));
+                }
+                
+                if (c == '\0') {
+                    break;
+                }
+                begin = end + 1;
+            } while(1);
+        }
+    }
+
+    return extensions.find(string) != extensions.end();
 }
 
 
index 05903a7b55281b96b6d00058c844fe551a2b9f7e..9557c0c71b65eb0d792852b905a792e3879c08bf 100644 (file)
@@ -32,6 +32,8 @@
 
 
 #include <vector>
+#include <set>
+#include <string>
 
 
 namespace glws {
@@ -130,12 +132,18 @@ public:
     const Visual *visual;
     Profile profile;
     
+    std::set<std::string> extensions;
+
     Context(const Visual *vis, Profile prof) :
         visual(vis),
         profile(prof)
     {}
 
     virtual ~Context() {}
+
+    // Context must be current
+    bool
+    hasExtension(const char *extension);
 };