From fe7a1342dc71a412a177a69b022ac1d1cc1fbdc6 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 14 Aug 2012 12:43:25 +0300 Subject: Add support for GLX and wGL extensions. --- src/graphics.cpp | 1 + src/graphicsmanager.cpp | 90 +++++++++++++++++++++++++++++++++++++++++++++++++ src/graphicsmanager.h | 10 ++++++ src/mgl.cpp | 6 +++- src/mgl.h | 7 ++++ 5 files changed, 113 insertions(+), 1 deletion(-) diff --git a/src/graphics.cpp b/src/graphics.cpp index 05083506b..b852ccb2b 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -169,6 +169,7 @@ bool Graphics::setOpenGLMode() graphicsManager.setGLVersion(); graphicsManager.initOpenGLFunctions(); graphicsManager.updateExtensions(); + graphicsManager.updatePlanformExtensions(); graphicsManager.updateTextureFormat(); updateMemoryInfo(); diff --git a/src/graphicsmanager.cpp b/src/graphicsmanager.cpp index 9529cda51..34b16989a 100644 --- a/src/graphicsmanager.cpp +++ b/src/graphicsmanager.cpp @@ -48,6 +48,8 @@ #include "test/testmain.h" +#include + #include "debug.h" GraphicsManager graphicsManager; @@ -83,6 +85,7 @@ bool GraphicsManager::detectGraphics() setGLVersion(); initOpenGLFunctions(); updateExtensions(); + updatePlanformExtensions(); std::string vendor = getGLString(GL_VENDOR); std::string renderer = getGLString(GL_RENDERER); logger->log("gl vendor: %s", vendor.c_str()); @@ -239,6 +242,83 @@ void GraphicsManager::updateExtensions() } } +void GraphicsManager::updatePlanformExtensions() +{ + SDL_SysWMinfo info; + SDL_VERSION(&info.version); + if (SDL_GetWMInfo(&info)) + { +#ifdef WIN32 + if (!mwglGetExtensionsString) + return; + + HDC hdc = GetDC(info.window); + if (hdc > 0) + { + const char *extensions = mwglGetExtensionsString (hdc); + if (extensions) + { + logger->log("wGL extensions:"); + logger->log1(extensions); + splitToStringSet(mPlatformExtensions, extensions, ' '); + } + } +#elif defined USE_X11 + Display *display = info.info.x11.display; + if (display) + { + Screen *screen = XDefaultScreenOfDisplay(display); + if (!screen) + return; + + int screenNum = XScreenNumberOfScreen(screen); + const char *extensions = glXQueryExtensionsString( + display, screenNum); + if (extensions) + { + logger->log("glx extensions:"); + logger->log1(extensions); + splitToStringSet(mPlatformExtensions, extensions, ' '); + } + glXQueryVersion(display, &mPlatformMajor, &mPlatformMinor); + if (checkPlatformVersion(1, 1)) + { + const char *vendor1 = glXQueryServerString( + display, screenNum, GLX_VENDOR); + if (vendor1) + logger->log("glx server vendor: %s", vendor1); + const char *version1 = glXQueryServerString( + display, screenNum, GLX_VERSION); + if (version1) + logger->log("glx server version: %s", version1); + const char *extensions1 = glXQueryServerString( + display, screenNum, GLX_EXTENSIONS); + if (extensions1) + { + logger->log("glx server extensions:"); + logger->log1(extensions1); + } + + const char *vendor2 = glXGetClientString(display, GLX_VENDOR); + if (vendor2) + logger->log("glx client vendor: %s", vendor2); + const char *version2 = glXGetClientString( + display, GLX_VERSION); + if (version2) + logger->log("glx client version: %s", version2); + const char *extensions2 = glXGetClientString( + display, GLX_EXTENSIONS); + if (extensions2) + { + logger->log("glx client extensions:"); + logger->log1(extensions2); + } + } + } +#endif + } +} + bool GraphicsManager::supportExtension(const std::string &ext) { return mExtensions.find(ext) != mExtensions.end(); @@ -385,6 +465,12 @@ bool GraphicsManager::checkGLVersion(int major, int minor) const return mMajor > major || (mMajor == major && mMinor >= minor); } +bool GraphicsManager::checkPlatformVersion(int major, int minor) const +{ + return mPlatformMajor > major || (mPlatformMajor == major + && mPlatformMinor >= minor); +} + void GraphicsManager::createFBO(int width, int height, FBOInfo *fbo) { #ifdef USE_OPENGL @@ -497,4 +583,8 @@ void GraphicsManager::initOpenGLFunctions() if (checkGLVersion(3, 0)) assignFunction(glGetStringi, "glGetStringi"); + +#ifdef WIN32 + assignFunction(wglGetExtensionsString, "wglGetExtensionsStringARB"); +#endif } diff --git a/src/graphicsmanager.h b/src/graphicsmanager.h index 6a41da035..9abc3bf23 100644 --- a/src/graphicsmanager.h +++ b/src/graphicsmanager.h @@ -55,6 +55,8 @@ class GraphicsManager bool checkGLVersion(int major, int minor) const; + bool checkPlatformVersion(int major, int minor) const; + void createFBO(int width, int height, FBOInfo *fbo); void deleteFBO(FBOInfo *fbo); @@ -63,16 +65,24 @@ class GraphicsManager void updateExtensions(); + void updatePlanformExtensions(); + Graphics *createGraphics(); private: std::set mExtensions; + std::set mPlatformExtensions; + std::string mVersionString; int mMinor; int mMajor; + + int mPlatformMinor; + + int mPlatformMajor; }; extern GraphicsManager graphicsManager; diff --git a/src/mgl.cpp b/src/mgl.cpp index 6dafb1258..6ed921b54 100644 --- a/src/mgl.cpp +++ b/src/mgl.cpp @@ -33,4 +33,8 @@ defName(glFramebufferTexture2D); defName(glFramebufferRenderbuffer); defName(glDeleteFramebuffers); defName(glDeleteRenderbuffers); -defName(glGetStringi); \ No newline at end of file +defName(glGetStringi); + +#ifdef WIN32 +defName(wglGetExtensionsString); +#endif diff --git a/src/mgl.h b/src/mgl.h index 8e7002d82..3c611e9ac 100644 --- a/src/mgl.h +++ b/src/mgl.h @@ -24,6 +24,7 @@ #define GL_GLEXT_PROTOTYPES 1 #include +#include #include #define GL_NUM_EXTENSIONS 0x821D @@ -61,4 +62,10 @@ defNameE(glDeleteFramebuffers); defNameE(glDeleteRenderbuffers); defNameE(glGetStringi); +#ifdef WIN32 +typedef const char* (APIENTRY * wglGetExtensionsString_t) (HDC hdc); + +defNameE(wglGetExtensionsString); +#endif + #endif -- cgit v1.2.3-70-g09d2