summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosé Fonseca <jose.r.fonseca@gmail.com>2011-10-09 16:16:18 +0100
committerJosé Fonseca <jose.r.fonseca@gmail.com>2011-10-09 16:16:18 +0100
commit93f0e3f5b7fc212bc993af407dacac24cdab5210 (patch)
tree597d5b764428be93e7eac54fb99fa48484e9607a
parentb87c229d14519fd912418cec3e3747557a055b31 (diff)
Create contexts with DEBUG_BIT when not benchmarking.
-rwxr-xr-xCMakeLists.txt7
-rw-r--r--glretrace_main.cpp1
-rw-r--r--glws.cpp62
-rw-r--r--glws.hpp41
-rw-r--r--glws_glx.cpp123
5 files changed, 188 insertions, 46 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8987c7d..c81e44d 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -197,10 +197,10 @@ add_custom_command (
if (WIN32)
set (os os_win32.cpp)
- set (glws glws_wgl.cpp)
+ set (glws_os glws_wgl.cpp)
else (WIN32)
set (os os_posix.cpp)
- set (glws glws_glx.cpp)
+ set (glws_os glws_glx.cpp)
endif (WIN32)
add_library (common STATIC
@@ -413,7 +413,8 @@ add_executable (glretrace
glstate.cpp
glstate_params.cpp
retrace.cpp
- ${glws}
+ glws.cpp
+ ${glws_os}
${CMAKE_CURRENT_BINARY_DIR}/glproc.hpp
)
diff --git a/glretrace_main.cpp b/glretrace_main.cpp
index dc02276..4e4b8ae 100644
--- a/glretrace_main.cpp
+++ b/glretrace_main.cpp
@@ -266,6 +266,7 @@ int main(int argc, char **argv)
} else if (!strcmp(arg, "-b")) {
benchmark = true;
retrace::verbosity = -1;
+ glws::debug = false;
} else if (!strcmp(arg, "-c")) {
compare_prefix = argv[++i];
if (snapshot_frequency == FREQUENCY_NEVER) {
diff --git a/glws.cpp b/glws.cpp
new file mode 100644
index 0000000..c5c41eb
--- /dev/null
+++ b/glws.cpp
@@ -0,0 +1,62 @@
+/**************************************************************************
+ *
+ * Copyright 2011 Jose Fonseca
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#include "glws.hpp"
+
+
+namespace glws {
+
+
+bool debug = true;
+
+
+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;
+}
+
+
+} /* namespace glws */
diff --git a/glws.hpp b/glws.hpp
index 12e53f3..47fdc7f 100644
--- a/glws.hpp
+++ b/glws.hpp
@@ -31,9 +31,48 @@
#define _GLWS_HPP_
+#include <vector>
+
+
namespace glws {
+extern bool debug;
+
+
+bool
+checkExtension(const char *extName, const char *extString);
+
+
+template< class T >
+class Attributes {
+protected:
+ std::vector<T> attribs;
+
+public:
+ void add(T param) {
+ attribs.push_back(param);
+ }
+
+ void add(T pname, T pvalue) {
+ add(pname);
+ add(pvalue);
+ }
+
+ void end(void) {
+ add(0);
+ }
+
+ operator T * (void) {
+ return &attribs[0];
+ }
+
+ operator const T * (void) const {
+ return &attribs[0];
+ }
+};
+
+
class Visual
{
public:
@@ -105,7 +144,7 @@ Drawable *
createDrawable(const Visual *visual, int width = 32, int height = 32);
Context *
-createContext(const Visual *visual, Context *shareContext = NULL);
+createContext(const Visual *visual, Context *shareContext = 0);
bool
makeCurrent(Drawable *drawable, Context *context);
diff --git a/glws_glx.cpp b/glws_glx.cpp
index 1c73564..23b4082 100644
--- a/glws_glx.cpp
+++ b/glws_glx.cpp
@@ -23,14 +23,13 @@
*
**************************************************************************/
+#include <assert.h>
#include <stdlib.h>
+
#include <iostream>
#include "glws.hpp"
-
-#include <X11/Xlib.h>
-#include <GL/gl.h>
-#include <GL/glx.h>
+#include "glproc.hpp"
namespace glws {
@@ -39,18 +38,25 @@ namespace glws {
static Display *display = NULL;
static int screen = 0;
+static unsigned glxVersion = 0;
+static const char *extensions = 0;
+static bool has_GLX_ARB_create_context = false;
+
class GlxVisual : public Visual
{
public:
+ GLXFBConfig fbconfig;
XVisualInfo *visinfo;
- GlxVisual(XVisualInfo *vi) :
- visinfo(vi)
+ GlxVisual() :
+ fbconfig(0),
+ visinfo(0)
{}
~GlxVisual() {
XFree(visinfo);
+ XFree(fbconfig);
}
};
@@ -205,14 +211,20 @@ public:
void
init(void) {
+ display = XOpenDisplay(NULL);
if (!display) {
- display = XOpenDisplay(NULL);
- if (!display) {
- std::cerr << "error: unable to open display " << XDisplayName(NULL) << "\n";
- exit(1);
- }
- screen = DefaultScreen(display);
+ std::cerr << "error: unable to open display " << XDisplayName(NULL) << "\n";
+ exit(1);
}
+
+ screen = DefaultScreen(display);
+
+ int major = 0, minor = 0;
+ glXQueryVersion(display, &major, &minor);
+ glxVersion = (major << 8) | minor;
+
+ extensions = glXQueryExtensionsString(display, screen);
+ has_GLX_ARB_create_context = checkExtension("GLX_ARB_create_context", extensions);
}
void
@@ -225,34 +237,47 @@ cleanup(void) {
Visual *
createVisual(bool doubleBuffer) {
- int single_attribs[] = {
- GLX_RGBA,
- GLX_RED_SIZE, 1,
- GLX_GREEN_SIZE, 1,
- GLX_BLUE_SIZE, 1,
- GLX_ALPHA_SIZE, 1,
- GLX_DEPTH_SIZE, 1,
- GLX_STENCIL_SIZE, 1,
- None
- };
-
- int double_attribs[] = {
- GLX_RGBA,
- GLX_RED_SIZE, 1,
- GLX_GREEN_SIZE, 1,
- GLX_BLUE_SIZE, 1,
- GLX_ALPHA_SIZE, 1,
- GLX_DOUBLEBUFFER,
- GLX_DEPTH_SIZE, 1,
- GLX_STENCIL_SIZE, 1,
- None
- };
-
- XVisualInfo *visinfo;
+ GlxVisual *visual = new GlxVisual;
+
+ if (glxVersion >= 0x0103) {
+ Attributes<int> attribs;
+ attribs.add(GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT);
+ attribs.add(GLX_RENDER_TYPE, GLX_RGBA_BIT);
+ attribs.add(GLX_RED_SIZE, 1);
+ attribs.add(GLX_GREEN_SIZE, 1);
+ attribs.add(GLX_BLUE_SIZE, 1);
+ attribs.add(GLX_ALPHA_SIZE, 1);
+ attribs.add(GLX_DOUBLEBUFFER, doubleBuffer ? GL_TRUE : GL_FALSE);
+ attribs.add(GLX_DEPTH_SIZE, 1);
+ attribs.add(GLX_STENCIL_SIZE, 1);
+ attribs.end();
+
+ int num_configs = 0;
+ GLXFBConfig * fbconfigs;
+ fbconfigs = glXChooseFBConfig(display, screen, attribs, &num_configs);
+ assert(num_configs && fbconfigs);
+ visual->fbconfig = fbconfigs[0];
+ assert(visual->fbconfig);
+ visual->visinfo = glXGetVisualFromFBConfig(display, visual->fbconfig);
+ assert(visual->visinfo);
+ } else {
+ Attributes<int> attribs;
+ attribs.add(GLX_RGBA);
+ attribs.add(GLX_RED_SIZE, 1);
+ attribs.add(GLX_GREEN_SIZE, 1);
+ attribs.add(GLX_BLUE_SIZE, 1);
+ attribs.add(GLX_ALPHA_SIZE, 1);
+ if (doubleBuffer) {
+ attribs.add(GLX_DOUBLEBUFFER);
+ }
+ attribs.add(GLX_DEPTH_SIZE, 1);
+ attribs.add(GLX_STENCIL_SIZE, 1);
+ attribs.end();
- visinfo = glXChooseVisual(display, screen, doubleBuffer ? double_attribs : single_attribs);
+ visual->visinfo = glXChooseVisual(display, screen, attribs);
+ }
- return new GlxVisual(visinfo);
+ return visual;
}
Drawable *
@@ -262,9 +287,9 @@ createDrawable(const Visual *visual, int width, int height)
}
Context *
-createContext(const Visual *visual, Context *shareContext)
+createContext(const Visual *_visual, Context *shareContext)
{
- XVisualInfo *visinfo = dynamic_cast<const GlxVisual *>(visual)->visinfo;
+ const GlxVisual *visual = dynamic_cast<const GlxVisual *>(_visual);
GLXContext share_context = NULL;
GLXContext context;
@@ -272,8 +297,22 @@ createContext(const Visual *visual, Context *shareContext)
share_context = dynamic_cast<GlxContext*>(shareContext)->context;
}
- context = glXCreateContext(display, visinfo,
- share_context, True);
+
+ if (glxVersion >= 0x0104 && has_GLX_ARB_create_context) {
+ Attributes<int> attribs;
+ attribs.add(GLX_RENDER_TYPE, GLX_RGBA_TYPE);
+ if (debug) {
+ attribs.add(GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB);
+ }
+ attribs.end();
+
+ context = glXCreateContextAttribsARB(display, visual->fbconfig, share_context, True, attribs);
+ } else if (glxVersion >= 0x103) {
+ context = glXCreateNewContext(display, visual->fbconfig, GLX_RGBA_TYPE, share_context, True);
+ } else {
+ context = glXCreateContext(display, visual->visinfo, share_context, True);
+ }
+
return new GlxContext(visual, context);
}