From 7618e2e11359f04c0ba02964a7b6d7869c2ac4c7 Mon Sep 17 00:00:00 2001 From: Peter Reijnders Date: Tue, 10 Jan 2017 16:21:14 +0100 Subject: [PATCH 1/2] Set the best GL version that is present, or fall back to 3.1. Issue-45 --- src/Interface/UIInterface.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Interface/UIInterface.cpp b/src/Interface/UIInterface.cpp index 8b2d2dc8..7c54fb59 100644 --- a/src/Interface/UIInterface.cpp +++ b/src/Interface/UIInterface.cpp @@ -47,16 +47,24 @@ UIInterface::UIInterface() void UIInterface::setGLContextAttribute() { + int major; + int minor; + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + if (SDL_GL_GetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, &major) == 0 && + SDL_GL_GetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, &minor) == 0 ) { + } else { + major = 3; + minor = 1; + } + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor); } bool UIInterface::createWindow(int width, int height) @@ -489,7 +497,7 @@ uint8_t *UIInterface::readScreenPixel() /* Flip Y pixels (row by row) */ for (uint32_t i = 0; i < height; i++) { memcpy(m_FrameBuffer + i * width * 4, - &ret[(height - i - 1) * width * 4], + &ret[(height - i - 1) * width * 4], width * 4); } From c329c4d52011be6618104b79f0d03cc5e2ea2c19 Mon Sep 17 00:00:00 2001 From: Peter Reijnders Date: Wed, 11 Jan 2017 06:50:10 +0100 Subject: [PATCH 2/2] Iterating through a list of approved GL versions, starting from the best and check if that could be set. --- src/Interface/UIInterface.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/Interface/UIInterface.cpp b/src/Interface/UIInterface.cpp index 7c54fb59..78d51a93 100644 --- a/src/Interface/UIInterface.cpp +++ b/src/Interface/UIInterface.cpp @@ -47,8 +47,18 @@ UIInterface::UIInterface() void UIInterface::setGLContextAttribute() { - int major; - int minor; + struct gl_version { + int major; + int minor; + }; + struct gl_version approved_versions[] = { + {4, 5 }, {4, 4}, {4, 3}, {4, 2}, {4, 1}, {4, 0}, + {3, 2}, {3, 1}, /*{3, 0},*/ + {2, 1}, {2, 0}, + {1, 5}, {1, 4}, {1, 3}, {1, 2}, {1, 1}, + {-1, -1} + }; + struct gl_version * ver; SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); @@ -57,14 +67,15 @@ void UIInterface::setGLContextAttribute() SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); - if (SDL_GL_GetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, &major) == 0 && - SDL_GL_GetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, &minor) == 0 ) { - } else { - major = 3; - minor = 1; + + ver = &approved_versions[0]; + while (ver->major != -1 ) { + if ( SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, ver->major) == 0 && + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, ver->minor) == 0) { + break; + } } - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor); + //printf("Set GL to %d.%d\n", ver->major, ver->minor); } bool UIInterface::createWindow(int width, int height)