From 65d74b2945754e376914ddd4599012ffd7abd1c0 Mon Sep 17 00:00:00 2001 From: Grim Maple Date: Tue, 25 Oct 2022 18:54:45 +0300 Subject: [PATCH] Fix X11 OpenGL support --- dub.json | 6 +++-- src/dlangui/platforms/x11/x11app.d | 43 +++++++++++++++++------------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/dub.json b/dub.json index 743834d1..d61db6d5 100644 --- a/dub.json +++ b/dub.json @@ -120,13 +120,15 @@ }, { "name": "x11", - "versions": ["USE_X11", "USE_FREETYPE", "EmbedStandardResources", "GL_32"], + "versions": ["USE_X11", "USE_FREETYPE", "EmbedStandardResources", "USE_OPENGL", "GL_32"], "versions-windows": ["Unicode"], + "libs-posix": ["GLX"], "dependencies": { "bindbc-opengl": "~>1.0.0", "bindbc-freetype": "~>1.0.0", "x11": "~>1.0.21", - "icontheme": "~>1.2.3" + "icontheme": "~>1.2.3", + "glx-d": "~>1.0.0" } }, { diff --git a/src/dlangui/platforms/x11/x11app.d b/src/dlangui/platforms/x11/x11app.d index 0a670eb8..01f4bd58 100644 --- a/src/dlangui/platforms/x11/x11app.d +++ b/src/dlangui/platforms/x11/x11app.d @@ -28,13 +28,12 @@ import x11.Xatom; import x11.X; static if (ENABLE_OPENGL) { - import derelict.opengl3.gl3; - import derelict.opengl3.gl; + import bindbc.opengl; import dlangui.graphics.gldrawbuf; import dlangui.graphics.glsupport; - import derelict.opengl3.glx; + import glx.glx; - private __gshared derelict.util.xtypes.XVisualInfo * x11visual; + private __gshared XVisualInfo * x11visual; private __gshared Colormap x11cmap; private __gshared bool _gl3Reloaded = false; } @@ -1292,6 +1291,8 @@ private immutable int TIMER_EVENT = 8; class X11Platform : Platform { this() { + static if(ENABLE_OPENGL) + _enableOpengl = true; import std.file : thisExePath; import std.path : baseName; _classname = (baseName(thisExePath()) ~ "\0").dup.ptr; @@ -1947,20 +1948,26 @@ extern(C) int DLANGUImain(string[] args) static if (ENABLE_OPENGL) { try { - DerelictGL3.missingSymbolCallback = &gl3MissingSymFunc; - DerelictGL3.load(); - DerelictGL.missingSymbolCallback = &gl3MissingSymFunc; - DerelictGL.load(); - Log.d("OpenGL library loaded ok"); - GLint[] att = [ GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None ]; - XWindow root; - root = DefaultRootWindow(x11display); - x11visual = glXChooseVisual(x11display, 0, cast(int*)att.ptr); - if (x11visual) { - x11cmap = XCreateColormap(x11display, root, cast(Visual*)x11visual.visual, AllocNone); - _enableOpengl = true; - } else { - Log.e("Cannot find suitable Visual for using of OpenGL"); + import bindbc.opengl : GLVersion = GLSupport; + GLVersion support = loadOpenGL(); + if(support == GLVersion.badLibrary) + { + _enableOpengl = false; + Log.e("Error loading OpenGL library"); + } + else + { + Log.d("OpenGL library loaded ok"); + GLint[] att = [ GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None ]; + XWindow root; + root = DefaultRootWindow(x11display); + x11visual = glXChooseVisual(x11display, 0, cast(int*)att.ptr); + if (x11visual) { + x11cmap = XCreateColormap(x11display, root, cast(Visual*)x11visual.visual, AllocNone); + _enableOpengl = true; + } else { + Log.e("Cannot find suitable Visual for using of OpenGL"); + } } } catch (Exception e) { Log.e("Cannot load OpenGL library", e);