From b07a6d54a7ca87a3a85770d55c8f10edd4dcb291 Mon Sep 17 00:00:00 2001 From: gazer Date: Thu, 8 Jun 2017 15:55:14 +0300 Subject: [PATCH 1/2] old API fixes --- src/dlangui/graphics/glsupport.d | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/dlangui/graphics/glsupport.d b/src/dlangui/graphics/glsupport.d index 675650a3..40c993cd 100644 --- a/src/dlangui/graphics/glsupport.d +++ b/src/dlangui/graphics/glsupport.d @@ -694,6 +694,8 @@ bool initGLSupport(bool legacy = false) { } if (!_glSupport) { Log.d("glSupport not initialized: trying to create"); + int major = to!int(glGetString(GL_VERSION)[0 .. 1]); + legacy = legacy || (major < 3); _glSupport = new GLSupport(legacy); if (!_glSupport.valid) { Log.e("Failed to compile shaders"); @@ -705,9 +707,8 @@ bool initGLSupport(bool legacy = false) { Log.i("Trying to reinit GLSupport with legacy flag ", !legacy); _glSupport = new GLSupport(!legacy); } - // Situation when opposite legacy flag is true and context version is 3.1+ + // Situation when opposite legacy flag is true and GL version is 3+ with no old functions if (_glSupport.legacyMode) { - int major = to!int(glGetString(GL_VERSION)[0]); if (major >= 3) { Log.e("Try to create OpenGL context with <= 3.1 version"); return false; @@ -828,10 +829,12 @@ final class GLSupport { /// This function is needed to draw custom OpenGL scene correctly (especially on legacy API) private void resetBindings() { - // TODO: check if there is a very old driver with no such functions - GLProgram.unbind(); - VAO.unbind(); - VBO.unbind(); + if (glUseProgram) + GLProgram.unbind(); + if (glBindVertexArray) + VAO.unbind(); + if (glBindBuffer) + VBO.unbind(); } private void destroyBuffers() { From 3d4bf61bb83d5ed291f9b386d9eb128d3deed049 Mon Sep 17 00:00:00 2001 From: gazer Date: Thu, 8 Jun 2017 17:57:05 +0300 Subject: [PATCH 2/2] GL_INVALID_OPERATION quickfix --- src/dlangui/graphics/glsupport.d | 8 ++++++-- src/dlangui/platforms/sdl/sdlapp.d | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/dlangui/graphics/glsupport.d b/src/dlangui/graphics/glsupport.d index 40c993cd..67be417c 100644 --- a/src/dlangui/graphics/glsupport.d +++ b/src/dlangui/graphics/glsupport.d @@ -651,6 +651,8 @@ private __gshared GLSupport _glSupport; return _glSupport; } +__gshared bool glNoContext; + /// initialize OpenGL support helper (call when current OpenGL context is initialized) bool initGLSupport(bool legacy = false) { import dlangui.platforms.common.platform : setOpenglEnabled; @@ -1125,8 +1127,10 @@ class GLObject(GLObjectTypes type, GLuint target = 0) { } ~this() { - unbind(); - mixin("checkgl!glDelete" ~ to!string(type) ~ "s(1, &ID);"); + if (!glNoContext) { + unbind(); + mixin("checkgl!glDelete" ~ to!string(type) ~ "s(1, &ID);"); + } } void bind() { diff --git a/src/dlangui/platforms/sdl/sdlapp.d b/src/dlangui/platforms/sdl/sdlapp.d index 5d9b24ec..87eb9b99 100644 --- a/src/dlangui/platforms/sdl/sdlapp.d +++ b/src/dlangui/platforms/sdl/sdlapp.d @@ -1595,6 +1595,8 @@ int sdlmain(string[] args) { Log.d("Destroying SDL platform"); Platform.setInstance(null); + static if (ENABLE_OPENGL) + glNoContext = true; releaseResourcesOnAppExit();