-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Legacy OpenGL example is broken #620
Comments
Oh, I think it was like that for eternity. IIRC in platform code it basically sticks to whatever API is available and won't ever try to recreate anything. But if you say that there is small bit of actual drawing maybe it is just glViewport or projection/model matrices or something was accidentally removed somewhere? |
I recently rewritten the window creation code to create a compatibility GL context. Which doesn't seem to work, unfortunately :( |
You mean core (aka forward compatible) context? I have implemented that locally for testing, Windows only though, can add PR for that, basically 20-30 lines of code including declarations and few changes to be able to reset internal stuff. |
There's no need to, as I already implemented it in c9ccaad . Multisampling is done the same way as getting compatibility GL context. I just need to figure out why said compatibility doesn't really work :) |
Umm, where do you call Or I am thinking about different thing here? |
I think that might be it, actually. I used |
Here is my local stuff I did for testing, patch file for reference. Windows only, other platforms does something similar except using their own variants like Basically my intent was to be able to use it in a game or at least use it as editor UI src/dlangui/graphics/glsupport.d | 7 +++++
src/dlangui/platforms/windows/winapp.d | 48 ++++++++++++++++++++++++++++++----
2 files changed, 50 insertions(+), 5 deletions(-)
diff --git a/src/dlangui/graphics/glsupport.d b/src/dlangui/graphics/glsupport.d
index e71f0f47..48cb32b3 100644
--- a/src/dlangui/graphics/glsupport.d
+++ b/src/dlangui/graphics/glsupport.d
@@ -662,6 +662,13 @@ private __gshared GLSupport _glSupport;
__gshared bool glNoContext;
+void resetGlSupport()
+{
+ if (_glSupport)
+ destroy(_glSupport);
+ _glSupport = null;
+}
+
/// initialize OpenGL support helper (call when current OpenGL context is initialized)
bool initGLSupport(bool legacy = false) {
import dlangui.platforms.common.platform : setOpenglEnabled;
diff --git a/src/dlangui/platforms/windows/winapp.d b/src/dlangui/platforms/windows/winapp.d
index d5af722e..3e04c763 100644
--- a/src/dlangui/platforms/windows/winapp.d
+++ b/src/dlangui/platforms/windows/winapp.d
@@ -45,6 +45,20 @@ import dlangui.core.files;
static if (ENABLE_OPENGL) {
import dlangui.graphics.glsupport;
+
+ alias PFNWGLSWAPINTERVALEXTPROC = extern(C) void function(GLint);
+ PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT;
+
+ // context creation
+
+ alias PFN_wglCreateContextAttribsARB = extern(C) HGLRC function(HDC hdc, HGLRC hShareContext, const int *attribList);
+ PFN_wglCreateContextAttribsARB wglCreateContextAttribsARB;
+
+ enum WGL_CONTEXT_MAJOR_VERSION_ARB = 0x2091;
+ enum WGL_CONTEXT_MINOR_VERSION_ARB = 0x2092;
+ enum WGL_CONTEXT_PROFILE_MASK_ARB = 0x9126;
+
+ enum WGL_CONTEXT_CORE_PROFILE_BIT_ARB = 0x00000001;
}
// specify debug=DebugMouseEvents for logging mouse handling
@@ -72,14 +86,14 @@ static if (ENABLE_OPENGL) {
PFD_DRAW_TO_WINDOW |
PFD_DOUBLEBUFFER, /* support double-buffering */
PFD_TYPE_RGBA, /* color type */
- 16, /* prefered color depth */
+ 32, /* prefered color depth */
0, 0, 0, 0, 0, 0, /* color bits (ignored) */
0, /* no alpha buffer */
0, /* alpha bits (ignored) */
0, /* no accumulation buffer */
0, 0, 0, 0, /* accum bits (ignored) */
- 16, /* depth buffer */
- 0, /* no stencil buffer */
+ 24, /* depth buffer */
+ 8, /* no stencil buffer */
0, /* no auxiliary buffers */
0, /* main layer PFD_MAIN_PLANE */
0, /* reserved */
@@ -184,6 +198,30 @@ static if (ENABLE_OPENGL) {
if (_hGLRC) {
bind(hDC);
bool initialized = initGLSupport(Platform.instance.GLVersionMajor < 3);
+
+ wglSwapIntervalEXT = cast(typeof(wglSwapIntervalEXT)) wglGetProcAddress("wglSwapIntervalEXT");
+ wglCreateContextAttribsARB = cast(PFN_wglCreateContextAttribsARB) wglGetProcAddress("wglCreateContextAttribsARB");
+
+ // Specify that we want to create an OpenGL 3.3 core profile context
+ int[] gl33_attribs = [
+ WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
+ WGL_CONTEXT_MINOR_VERSION_ARB, 3,
+ WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
+ 0,
+ ];
+
+ // try to create core context if possible
+ if (auto coreGLRC = wglCreateContextAttribsARB(hDC, null, gl33_attribs.ptr)) {
+ resetGlSupport();
+ wglMakeCurrent(hDC, null);
+ wglDeleteContext(_hGLRC);
+ _hGLRC = coreGLRC;
+ wglMakeCurrent(hDC, _hGLRC);
+ initialized = initGLSupport();
+ }
+
+ if (wglSwapIntervalEXT)
+ wglSwapIntervalEXT(0); // no vsync
unbind(hDC);
if (!initialized) {
uninit();
@@ -340,9 +378,9 @@ class Win32Window : Window {
float g = ((_backgroundColor >> 8) & 255) / 255.0f;
float b = ((_backgroundColor >> 0) & 255) / 255.0f;
glClearColor(r, g, b, a);
- glClear(GL_COLOR_BUFFER_BIT);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- GLDrawBuf buf = new GLDrawBuf(_dx, _dy, false);
+ scope GLDrawBuf buf = new GLDrawBuf(_dx, _dy, false);
buf.beforeDrawing();
static if (false) {
// for testing for render
|
Currenty it draws just some small bit on the bottom of the window.
The text was updated successfully, but these errors were encountered: