No API for releasing OpenGL context. (Issue #25951)

35 views
Skip to first unread message

dsa-t

unread,
Nov 4, 2025, 1:21:09 PM (5 days ago) Nov 4
to wx-...@googlegroups.com, Subscribed
dsa-t created an issue (wxWidgets/wxWidgets#25951)

Description

If I use:

    wxGLContextAttrs ctxAttrs;
    ctxAttrs.PlatformDefaults().ReleaseFlush().EndList();

    wxGLContext* context = new wxGLContext( aCanvas, aOther, &ctxAttrs );

to flush the calls, I have to release the context by doing (on MSW):

wglMakeCurrent( nullptr, nullptr );

but there doesn't appear to be an API within wx to do such a call.

Also, wxGLContextAttrs::ReleaseFlush is no-op in EGL but seems like it should be supported.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/25951@github.com>

VZ

unread,
Nov 4, 2025, 6:40:45 PM (5 days ago) Nov 4
to wx-...@googlegroups.com, Subscribed
vadz left a comment (wxWidgets/wxWidgets#25951)

Sorry, I know nothing about GLX_CONTEXT_RELEASE_BEHAVIOR_ARB (well, I've just quickly looked it up, so now I do know something, but not much), so I don't understand why does using it require calling wglMakeCurrent(0,0), but we could add a static void wxGLContext::ReleaseCurrent() wrapping it, of course. Would its implementation need to do glXMakeCurrent(0,0,0) and eglMakeCurrent(0,0,0,0) in GLX/EGL respectively? And under macOS it looks like we'd need to do [NSOpenGLContext clearCurrentContext], right?

cc @Manolo-ES


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/25951/3488400553@github.com>

dsa-t

unread,
Nov 4, 2025, 7:12:48 PM (5 days ago) Nov 4
to wx-...@googlegroups.com, Subscribed
dsa-t left a comment (wxWidgets/wxWidgets#25951)
  • WGL:
    wglMakeCurrent( NULL, NULL );
  • GLX:
    glXMakeContextCurrent( dpy, None, None, NULL ); for GLX > 1.2
    glXMakeCurrent( dpy, None, NULL ); for GLX <= 1.2
  • EGL:
    eglMakeCurrent( dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT );
  • Qt: looks like doneCurrent() can be used
  • Mac: clearCurrentContext seems correct.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/25951/3488511222@github.com>

VZ

unread,
Nov 4, 2025, 7:30:55 PM (5 days ago) Nov 4
to wx-...@googlegroups.com, Subscribed
vadz left a comment (wxWidgets/wxWidgets#25951)

OK, thanks, I'll add this soon.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/25951/3488556201@github.com>

VZ

unread,
Nov 4, 2025, 7:33:28 PM (5 days ago) Nov 4
to wx-...@googlegroups.com, Subscribed
vadz left a comment (wxWidgets/wxWidgets#25951)

Also, wxGLContextAttrs::ReleaseFlush is no-op in EGL but seems like it should be supported.

Sorry, forgot to ask: do you mean that we can reuse the same implementation as for GLX and have you already tested that it worked by chance? If not, how exactly can I test whether it works or not?

BTW, wxOSX and wxQt don't support this either, but let's leave this for a separate issue (if anybody cares enough to open one).


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/25951/3488561991@github.com>

dsa-t

unread,
Nov 4, 2025, 7:57:58 PM (5 days ago) Nov 4
to wx-...@googlegroups.com, Subscribed
dsa-t left a comment (wxWidgets/wxWidgets#25951)

do you mean that we can reuse the same implementation as for GLX

Except for EGL, the constants should be:

  • EGL_CONTEXT_RELEASE_BEHAVIOR_KHR

  • EGL_CONTEXT_RELEASE_BEHAVIOR_NONE_KHR
    EGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_KHR

have you already tested that it worked by chance?

I'm only testing on Windows for now and I see in the profiler that using ReleaseFlush + wglMakeCurrent( nullptr, nullptr ); does its thing.

If not, how exactly can I test whether it works or not?

I think you can query it:

    Accepted by the <pname> parameter of GetIntegerv, GetFloatv, GetBooleanv
    GetDoublev and GetInteger64v:

        GL_CONTEXT_RELEASE_BEHAVIOR                         0x82FB

    Returned in <data> by GetIntegerv, GetFloatv, GetBooleanv
    GetDoublev and GetInteger64v when <pname> is
    GL_CONTEXT_RELEASE_BEHAVIOR:

        GL_NONE                                             0x0000
        GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH                   0x82FC


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/25951/3488623231@github.com>

VZ

unread,
Nov 6, 2025, 5:55:55 PM (3 days ago) Nov 6
to wx-...@googlegroups.com, Subscribed
vadz left a comment (wxWidgets/wxWidgets#25951)

I've added this function in #25958 but I have some trouble with implementing support for this attribute for EGL: after adding

diff --git a/src/unix/glegl.cpp b/src/unix/glegl.cpp
index 78f8f3a6e0..af396b0ec0 100644
--- a/src/unix/glegl.cpp
+++ b/src/unix/glegl.cpp
@@ -125,8 +125,13 @@ wxGLContextAttrs& wxGLContextAttrs::ResetIsolation()
     return *this;
 }
 
-wxGLContextAttrs& wxGLContextAttrs::ReleaseFlush(int)
+wxGLContextAttrs& wxGLContextAttrs::ReleaseFlush(int val)
 {
+    AddAttribute(EGL_CONTEXT_RELEASE_BEHAVIOR_KHR);
+    if ( val == 1 )
+        AddAttribute(EGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_KHR);
+    else
+        AddAttribute(EGL_CONTEXT_RELEASE_BEHAVIOR_NONE_KHR);
     return *this;
 }
 

I've modified the sample like this:

diff --git a/samples/opengl/cube/cube.cpp b/samples/opengl/cube/cube.cpp
index f2b628ac9d..22107d9c88 100644
--- a/samples/opengl/cube/cube.cpp
+++ b/samples/opengl/cube/cube.cpp
@@ -128,11 +128,39 @@ static wxImage DrawDice(int size, unsigned num)
 // TestGLContext
 // ----------------------------------------------------------------------------
 
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+
+wxGLContextAttrs* GetAttrs()
+{
+    static wxGLContextAttrs s_attrs;
+    static bool s_initialized = false;
+
+    if ( !s_initialized )
+    {
+        s_attrs.PlatformDefaults().ReleaseFlush(0).EndList();
+        s_initialized = true;
+    }
+
+    return &s_attrs;
+}
+
 TestGLContext::TestGLContext(wxGLCanvas *canvas)
-             : wxGLContext(canvas)
+             : wxGLContext(canvas, nullptr, GetAttrs())
 {
     SetCurrent(*canvas);
 
+    EGLint value;
+    if (!eglQueryContext(eglGetCurrentDisplay(), eglGetCurrentContext(),
+                         EGL_CONTEXT_RELEASE_BEHAVIOR_KHR, &value))
+    {
+        wxLogDebug("eglQueryContext failed: %x", eglGetError());
+    }
+    else
+    {
+        wxLogDebug("EGL_CONTEXT_RELEASE_BEHAVIOR = %x", value);
+    }
+
     // set up the parameters we want to use
     glEnable(GL_CULL_FACE);
     glEnable(GL_DEPTH_TEST);

but this outputs

23:52:02: Debug: eglQueryContext failed: 3004

where 3004 is EGL_BAD_ATTRIBUTE. Do you see something obviously wrong here that I don't by chance?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issues/25951/3499720155@github.com>

VZ

unread,
Nov 8, 2025, 7:25:44 PM (yesterday) Nov 8
to wx-...@googlegroups.com, Subscribed

Closed #25951 as completed via f0309c9.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/issue/25951/issue_event/20814774961@github.com>

Reply all
Reply to author
Forward
0 new messages