From: José Fonseca Date: Sun, 9 Oct 2011 15:16:18 +0000 (+0100) Subject: Create contexts with DEBUG_BIT when not benchmarking. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=93f0e3f5b7fc212bc993af407dacac24cdab5210;p=apitrace Create contexts with DEBUG_BIT when not benchmarking. --- 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 + + namespace glws { +extern bool debug; + + +bool +checkExtension(const char *extName, const char *extString); + + +template< class T > +class Attributes { +protected: + std::vector 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 #include + #include #include "glws.hpp" - -#include -#include -#include +#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 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 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(visual)->visinfo; + const GlxVisual *visual = dynamic_cast(_visual); GLXContext share_context = NULL; GLXContext context; @@ -272,8 +297,22 @@ createContext(const Visual *visual, Context *shareContext) share_context = dynamic_cast(shareContext)->context; } - context = glXCreateContext(display, visinfo, - share_context, True); + + if (glxVersion >= 0x0104 && has_GLX_ARB_create_context) { + Attributes 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); }