diff --git a/src/dlangui/graphics/glsupport.d b/src/dlangui/graphics/glsupport.d index c43d596a..957f486a 100644 --- a/src/dlangui/graphics/glsupport.d +++ b/src/dlangui/graphics/glsupport.d @@ -125,8 +125,9 @@ class GLProgram { private char[] glslversionString; private void compatibilityFixes(ref char[] code, GLuint type) { - if (glslversionInt < 150) { + if (glslversionInt < 150) code = replace(code, " texture(", " texture2D("); + if (glslversionInt < 140) { if(type == GL_VERTEX_SHADER) { code = replace(code, "in ", "attribute "); @@ -134,6 +135,8 @@ class GLProgram { } else { code = replace(code, "in ", "varying "); + code = replace(code, "out vec4 outColor;", ""); + code = replace(code, "outColor", "gl_FragColor"); } } } 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(); } diff --git a/src/dlangui/platforms/x11/x11app.d b/src/dlangui/platforms/x11/x11app.d index 4f987046..b5c3ff8b 100644 --- a/src/dlangui/platforms/x11/x11app.d +++ b/src/dlangui/platforms/x11/x11app.d @@ -220,7 +220,7 @@ class X11Window : DWindow { swamask |= CWColormap; swa.colormap = x11cmap; visual = cast(Visual*)x11visual.visual; - depth = x11visutal.depth; + depth = x11visual.depth; } }