diff --git a/src/dlangui/platforms/common/platform.d b/src/dlangui/platforms/common/platform.d index 128790fa..5f2885fd 100644 --- a/src/dlangui/platforms/common/platform.d +++ b/src/dlangui/platforms/common/platform.d @@ -1253,6 +1253,19 @@ class Platform { * Window w/o Resizable nor Fullscreen will be created with size based on measurement of its content widget */ abstract Window createWindow(dstring windowCaption, Window parent, uint flags = WindowFlag.Resizable, uint width = 0, uint height = 0); + + static if (ENABLE_OPENGL) { + /** + * OpenGL context major version. + * Note: if the version is invalid or not supported, this value will be set to supported one. + */ + int GLVersionMajor = 3; + /** + * OpenGL context minor version. + * Note: if the version is invalid or not supported, this value will be set to supported one. + */ + int GLVersionMinor = 2; + } /** * close window * diff --git a/src/dlangui/platforms/sdl/sdlapp.d b/src/dlangui/platforms/sdl/sdlapp.d index 1637997d..035c8751 100644 --- a/src/dlangui/platforms/sdl/sdlapp.d +++ b/src/dlangui/platforms/sdl/sdlapp.d @@ -127,8 +127,11 @@ class SDLWindow : Window { _context = SDL_GL_CreateContext(_win); // Create the actual context and make it current if (!_context) Log.e("SDL_GL_CreateContext failed: ", fromStringz(SDL_GetError())); - else + else { Log.i("Created successfully"); + _platform.GLVersionMajor = versionMajor; + _platform.GLVersionMinor = versionMinor; + } return _context !is null; } } @@ -176,21 +179,24 @@ class SDLWindow : Window { static if (ENABLE_OPENGL) { if (_enableOpengl) { - createContext(3, 2); - if (!_context) { - Log.e("SDL_GL_CreateContext failed: ", fromStringz(SDL_GetError())); + bool success = createContext(_platform.GLVersionMajor, _platform.GLVersionMinor); + if (!success) { Log.w("trying other versions of OpenGL"); - bool flg = false; - flg = flg || createContext(3, 3); - flg = flg || createContext(3, 1); - flg = flg || createContext(4, 0); - flg = flg || createContext(2, 1); - if (!flg) { + // Lazy conditions. + if(_platform.GLVersionMajor >= 4) + success = success || createContext(4, 0); + success = success || createContext(3, 3); + success = success || createContext(3, 2); + success = success || createContext(3, 1); + success = success || createContext(2, 1); + if (!success) { _enableOpengl = false; + _platform.GLVersionMajor = 0; + _platform.GLVersionMinor = 0; Log.w("OpenGL support is disabled"); } } - if (_context && !_glSupport) { + if (success && !_glSupport) { _enableOpengl = initGLSupport(false); fixSize(); }