Fix opengl support, switch to bindbc

This commit is contained in:
Grim Maple 2022-04-16 13:49:04 +03:00
parent 352f7f94f2
commit d19ff3c042
4 changed files with 59 additions and 152 deletions

View File

@ -18,7 +18,7 @@
], ],
"libs-linux": ["z"], "libs-linux": ["z"],
"stringImportPaths": [ "stringImportPaths": [
"views" "views"
], ],
@ -29,6 +29,12 @@
"sourceFiles-windows-x86-dmd": ["$PACKAGE_DIR/src/win_app.def"], "sourceFiles-windows-x86-dmd": ["$PACKAGE_DIR/src/win_app.def"],
"excludedSourceFiles-windows": ["3rdparty/fontconfig/*"], "excludedSourceFiles-windows": ["3rdparty/fontconfig/*"],
"dependencies": {
"bindbc-opengl": "~>1.0.0"
},
"versions": ["GL_AllowDeprecated", "GL_30"],
"subPackages": [ "subPackages": [
"./examples/helloworld/", "./examples/helloworld/",
"./examples/example1/", "./examples/example1/",
@ -50,7 +56,6 @@
"versions-windows": ["Unicode"], "versions-windows": ["Unicode"],
"libs-windows": ["opengl32"], "libs-windows": ["opengl32"],
"dependencies": { "dependencies": {
"derelict-gl3": "~>2.0.0-beta.8",
"derelict-ft": "~>2.0.0-beta.5", "derelict-ft": "~>2.0.0-beta.5",
"icontheme": "~>1.2.3" "icontheme": "~>1.2.3"
}, },
@ -74,7 +79,6 @@
"versions": ["USE_EXTERNAL"], "versions": ["USE_EXTERNAL"],
"libs-windows": ["opengl32"], "libs-windows": ["opengl32"],
"dependencies": { "dependencies": {
"derelict-gl3": "~>2.0.0-beta.8",
"derelict-ft": "~>2.0.0-beta.5", "derelict-ft": "~>2.0.0-beta.5",
"icontheme": "~>1.2.3" "icontheme": "~>1.2.3"
} }
@ -86,7 +90,6 @@
"versions-windows": ["Unicode" ,"NO_OPENGL"], "versions-windows": ["Unicode" ,"NO_OPENGL"],
"libs-windows": ["opengl32"], "libs-windows": ["opengl32"],
"dependencies-posix": { "dependencies-posix": {
"derelict-gl3": "~>2.0.0-beta.8",
"derelict-sdl2": "~>3.0.0-beta.8", "derelict-sdl2": "~>3.0.0-beta.8",
"derelict-ft": "~>2.0.0-beta.5", "derelict-ft": "~>2.0.0-beta.5",
"icontheme": "~>1.2.3" "icontheme": "~>1.2.3"
@ -97,17 +100,16 @@
"versions": ["USE_SDL", "USE_OPENGL", "USE_FREETYPE", "EmbedStandardResources"], "versions": ["USE_SDL", "USE_OPENGL", "USE_FREETYPE", "EmbedStandardResources"],
"versions-windows": ["Unicode"], "versions-windows": ["Unicode"],
"dependencies": { "dependencies": {
"derelict-gl3": "~>2.0.0-beta.8",
"derelict-ft": "~>2.0.0-beta.5", "derelict-ft": "~>2.0.0-beta.5",
"derelict-sdl2": "~>3.0.0-beta.8", "derelict-sdl2": "~>3.0.0-beta.8",
"icontheme": "~>1.2.3" "icontheme": "~>1.2.3"
}, },
"copyFiles-windows-x86_64": [ "copyFiles-windows-x86_64": [
"libs/windows/x86_64/libfreetype-6.dll", "libs/windows/x86_64/libfreetype-6.dll",
"libs/windows/x86_64/SDL2.dll", "libs/windows/x86_64/SDL2.dll"
], ],
"copyFiles-windows-x86": [ "copyFiles-windows-x86": [
"libs/windows/x86/libfreetype-6.dll", "libs/windows/x86/libfreetype-6.dll",
"libs/windows/x86/SDL2.dll" "libs/windows/x86/SDL2.dll"
] ]
}, },
@ -116,7 +118,6 @@
"versions": ["USE_X11", "USE_FREETYPE", "EmbedStandardResources"], "versions": ["USE_X11", "USE_FREETYPE", "EmbedStandardResources"],
"versions-windows": ["Unicode"], "versions-windows": ["Unicode"],
"dependencies": { "dependencies": {
"derelict-gl3": "~>2.0.0-beta.8",
"derelict-ft": "~>2.0.0-beta.5", "derelict-ft": "~>2.0.0-beta.5",
"x11": "~>1.0.21", "x11": "~>1.0.21",
"icontheme": "~>1.2.3" "icontheme": "~>1.2.3"
@ -127,7 +128,6 @@
"versions": ["USE_DSFML", "USE_OPENGL", "USE_FREETYPE", "EmbedStandardResources"], "versions": ["USE_DSFML", "USE_OPENGL", "USE_FREETYPE", "EmbedStandardResources"],
"versions-windows": ["Unicode"], "versions-windows": ["Unicode"],
"dependencies": { "dependencies": {
"derelict-gl3": "~>2.0.0-beta.7",
"derelict-ft": "~>2.0.0-beta.4", "derelict-ft": "~>2.0.0-beta.4",
"dsfml": "~>2.1.0", "dsfml": "~>2.1.0",
"icontheme": "~>1.2.3" "icontheme": "~>1.2.3"

View File

@ -33,8 +33,6 @@ extern (C) int UIAppMain(string[] args) {
static if (ENABLE_OPENGL): static if (ENABLE_OPENGL):
import derelict.opengl3.gl3;
import derelict.opengl3.gl;
import dlangui.graphics.glsupport; import dlangui.graphics.glsupport;
import dlangui.graphics.gldrawbuf; import dlangui.graphics.gldrawbuf;

View File

@ -48,31 +48,7 @@ version (Android) {
} else { } else {
enum SUPPORT_LEGACY_OPENGL = false; //true; enum SUPPORT_LEGACY_OPENGL = false; //true;
public import derelict.opengl; public import bindbc.opengl;
import derelict.util.exception;
//public import derelict.opengl.types;
//public import derelict.opengl.versions.base;
//public import derelict.opengl.versions.gl3x;
//public import derelict.opengl.gl;
derelict.util.exception.ShouldThrow gl3MissingSymFunc( string symName ) {
import std.algorithm : equal;
static import derelict.util.exception;
foreach(s; ["glGetError", "glShaderSource", "glCompileShader",
"glGetShaderiv", "glGetShaderInfoLog", "glGetString",
"glCreateProgram", "glUseProgram", "glDeleteProgram",
"glDeleteShader", "glEnable", "glDisable", "glBlendFunc",
"glUniformMatrix4fv", "glGetAttribLocation", "glGetUniformLocation",
"glGenVertexArrays", "glBindVertexArray", "glBufferData",
"glBindBuffer", "glBufferSubData"]) {
if (symName.equal(s)) // Symbol is used
return derelict.util.exception.ShouldThrow.Yes;
}
// Don't throw for unused symbol
return derelict.util.exception.ShouldThrow.No;
}
} }
import dlangui.graphics.scene.mesh; import dlangui.graphics.scene.mesh;
@ -668,40 +644,16 @@ bool initGLSupport(bool legacy = false) {
version(Android) { version(Android) {
Log.d("initGLSupport"); Log.d("initGLSupport");
} else { } else {
static bool DERELICT_GL3_RELOADED;
static bool gl3ReloadedOk; auto support = loadOpenGL();
static bool glReloadedOk; if(support < bindbc.opengl.GLSupport.gl11) // No context! Error!
if (!DERELICT_GL3_RELOADED) { {
DERELICT_GL3_RELOADED = true; Log.e("OpenGL wasn't loaded successfully");
try {
Log.v("Reloading DerelictGL3");
import derelict.opengl; //.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.opengl; //.gl;
DerelictGL3.missingSymbolCallback = &gl3MissingSymFunc;
DerelictGL3.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; return false;
} }
if (!gl3ReloadedOk) legacy = false;
legacy = true;
else if (!glReloadedOk)
legacy = false;
} }
if (!_glSupport) { 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");
int major = *cast(int*)(glGetString(GL_VERSION)[0 .. 1].ptr); int major = *cast(int*)(glGetString(GL_VERSION)[0 .. 1].ptr);
legacy = legacy || (major < 3); legacy = legacy || (major < 3);

View File

@ -160,7 +160,7 @@ static if (ENABLE_OPENGL) {
/// Shared opengl context helper /// Shared opengl context helper
struct SharedGLContext { struct SharedGLContext {
import derelict.opengl; //3.wgl; import bindbc.opengl;
HGLRC _hGLRC; // opengl context HGLRC _hGLRC; // opengl context
HPALETTE _hPalette; HPALETTE _hPalette;
@ -323,8 +323,6 @@ class Win32Window : Window {
EndPaint(_hwnd, &ps); EndPaint(_hwnd, &ps);
import derelict.opengl; //3.gl3;
import derelict.opengl; //3.wgl;
import dlangui.graphics.gldrawbuf; import dlangui.graphics.gldrawbuf;
//Log.d("onPaint() start drawing opengl viewport: ", _dx, "x", _dy); //Log.d("onPaint() start drawing opengl viewport: ", _dx, "x", _dy);
//PAINTSTRUCT ps; //PAINTSTRUCT ps;
@ -392,7 +390,7 @@ class Win32Window : Window {
destroy(_drawbuf); destroy(_drawbuf);
_drawbuf = null; _drawbuf = null;
} }
/* /*
static if (ENABLE_OPENGL) { static if (ENABLE_OPENGL) {
import derelict.opengl3.wgl; import derelict.opengl3.wgl;
@ -419,10 +417,10 @@ class Win32Window : Window {
} }
/// set handler for files dropped to app window /// set handler for files dropped to app window
override @property Window onFilesDropped(void delegate(string[]) handler) { override @property Window onFilesDropped(void delegate(string[]) handler) {
super.onFilesDropped(handler); super.onFilesDropped(handler);
DragAcceptFiles(_hwnd, handler ? TRUE : FALSE); DragAcceptFiles(_hwnd, handler ? TRUE : FALSE);
return this; return this;
} }
private long _nextExpectedTimerTs; private long _nextExpectedTimerTs;
@ -436,7 +434,7 @@ class Win32Window : Window {
if (_timerId && _nextExpectedTimerTs && _nextExpectedTimerTs < nextts + 10) if (_timerId && _nextExpectedTimerTs && _nextExpectedTimerTs < nextts + 10)
return; // don't reschedule timer, timer event will be received soon return; // don't reschedule timer, timer event will be received soon
if (_hwnd) { if (_hwnd) {
//_timerId = //_timerId =
SetTimer(_hwnd, _timerId, cast(uint)intervalMillis, null); SetTimer(_hwnd, _timerId, cast(uint)intervalMillis, null);
_nextExpectedTimerTs = nextts; _nextExpectedTimerTs = nextts;
} }
@ -488,9 +486,9 @@ class Win32Window : Window {
else else
adjustWindowOrContentSize(_mainWidget.measuredWidth, _mainWidget.measuredHeight); adjustWindowOrContentSize(_mainWidget.measuredWidth, _mainWidget.measuredHeight);
} }
adjustPositionDuringShow(); adjustPositionDuringShow();
if (_flags & WindowFlag.Fullscreen) { if (_flags & WindowFlag.Fullscreen) {
Rect rc = getScreenDimensions(); Rect rc = getScreenDimensions();
SetWindowPos(_hwnd, HWND_TOPMOST, 0, 0, rc.width, rc.height, SWP_SHOWWINDOW); SetWindowPos(_hwnd, HWND_TOPMOST, 0, 0, rc.width, rc.height, SWP_SHOWWINDOW);
@ -508,15 +506,15 @@ class Win32Window : Window {
override @property Window parentWindow() { override @property Window parentWindow() {
return _w32parent; return _w32parent;
} }
override protected void handleWindowActivityChange(bool isWindowActive) { override protected void handleWindowActivityChange(bool isWindowActive) {
super.handleWindowActivityChange(isWindowActive); super.handleWindowActivityChange(isWindowActive);
} }
override @property bool isActive() { override @property bool isActive() {
return _hwnd == GetForegroundWindow(); return _hwnd == GetForegroundWindow();
} }
override @property dstring windowCaption() const { override @property dstring windowCaption() const {
return _caption; return _caption;
} }
@ -584,7 +582,7 @@ class Win32Window : Window {
res = true; res = true;
} }
break; break;
case WindowState.normal: case WindowState.normal:
if (_windowState != WindowState.normal || activate) { if (_windowState != WindowState.normal || activate) {
ShowWindow(_hwnd, activate ? SW_SHOWNORMAL : SW_SHOWNA); // SW_RESTORE ShowWindow(_hwnd, activate ? SW_SHOWNORMAL : SW_SHOWNA); // SW_RESTORE
res = true; res = true;
@ -622,15 +620,15 @@ class Win32Window : Window {
} }
} }
} }
if (rectChanged) { if (rectChanged) {
handleWindowStateChange(newState, Rect(newWindowRect.left == int.min ? _windowRect.left : newWindowRect.left, handleWindowStateChange(newState, Rect(newWindowRect.left == int.min ? _windowRect.left : newWindowRect.left,
newWindowRect.top == int.min ? _windowRect.top : newWindowRect.top, newWindowRect.right == int.min ? _windowRect.right : newWindowRect.right, newWindowRect.top == int.min ? _windowRect.top : newWindowRect.top, newWindowRect.right == int.min ? _windowRect.right : newWindowRect.right,
newWindowRect.bottom == int.min ? _windowRect.bottom : newWindowRect.bottom)); newWindowRect.bottom == int.min ? _windowRect.bottom : newWindowRect.bottom));
} }
else else
handleWindowStateChange(newState, RECT_VALUE_IS_NOT_SET); handleWindowStateChange(newState, RECT_VALUE_IS_NOT_SET);
return res; return res;
} }
@ -652,7 +650,7 @@ class Win32Window : Window {
Log.d("Window.close()"); Log.d("Window.close()");
_platform.closeWindow(this); _platform.closeWindow(this);
} }
override protected void handleWindowStateChange(WindowState newState, Rect newWindowRect = RECT_VALUE_IS_NOT_SET) { override protected void handleWindowStateChange(WindowState newState, Rect newWindowRect = RECT_VALUE_IS_NOT_SET) {
if (_destroying) if (_destroying)
return; return;
@ -1175,22 +1173,22 @@ class Win32Platform : Platform {
if (mouseBuffer) if (mouseBuffer)
return res; // not supporetd under win32 return res; // not supporetd under win32
if (!IsClipboardFormatAvailable(CF_UNICODETEXT)) if (!IsClipboardFormatAvailable(CF_UNICODETEXT))
return res; return res;
if (!OpenClipboard(NULL)) if (!OpenClipboard(NULL))
return res; return res;
HGLOBAL hglb = GetClipboardData(CF_UNICODETEXT); HGLOBAL hglb = GetClipboardData(CF_UNICODETEXT);
if (hglb != NULL) if (hglb != NULL)
{ {
LPWSTR lptstr = cast(LPWSTR)GlobalLock(hglb); LPWSTR lptstr = cast(LPWSTR)GlobalLock(hglb);
if (lptstr != NULL) if (lptstr != NULL)
{ {
wstring w = fromWStringz(lptstr); wstring w = fromWStringz(lptstr);
res = normalizeEndOfLineCharacters(toUTF32(w)); res = normalizeEndOfLineCharacters(toUTF32(w));
GlobalUnlock(hglb); GlobalUnlock(hglb);
} }
} }
CloseClipboard(); CloseClipboard();
//Log.d("getClipboardText(", res, ")"); //Log.d("getClipboardText(", res, ")");
@ -1203,14 +1201,14 @@ class Win32Platform : Platform {
if (text.length < 1 || mouseBuffer) if (text.length < 1 || mouseBuffer)
return; return;
if (!OpenClipboard(NULL)) if (!OpenClipboard(NULL))
return; return;
EmptyClipboard(); EmptyClipboard();
wstring w = toUTF16(text); wstring w = toUTF16(text);
HGLOBAL hglbCopy = GlobalAlloc(GMEM_MOVEABLE, HGLOBAL hglbCopy = GlobalAlloc(GMEM_MOVEABLE,
cast(uint)((w.length + 1) * TCHAR.sizeof)); cast(uint)((w.length + 1) * TCHAR.sizeof));
if (hglbCopy == NULL) { if (hglbCopy == NULL) {
CloseClipboard(); CloseClipboard();
return; return;
} }
LPWSTR lptstrCopy = cast(LPWSTR)GlobalLock(hglbCopy); LPWSTR lptstrCopy = cast(LPWSTR)GlobalLock(hglbCopy);
for (int i = 0; i < w.length; i++) { for (int i = 0; i < w.length; i++) {
@ -1218,7 +1216,7 @@ class Win32Platform : Platform {
} }
lptstrCopy[w.length] = 0; lptstrCopy[w.length] = 0;
GlobalUnlock(hglbCopy); GlobalUnlock(hglbCopy);
SetClipboardData(CF_UNICODETEXT, hglbCopy); SetClipboardData(CF_UNICODETEXT, hglbCopy);
CloseClipboard(); CloseClipboard();
} }
@ -1254,7 +1252,7 @@ int DLANGUIWinMain(void* hInstance, void* hPrevInstance,
} }
extern(Windows) extern(Windows)
int DLANGUIWinMainProfile(string[] args) int DLANGUIWinMainProfile(string[] args)
{ {
int result; int result;
@ -1308,35 +1306,6 @@ string[] splitCmdLine(string line) {
private __gshared Win32Platform w32platform; private __gshared Win32Platform w32platform;
static if (ENABLE_OPENGL) {
import derelict.opengl; //3.gl3;
//import derelict.opengl3.gl;
void initOpenGL() {
try {
Log.d("Loading Derelict GL");
//DerelictGL.load();
DerelictGL3.load();
Log.d("Derelict GL - loaded");
//
//// just to check OpenGL context
//Log.i("Trying to setup OpenGL context");
//Win32Window tmpWindow = new Win32Window(w32platform, ""d, null, 0);
//destroy(tmpWindow);
//if (openglEnabled)
// Log.i("OpenGL support is enabled");
//else
// Log.w("OpenGL support is disabled");
//// process messages
//platform.enterMessageLoop();
} catch (Exception e) {
Log.e("Exception while trying to init OpenGL", e);
setOpenglEnabled(false);
}
}
}
int myWinMain(void* hInstance, void* hPrevInstance, char* lpCmdLine, int iCmdShow) int myWinMain(void* hInstance, void* hPrevInstance, char* lpCmdLine, int iCmdShow)
{ {
initLogs(); initLogs();
@ -1376,12 +1345,6 @@ int myWinMain(void* hInstance, void* hPrevInstance, char* lpCmdLine, int iCmdSho
currentTheme = createDefaultTheme(); currentTheme = createDefaultTheme();
static if (ENABLE_OPENGL) {
initOpenGL();
}
// Load versions 1.2+ and all supported ARB and EXT extensions.
Log.i("Entering UIAppMain: ", args); Log.i("Entering UIAppMain: ", args);
int result = -1; int result = -1;
try { try {
@ -1443,12 +1406,6 @@ int myWinMainProfile(string[] args)
currentTheme = createDefaultTheme(); currentTheme = createDefaultTheme();
static if (ENABLE_OPENGL) {
initOpenGL();
}
// Load versions 1.2+ and all supported ARB and EXT extensions.
Log.i("Entering UIAppMain: ", args); Log.i("Entering UIAppMain: ", args);
int result = -1; int result = -1;
try { try {
@ -1514,7 +1471,7 @@ LRESULT WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_WINDOWPOSCHANGED: case WM_WINDOWPOSCHANGED:
{ {
if (window !is null) { if (window !is null) {
if (IsIconic(hwnd)) { if (IsIconic(hwnd)) {
window.handleWindowStateChange(WindowState.minimized); window.handleWindowStateChange(WindowState.minimized);
} }
@ -1547,7 +1504,7 @@ LRESULT WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_ACTIVATE: case WM_ACTIVATE:
{ {
if (window) { if (window) {
if (wParam == WA_INACTIVE) if (wParam == WA_INACTIVE)
window.handleWindowActivityChange(false); window.handleWindowActivityChange(false);
else if (wParam == WA_ACTIVE || wParam == WA_CLICKACTIVE) else if (wParam == WA_ACTIVE || wParam == WA_CLICKACTIVE)
window.handleWindowActivityChange(true); window.handleWindowActivityChange(true);
@ -1617,7 +1574,7 @@ LRESULT WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
// not a key we map from generic to left/right specialized // not a key we map from generic to left/right specialized
// just return it. // just return it.
new_vk = vk; new_vk = vk;
break; break;
} }
if (window.onKey(message == WM_KEYDOWN || message == WM_SYSKEYDOWN ? KeyAction.KeyDown : KeyAction.KeyUp, cast(uint)new_vk, repeatCount, 0, message == WM_SYSKEYUP || message == WM_SYSKEYDOWN)) if (window.onKey(message == WM_KEYDOWN || message == WM_SYSKEYDOWN ? KeyAction.KeyDown : KeyAction.KeyUp, cast(uint)new_vk, repeatCount, 0, message == WM_SYSKEYUP || message == WM_SYSKEYDOWN))
@ -1657,9 +1614,9 @@ LRESULT WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
wchar[] buf; wchar[] buf;
auto count = DragQueryFileW(hdrop, 0xFFFFFFFF, cast(wchar*)NULL, 0); auto count = DragQueryFileW(hdrop, 0xFFFFFFFF, cast(wchar*)NULL, 0);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
auto sz = DragQueryFileW(hdrop, i, cast(wchar*)NULL, 0); auto sz = DragQueryFileW(hdrop, i, cast(wchar*)NULL, 0);
buf.length = sz + 2; buf.length = sz + 2;
sz = DragQueryFileW(hdrop, i, buf.ptr, sz + 1); sz = DragQueryFileW(hdrop, i, buf.ptr, sz + 1);
files ~= toUTF8(buf[0..sz]); files ~= toUTF8(buf[0..sz]);
} }
if (files.length) if (files.length)