From: José Fonseca Date: Thu, 18 Oct 2012 14:22:41 +0000 (+0100) Subject: Check extensions via glGetStringi() on core profile. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=d1c301f7dbb2a90a52cd0109b5185c4ad463a612;p=apitrace Check extensions via glGetStringi() on core profile. Fixes segfault on MacOSX, given that glGetString() returns NULL there. --- diff --git a/retrace/glretrace.hpp b/retrace/glretrace.hpp index 11f4d27..7729ec5 100644 --- a/retrace/glretrace.hpp +++ b/retrace/glretrace.hpp @@ -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; diff --git a/retrace/glretrace_main.cpp b/retrace/glretrace_main.cpp index 1086be9..05567a2 100755 --- a/retrace/glretrace_main.cpp +++ b/retrace/glretrace_main.cpp @@ -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) { diff --git a/retrace/glretrace_ws.cpp b/retrace/glretrace_ws.cpp index bead54e..ccc7023 100644 --- a/retrace/glretrace_ws.cpp +++ b/retrace/glretrace_ws.cpp @@ -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; diff --git a/retrace/glws.cpp b/retrace/glws.cpp index 4e07ede..f89f980 100644 --- a/retrace/glws.cpp +++ b/retrace/glws.cpp @@ -24,6 +24,9 @@ **************************************************************************/ +#include + +#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(glGetStringi(GL_EXTENSIONS, i)); + if (extension) { + extensions.insert(extension); + } + } + } else { + // Use glGetString + const char *begin = reinterpret_cast(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(); } diff --git a/retrace/glws.hpp b/retrace/glws.hpp index 05903a7..9557c0c 100644 --- a/retrace/glws.hpp +++ b/retrace/glws.hpp @@ -32,6 +32,8 @@ #include +#include +#include namespace glws { @@ -130,12 +132,18 @@ public: const Visual *visual; Profile profile; + std::set extensions; + Context(const Visual *vis, Profile prof) : visual(vis), profile(prof) {} virtual ~Context() {} + + // Context must be current + bool + hasExtension(const char *extension); };