summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-07-10 21:15:55 +0300
committerAndrei Karas <akaras@inbox.ru>2014-07-10 21:15:55 +0300
commit4a21c51e2183c41079342a20239cb8d10f8f2e0c (patch)
tree235123f5c01824f04576b9b823e0b479cfab050d
parent2c2d6c379cf994a61491983780edd3ab9852eaf4 (diff)
downloadplus-4a21c51e2183c41079342a20239cb8d10f8f2e0c.tar.gz
plus-4a21c51e2183c41079342a20239cb8d10f8f2e0c.tar.bz2
plus-4a21c51e2183c41079342a20239cb8d10f8f2e0c.tar.xz
plus-4a21c51e2183c41079342a20239cb8d10f8f2e0c.zip
In OpenGL context creation add support for compatability context.
-rw-r--r--src/render/modernopenglgraphics.cpp2
-rw-r--r--src/utils/glxhelper.cpp5
-rw-r--r--src/utils/glxhelper.h3
-rw-r--r--src/utils/sdl2helper.cpp41
-rw-r--r--src/utils/sdl2helper.h3
-rw-r--r--src/utils/sdlhelper.cpp30
-rw-r--r--src/utils/sdlhelper.h3
7 files changed, 60 insertions, 27 deletions
diff --git a/src/render/modernopenglgraphics.cpp b/src/render/modernopenglgraphics.cpp
index e8d0756cf..fc5e40062 100644
--- a/src/render/modernopenglgraphics.cpp
+++ b/src/render/modernopenglgraphics.cpp
@@ -1260,7 +1260,7 @@ void ModernOpenGLGraphics::createGLContext()
if (mGLContext)
SDL::makeCurrentContext(mGLContext);
else
- mGLContext = SDL::createGLContext(mWindow, 3, 3);
+ mGLContext = SDL::createGLContext(mWindow, 3, 3, 0x01);
}
void ModernOpenGLGraphics::finalize(ImageCollection *const col)
diff --git a/src/utils/glxhelper.cpp b/src/utils/glxhelper.cpp
index bd50d8c61..e27124325 100644
--- a/src/utils/glxhelper.cpp
+++ b/src/utils/glxhelper.cpp
@@ -39,7 +39,8 @@ static int ErrorHandler(Display *d A_UNUSED, XErrorEvent *e A_UNUSED)
void *GlxHelper::createContext(const unsigned long window,
void *const display0,
const int major,
- const int minor)
+ const int minor,
+ const int profile)
{
Display *const display = static_cast<Display*>(display0);
XSync(display, false);
@@ -88,7 +89,7 @@ void *GlxHelper::createContext(const unsigned long window,
{
GLX_CONTEXT_MAJOR_VERSION_ARB, major,
GLX_CONTEXT_MINOR_VERSION_ARB, minor,
- GLX_CONTEXT_PROFILE_MASK_ARB, 0x01, // core profile
+ GLX_CONTEXT_PROFILE_MASK_ARB, profile,
0, 0
};
diff --git a/src/utils/glxhelper.h b/src/utils/glxhelper.h
index 528e3f7fb..e76da1005 100644
--- a/src/utils/glxhelper.h
+++ b/src/utils/glxhelper.h
@@ -32,7 +32,8 @@ namespace GlxHelper
void *createContext(const unsigned long window,
void *const display,
const int major,
- const int minor);
+ const int minor,
+ const int profile);
bool makeCurrent(const unsigned long window,
void *const display,
diff --git a/src/utils/sdl2helper.cpp b/src/utils/sdl2helper.cpp
index 07f8d965c..6de5ef357 100644
--- a/src/utils/sdl2helper.cpp
+++ b/src/utils/sdl2helper.cpp
@@ -96,33 +96,48 @@ SDL_Thread *SDL::createThread(SDL_ThreadFunction fn,
void *SDL::createGLContext(SDL_Window *const window,
const int major,
- const int minor)
+ const int minor,
+ const int profile)
{
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
- SDL_GL_CONTEXT_PROFILE_CORE);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile);
// SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
SDL_ClearError();
void *context = SDL_GL_CreateContext(window);
- if (SDL_GetError())
+ if (SDL_GetError() && (major > 3 || (major == 3 && minor > 3)))
{
- if (!context && (major > 3 || (major == 3 && minor > 3)))
+ logger->log("Try fallback to OpenGL 3.3 core context");
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
+ SDL_ClearError();
+ context = SDL_GL_CreateContext(window);
+ if (SDL_GetError() && profile == 0x01)
{
- logger->log("Try fallback to OpenGL 3.3 context");
+ logger->log("Try fallback to OpenGL 3.3 compatibility context");
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0x02);
SDL_ClearError();
context = SDL_GL_CreateContext(window);
- if (SDL_GetError())
- {
- logger->log("Try fallback to OpenGL 3.0 context");
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
- context = SDL_GL_CreateContext(window);
- }
}
}
+ if (SDL_GetError() && (major > 3 || (major == 3 && minor > 0)))
+ {
+ logger->log("Try fallback to OpenGL 3.0 core context");
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile);
+ context = SDL_GL_CreateContext(window);
+ }
+ if (SDL_GetError() && (major > 2 || (major == 2 && minor > 1)))
+ {
+ logger->log("Try fallback to OpenGL 2.1 compatibility context");
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0x02);
+ context = SDL_GL_CreateContext(window);
+ }
return context;
}
diff --git a/src/utils/sdl2helper.h b/src/utils/sdl2helper.h
index b7ab35d84..0f8f7c6ff 100644
--- a/src/utils/sdl2helper.h
+++ b/src/utils/sdl2helper.h
@@ -54,7 +54,8 @@ namespace SDL
void *createGLContext(SDL_Window *const window,
const int major,
- const int minor);
+ const int minor,
+ const int profile);
void makeCurrentContext(void *const context);
} // namespace SDL
diff --git a/src/utils/sdlhelper.cpp b/src/utils/sdlhelper.cpp
index b809fd76b..7604334c9 100644
--- a/src/utils/sdlhelper.cpp
+++ b/src/utils/sdlhelper.cpp
@@ -119,25 +119,38 @@ SDL_Thread *SDL::createThread(int (SDLCALL *fn)(void *),
#if defined(USE_X11) && defined(USE_OPENGL)
void *SDL::createGLContext(SDL_Surface *const window A_UNUSED,
const int major,
- const int minor)
+ const int minor,
+ const int profile)
{
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
SDL_GetWMInfo(&info);
void *context = GlxHelper::createContext(info.info.x11.window,
- info.info.x11.display, major, minor);
+ info.info.x11.display, major, minor, profile);
if (!context && (major > 3 || (major == 3 && minor > 3)))
{
- logger->log("Try fallback to OpenGL 3.3 context");
+ logger->log("Try fallback to OpenGL 3.3 core context");
context = GlxHelper::createContext(info.info.x11.window,
- info.info.x11.display, 3, 3);
- if (!context)
+ info.info.x11.display, 3, 3, profile);
+ if (!context && profile == 0x01)
{
- logger->log("Try fallback to OpenGL 3.0 context");
+ logger->log("Try fallback to OpenGL 3.3 compatibility context");
context = GlxHelper::createContext(info.info.x11.window,
- info.info.x11.display, 3, 0);
+ info.info.x11.display, 3, 3, 0x02);
}
}
+ if (!context && (major > 3 || (major == 3 && minor > 0)))
+ {
+ logger->log("Try fallback to OpenGL 3.0 core context");
+ context = GlxHelper::createContext(info.info.x11.window,
+ info.info.x11.display, 3, 0, profile);
+ }
+ if (!context && (major > 2 || (major == 2 && minor > 1)))
+ {
+ logger->log("Try fallback to OpenGL 2.1 compatibility context");
+ context = GlxHelper::createContext(info.info.x11.window,
+ info.info.x11.display, 2, 1, 0x02);
+ }
return context;
}
@@ -153,7 +166,8 @@ void SDL::makeCurrentContext(void *const context)
#else
void *SDL::createGLContext(SDL_Surface *const window A_UNUSED,
const int major A_UNUSED,
- const int minor A_UNUSED)
+ const int minor A_UNUSED,
+ const int profile A_UNUSED)
{
return nullptr;
}
diff --git a/src/utils/sdlhelper.h b/src/utils/sdlhelper.h
index 92fcaba65..36616797e 100644
--- a/src/utils/sdlhelper.h
+++ b/src/utils/sdlhelper.h
@@ -59,7 +59,8 @@ namespace SDL
void *createGLContext(SDL_Surface *const window A_UNUSED,
const int major,
- const int minor);
+ const int minor,
+ const int profile);
void makeCurrentContext(void *const context);
} // namespace SDL