mirror of https://github.com/buggins/dlangui.git
refactor OpenGL initialization
This commit is contained in:
parent
2cb21339e5
commit
349c6612e1
|
@ -455,6 +455,76 @@ __gshared GLSupport _glSupport;
|
||||||
return _glSupport;
|
return _glSupport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// initialize OpenGL suport helper (call when current OpenGL context is initialized)
|
||||||
|
bool initGLSupport(bool legacy = false) {
|
||||||
|
import dlangui.platforms.common.platform : setOpenglEnabled;
|
||||||
|
if (_glSupport && _glSupport.valid)
|
||||||
|
return true;
|
||||||
|
static bool DERELICT_GL3_RELOADED;
|
||||||
|
static bool gl3ReloadedOk;
|
||||||
|
static bool glReloadedOk;
|
||||||
|
if (!DERELICT_GL3_RELOADED) {
|
||||||
|
DERELICT_GL3_RELOADED = true;
|
||||||
|
try {
|
||||||
|
Log.v("Reloading DerelictGL3");
|
||||||
|
import derelict.opengl3.gl3;
|
||||||
|
DerelictGL3.missingSymbolCallback = &gl3MissingSymFunc;
|
||||||
|
DerelictGL3.reload();
|
||||||
|
gl3ReloadedOk = true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("Derelict exception while reloading DerelictGL3", e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Log.v("Reloading DerelictGL");
|
||||||
|
import derelict.opengl3.gl;
|
||||||
|
DerelictGL.missingSymbolCallback = &gl3MissingSymFunc;
|
||||||
|
DerelictGL.reload();
|
||||||
|
glReloadedOk = true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("Derelict exception while reloading DerelictGL", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!gl3ReloadedOk && !glReloadedOk) {
|
||||||
|
Log.e("Neither DerelictGL3 nor DerelictGL were reloaded successfully");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!gl3ReloadedOk)
|
||||||
|
legacy = true;
|
||||||
|
else if (!glReloadedOk)
|
||||||
|
legacy = false;
|
||||||
|
if (!_glSupport) {
|
||||||
|
_glSupport = new GLSupport(legacy);
|
||||||
|
if (_glSupport.valid || _glSupport.initShaders()) {
|
||||||
|
Log.v("shaders are ok");
|
||||||
|
setOpenglEnabled();
|
||||||
|
Log.v("OpenGL is initialized ok");
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
Log.e("Failed to compile shaders");
|
||||||
|
// try opposite legacy flag
|
||||||
|
if (_glSupport.legacyMode == legacy) {
|
||||||
|
Log.i("Trying to reinit GLSupport with legacy flag ", !legacy);
|
||||||
|
_glSupport = new GLSupport(!legacy);
|
||||||
|
if (_glSupport.valid || _glSupport.initShaders()) {
|
||||||
|
Log.v("shaders are ok");
|
||||||
|
setOpenglEnabled();
|
||||||
|
Log.v("OpenGL is initialized ok");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_glSupport.valid || _glSupport.initShaders()) {
|
||||||
|
setOpenglEnabled();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
Log.e("Failed to compile shaders");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// OpenGL suport helper
|
||||||
class GLSupport {
|
class GLSupport {
|
||||||
|
|
||||||
private bool _legacyMode;
|
private bool _legacyMode;
|
||||||
|
|
|
@ -152,14 +152,6 @@ class SDLWindow : Window {
|
||||||
static if (ENABLE_OPENGL) {
|
static if (ENABLE_OPENGL) {
|
||||||
if (_enableOpengl)
|
if (_enableOpengl)
|
||||||
windowFlags |= SDL_WINDOW_OPENGL;
|
windowFlags |= SDL_WINDOW_OPENGL;
|
||||||
if (!_glSupport) {
|
|
||||||
version(OSX) {
|
|
||||||
bool useLegacyOpengl = false; //true;
|
|
||||||
} else {
|
|
||||||
bool useLegacyOpengl = false;
|
|
||||||
}
|
|
||||||
_glSupport = new GLSupport(useLegacyOpengl);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_win = SDL_CreateWindow(toUTF8(_caption).toStringz, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
_win = SDL_CreateWindow(toUTF8(_caption).toStringz, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||||
_dx, _dy,
|
_dx, _dy,
|
||||||
|
@ -200,21 +192,9 @@ class SDLWindow : Window {
|
||||||
Log.w("OpenGL support is disabled");
|
Log.w("OpenGL support is disabled");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_context && !_gl3Reloaded) {
|
if (_context && !_glSupport) {
|
||||||
try {
|
_enableOpengl = initGLSupport(false);
|
||||||
Log.d("Reloading DerelictGL3");
|
fixSize();
|
||||||
DerelictGL3.missingSymbolCallback = &gl3MissingSymFunc;
|
|
||||||
DerelictGL3.reload(GLVersion.GL21, GLVersion.GL40);
|
|
||||||
_gl3Reloaded = true;
|
|
||||||
if (!glSupport.valid && !glSupport.initShaders()) {
|
|
||||||
Log.e("Failed to initialize OpenGL - disabling OpenGL support");
|
|
||||||
_enableOpengl = false;
|
|
||||||
}
|
|
||||||
fixSize();
|
|
||||||
} catch (derelict.util.exception.SymbolLoadException e) {
|
|
||||||
Log.e("Exception in DerelictGL3.reload ", e);
|
|
||||||
_enableOpengl = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,56 +205,19 @@ class Win32Window : Window {
|
||||||
/* initialize OpenGL rendering */
|
/* initialize OpenGL rendering */
|
||||||
HDC hDC = GetDC(_hwnd);
|
HDC hDC = GetDC(_hwnd);
|
||||||
|
|
||||||
if (!DERELICT_GL3_RELOADED || openglEnabled) {
|
if (openglEnabled || !_glSupport) {
|
||||||
if (setupPixelFormat(hDC)) {
|
if (setupPixelFormat(hDC)) {
|
||||||
_hPalette = setupPalette(hDC);
|
_hPalette = setupPalette(hDC);
|
||||||
_hGLRC = wglCreateContext(hDC);
|
_hGLRC = wglCreateContext(hDC);
|
||||||
if (_hGLRC) {
|
if (_hGLRC) {
|
||||||
|
|
||||||
wglMakeCurrent(hDC, _hGLRC);
|
wglMakeCurrent(hDC, _hGLRC);
|
||||||
//_glSupport = _gl;
|
useOpengl = initGLSupport(false);
|
||||||
|
|
||||||
if (!DERELICT_GL3_RELOADED) {
|
|
||||||
// run this code only once
|
|
||||||
if (!_glSupport) {
|
|
||||||
Log.v("Creating OpenGL support");
|
|
||||||
_glSupport = new GLSupport(true);
|
|
||||||
Log.v("OpenGL support created");
|
|
||||||
}
|
|
||||||
|
|
||||||
DERELICT_GL3_RELOADED = true;
|
|
||||||
try {
|
|
||||||
import derelict.opengl3.gl3;
|
|
||||||
DerelictGL3.reload();
|
|
||||||
|
|
||||||
// successful
|
|
||||||
Log.v("initializing shaders");
|
|
||||||
if (glSupport.valid || glSupport.initShaders()) {
|
|
||||||
Log.v("shaders are ok");
|
|
||||||
setOpenglEnabled();
|
|
||||||
useOpengl = true;
|
|
||||||
Log.v("OpenGL is initialized ok");
|
|
||||||
} else {
|
|
||||||
Log.e("Failed to compile shaders");
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.e("Derelict exception", e);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (glSupport.valid || glSupport.initShaders()) {
|
|
||||||
setOpenglEnabled();
|
|
||||||
useOpengl = true;
|
|
||||||
} else {
|
|
||||||
Log.e("Failed to compile shaders");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
wglMakeCurrent(hDC, null);
|
wglMakeCurrent(hDC, null);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e("Pixelformat failed");
|
Log.e("Pixelformat failed");
|
||||||
// disable GL
|
// disable GL
|
||||||
DERELICT_GL3_RELOADED = true;
|
useOpengl = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue