Merge pull request #369 from g4z3r/gl

old GL API fixes
This commit is contained in:
Vadim Lopatin 2017-06-10 09:42:27 +03:00 committed by GitHub
commit 84ee32c100
2 changed files with 17 additions and 8 deletions

View File

@ -651,6 +651,8 @@ private __gshared GLSupport _glSupport;
return _glSupport; return _glSupport;
} }
__gshared bool glNoContext;
/// initialize OpenGL support helper (call when current OpenGL context is initialized) /// initialize OpenGL support helper (call when current OpenGL context is initialized)
bool initGLSupport(bool legacy = false) { bool initGLSupport(bool legacy = false) {
import dlangui.platforms.common.platform : setOpenglEnabled; import dlangui.platforms.common.platform : setOpenglEnabled;
@ -694,6 +696,8 @@ bool initGLSupport(bool legacy = false) {
} }
if (!_glSupport) { if (!_glSupport) {
Log.d("glSupport not initialized: trying to create"); 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); _glSupport = new GLSupport(legacy);
if (!_glSupport.valid) { if (!_glSupport.valid) {
Log.e("Failed to compile shaders"); Log.e("Failed to compile shaders");
@ -705,9 +709,8 @@ bool initGLSupport(bool legacy = false) {
Log.i("Trying to reinit GLSupport with legacy flag ", !legacy); Log.i("Trying to reinit GLSupport with legacy flag ", !legacy);
_glSupport = new GLSupport(!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) { if (_glSupport.legacyMode) {
int major = to!int(glGetString(GL_VERSION)[0]);
if (major >= 3) { if (major >= 3) {
Log.e("Try to create OpenGL context with <= 3.1 version"); Log.e("Try to create OpenGL context with <= 3.1 version");
return false; return false;
@ -828,9 +831,11 @@ final class GLSupport {
/// This function is needed to draw custom OpenGL scene correctly (especially on legacy API) /// This function is needed to draw custom OpenGL scene correctly (especially on legacy API)
private void resetBindings() { private void resetBindings() {
// TODO: check if there is a very old driver with no such functions if (glUseProgram)
GLProgram.unbind(); GLProgram.unbind();
if (glBindVertexArray)
VAO.unbind(); VAO.unbind();
if (glBindBuffer)
VBO.unbind(); VBO.unbind();
} }
@ -1122,9 +1127,11 @@ class GLObject(GLObjectTypes type, GLuint target = 0) {
} }
~this() { ~this() {
if (!glNoContext) {
unbind(); unbind();
mixin("checkgl!glDelete" ~ to!string(type) ~ "s(1, &ID);"); mixin("checkgl!glDelete" ~ to!string(type) ~ "s(1, &ID);");
} }
}
void bind() { void bind() {
static if(target != 0) static if(target != 0)

View File

@ -1595,6 +1595,8 @@ int sdlmain(string[] args) {
Log.d("Destroying SDL platform"); Log.d("Destroying SDL platform");
Platform.setInstance(null); Platform.setInstance(null);
static if (ENABLE_OPENGL)
glNoContext = true;
releaseResourcesOnAppExit(); releaseResourcesOnAppExit();