Fixes segfault on MacOSX, given that glGetString() returns NULL there.
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;
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) {
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;
**************************************************************************/
+#include <assert.h>
+
+#include "glproc.hpp"
#include "glws.hpp"
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();
}
#include <vector>
+#include <set>
+#include <string>
namespace glws {
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);
};