Refactor initGLSupport

This commit is contained in:
Grim Maple 2022-10-17 19:39:39 +03:00
parent 4a1e62240a
commit c85118e2cc
1 changed files with 11 additions and 35 deletions

View File

@ -31,6 +31,7 @@ import dlangui.core.math3d;
import std.conv; import std.conv;
import std.string; import std.string;
import std.array; import std.array;
import std.algorithm : any;
version (Android) { version (Android) {
enum SUPPORT_LEGACY_OPENGL = false; enum SUPPORT_LEGACY_OPENGL = false;
@ -49,11 +50,10 @@ version (Android) {
} else { } else {
enum SUPPORT_LEGACY_OPENGL = false; //true; enum SUPPORT_LEGACY_OPENGL = false; //true;
public import bindbc.opengl; public import bindbc.opengl;
public import bindbc.opengl.bind.arb.core_30; import bindbc.loader : ErrorInfo, errors;
import loader = bindbc.loader.sharedlib;
private void gl3CheckMissingSymFunc(const(loader.ErrorInfo)[] errors) private void gl3CheckMissingSymFunc(const(ErrorInfo)[] errors)
{ {
import std.algorithm : equal; import std.algorithm : equal;
immutable names = ["glGetError", "glShaderSource", "glCompileShader", immutable names = ["glGetError", "glShaderSource", "glCompileShader",
@ -119,7 +119,7 @@ template assertgl(alias func)
{ {
scope(success) assertNoError(func.stringof, functionName, line); scope(success) assertNoError(func.stringof, functionName, line);
return func(args); return func(args);
}; }
} }
void assertNoError(string context="", string functionName=__FUNCTION__, int line=__LINE__) void assertNoError(string context="", string functionName=__FUNCTION__, int line=__LINE__)
{ {
@ -665,44 +665,20 @@ __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;
import loader = bindbc.loader.sharedlib; import bindbc.opengl.config : GLVersion = GLSupport;
if (_glSupport && _glSupport.valid) if (_glSupport && _glSupport.valid)
return true; return true;
version(Android) { version(Android) {
Log.d("initGLSupport"); Log.d("initGLSupport");
} else { } else {
static bool BINDBC_GL3_RELOADED; GLVersion res = loadOpenGL();
static bool gl3ReloadedOk; if([GLVersion.badLibrary, GLVersion.noLibrary, GLVersion.noContext].any!(x => x == res))
static bool glReloadedOk; {
if (!BINDBC_GL3_RELOADED) { Log.e("bindbc-opengl cannot load OpenGL library!");
BINDBC_GL3_RELOADED = true;
try {
Log.v("Reloading bindbc-opengl");
import bindbc.opengl;
loadOpenGL();
gl3CheckMissingSymFunc(loader.errors);
gl3ReloadedOk = true;
} catch (Exception e) {
Log.e("bindbc-opengl exception while reloading opengl", e);
}
try {
Log.v("Reloading bindbc-opengl");
import bindbc.opengl;
loadOpenGL();
gl3CheckMissingSymFunc(loader.errors);
glReloadedOk = true;
} catch (Exception e) {
Log.e("bindbc-opengl exception while reloading opengl", e);
}
}
if (!gl3ReloadedOk && !glReloadedOk) {
Log.e("bindbc-opengl reloaded unsuccessfully");
return false;
} }
if (!gl3ReloadedOk) if(res < GLVersion.gl30)
legacy = true; legacy = true;
else if (!glReloadedOk) gl3CheckMissingSymFunc(errors);
legacy = false;
} }
if (!_glSupport) { // TODO_GRIM: Legacy looks very broken to me. if (!_glSupport) { // TODO_GRIM: Legacy looks very broken to me.
Log.d("glSupport not initialized: trying to create"); Log.d("glSupport not initialized: trying to create");