From 8711d3d3a342bc58b9876eb116f1640660c2dbbb Mon Sep 17 00:00:00 2001 From: bkaradzic Date: Fri, 26 Apr 2013 23:43:31 -0700 Subject: [PATCH] GLX: added swap interval. --- src/glcontext_glx.cpp | 30 +++++++++++++++++++++++++++--- src/glcontext_wgl.cpp | 29 ++--------------------------- src/renderer_gl.cpp | 30 ++++++++++++++++++++++++++++++ src/renderer_gl.h | 4 +++- 4 files changed, 62 insertions(+), 31 deletions(-) diff --git a/src/glcontext_glx.cpp b/src/glcontext_glx.cpp index ab1b68cda..d67a3581a 100644 --- a/src/glcontext_glx.cpp +++ b/src/glcontext_glx.cpp @@ -7,6 +7,8 @@ #if (BGFX_CONFIG_RENDERER_OPENGLES2|BGFX_CONFIG_RENDERER_OPENGLES3|BGFX_CONFIG_RENDERER_OPENGL) # include "renderer_gl.h" +# define GLX_GLXEXT_PROTOTYPES +# include # if BX_PLATFORM_LINUX @@ -39,6 +41,12 @@ namespace bgfx , minor ); + int32_t screen = DefaultScreen(s_display); + + const char* extensions = glXQueryExtensionsString(s_display, screen); + BX_TRACE("GLX extensions:"); + dumpExtensions(extensions); + const int attrsGlx[] = { GLX_RENDER_TYPE, GLX_RGBA_BIT, @@ -57,7 +65,7 @@ namespace bgfx GLXFBConfig bestConfig = NULL; int numConfigs; - GLXFBConfig* configs = glXChooseFBConfig(s_display, DefaultScreen(s_display), attrsGlx, &numConfigs); + GLXFBConfig* configs = glXChooseFBConfig(s_display, screen, attrsGlx, &numConfigs); BX_TRACE("glX num configs %d", numConfigs); @@ -113,8 +121,7 @@ namespace bgfx XFree(visualInfo); #if BGFX_CONFIG_RENDERER_OPENGL >= 31 - typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*); - glXCreateContextAttribsARBProc glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddress((const GLubyte*)"glXCreateContextAttribsARB"); + PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress( (const GLubyte*)"glXCreateContextAttribsARB"); if (NULL != glXCreateContextAttribsARB) { BX_TRACE("Create GL 3.1 context."); @@ -142,7 +149,24 @@ namespace bgfx import(); + PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddress( (const GLubyte*)"glXSwapIntervalEXT"); + if (NULL != glXSwapIntervalEXT) + { + BX_TRACE("Using glXSwapIntervalEXT."); + glXSwapIntervalEXT(s_display, 0, 0); + } + else + { + PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)glXGetProcAddress( (const GLubyte*)"glXSwapIntervalSGI"); + if (NULL != glXSwapIntervalSGI) + { + BX_TRACE("Using glXSwapIntervalSGI."); + glXSwapIntervalSGI(0); + } + } + glXMakeCurrent(s_display, s_window, m_context); + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glXSwapBuffers(s_display, s_window); diff --git a/src/glcontext_wgl.cpp b/src/glcontext_wgl.cpp index ea3a36b6c..d46c97286 100644 --- a/src/glcontext_wgl.cpp +++ b/src/glcontext_wgl.cpp @@ -120,34 +120,9 @@ namespace bgfx if (NULL != wglGetExtensionsStringARB) { - BX_TRACE("WGL extensions:"); const char* extensions = (const char*)wglGetExtensionsStringARB(hdc); - if (NULL != extensions) - { - char name[1024]; - const char* pos = extensions; - const char* end = extensions + strlen(extensions); - while (pos < end) - { - uint32_t len; - const char* space = strchr(pos, ' '); - if (NULL != space) - { - len = uint32_min(sizeof(name), (uint32_t)(space - pos) ); - } - else - { - len = uint32_min(sizeof(name), (uint32_t)strlen(pos) ); - } - - strncpy(name, pos, len); - name[len] = '\0'; - - BX_TRACE("\t%s", name); - - pos += len+1; - } - } + BX_TRACE("WGL extensions:"); + dumpExtensions(extensions); } if (NULL != wglChoosePixelFormatARB diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index af2891297..c1abfe0b3 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -186,6 +186,36 @@ namespace bgfx return 0; } + void dumpExtensions(const char* _extensions) + { + if (NULL != _extensions) + { + char name[1024]; + const char* pos = _extensions; + const char* end = _extensions + strlen(_extensions); + while (pos < end) + { + uint32_t len; + const char* space = strchr(pos, ' '); + if (NULL != space) + { + len = uint32_min(sizeof(name), (uint32_t)(space - pos) ); + } + else + { + len = uint32_min(sizeof(name), (uint32_t)strlen(pos) ); + } + + strncpy(name, pos, len); + name[len] = '\0'; + + BX_TRACE("\t%s", name); + + pos += len+1; + } + } + } + #if BGFX_CONFIG_RENDERER_OPENGL const char* toString(GLenum _enum) { diff --git a/src/renderer_gl.h b/src/renderer_gl.h index b5a7d0164..0fc13b2fd 100755 --- a/src/renderer_gl.h +++ b/src/renderer_gl.h @@ -280,7 +280,9 @@ namespace bgfx #define GL_IMPORT(_optional, _proto, _func) extern _proto _func #include "glimports.h" #undef GL_IMPORT - + + void dumpExtensions(const char* _extensions); + class ConstantBuffer; class VaoCache