summaryrefslogtreecommitdiff
path: root/gdk
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2023-04-26 18:08:59 +0200
committerBenjamin Otte <otte@redhat.com>2023-04-27 02:19:25 +0200
commit9254ab8503de0d12310c48d4f661a14608852b28 (patch)
tree9117e7593c1e0b929873ffb4585df209cba5257e /gdk
parentd6afcee1e4fd48fdeb6ccec63ac2287091c863d7 (diff)
downloadgtk+-9254ab8503de0d12310c48d4f661a14608852b28.tar.gz
wgl: Improve error messages when GL init fails
In particular, we want to get the GL version, when the Windows box/VM has an unsuitable GL implementation. This is somewhat helpful in analyzing failures to bring up GL on machines where users claim GL does work.
Diffstat (limited to 'gdk')
-rw-r--r--gdk/win32/gdkglcontext-win32-wgl.c71
1 files changed, 48 insertions, 23 deletions
diff --git a/gdk/win32/gdkglcontext-win32-wgl.c b/gdk/win32/gdkglcontext-win32-wgl.c
index b4b80dd065..f1efe9124e 100644
--- a/gdk/win32/gdkglcontext-win32-wgl.c
+++ b/gdk/win32/gdkglcontext-win32-wgl.c
@@ -328,10 +328,11 @@ gdk_win32_display_init_wgl (GdkDisplay *display,
/* Setup the legacy context after creating it */
static gboolean
-ensure_legacy_wgl_context (HDC hdc,
- HGLRC hglrc_legacy,
- GdkGLContext *share,
- GdkGLVersion *version)
+ensure_legacy_wgl_context (HDC hdc,
+ HGLRC hglrc_legacy,
+ GdkGLContext *share,
+ GdkGLVersion *version,
+ GError **error)
{
GdkWin32GLContextWGL *context_wgl;
GdkGLVersion legacy_version;
@@ -342,11 +343,25 @@ ensure_legacy_wgl_context (HDC hdc,
gdk_gl_version_get_minor (version)));
if (!wglMakeCurrent (hdc, hglrc_legacy))
- return FALSE;
+ {
+ g_set_error_literal (error, GDK_GL_ERROR,
+ GDK_GL_ERROR_NOT_AVAILABLE,
+ _("Unable to create a GL context"));
+ return FALSE;
+ }
gdk_gl_version_init_epoxy (&legacy_version);
if (!gdk_gl_version_greater_equal (&legacy_version, version))
- return FALSE;
+ {
+ g_set_error (error, GDK_GL_ERROR,
+ GDK_GL_ERROR_NOT_AVAILABLE,
+ _("WGL version %d.%d is too low, need at least %d.%d"),
+ gdk_gl_version_get_major (&legacy_version),
+ gdk_gl_version_get_minor (&legacy_version),
+ gdk_gl_version_get_major (version),
+ gdk_gl_version_get_minor (version));
+ return FALSE;
+ }
*version = legacy_version;
@@ -354,7 +369,13 @@ ensure_legacy_wgl_context (HDC hdc,
{
context_wgl = GDK_WIN32_GL_CONTEXT_WGL (share);
- return wglShareLists (hglrc_legacy, context_wgl->wgl_context);
+ if (!wglShareLists (hglrc_legacy, context_wgl->wgl_context))
+ {
+ g_set_error (error, GDK_GL_ERROR,
+ GDK_GL_ERROR_UNSUPPORTED_PROFILE,
+ _("GL implementation cannot share GL contexts"));
+ return FALSE;
+ }
}
return TRUE;
@@ -416,12 +437,13 @@ create_wgl_context_with_attribs (HDC hdc,
}
static HGLRC
-create_wgl_context (GdkGLContext *context,
- HDC hdc,
- gboolean hasWglARBCreateContext,
- GdkGLContext *share,
- int flags,
- gboolean legacy)
+create_wgl_context (GdkGLContext *context,
+ HDC hdc,
+ gboolean hasWglARBCreateContext,
+ GdkGLContext *share,
+ int flags,
+ gboolean legacy,
+ GError **error)
{
/* We need a legacy context for *all* cases */
HGLRC hglrc_base, hglrc;
@@ -431,7 +453,15 @@ create_wgl_context (GdkGLContext *context,
HGLRC hglrc_current = wglGetCurrentContext ();
hglrc_base = wglCreateContext (hdc);
- wglMakeCurrent (hdc, hglrc_base);
+ if (hglrc_base == NULL ||
+ !wglMakeCurrent (hdc, hglrc_base))
+ {
+ g_clear_pointer (&hglrc_base, wglDeleteContext);
+ g_set_error_literal (error, GDK_GL_ERROR,
+ GDK_GL_ERROR_NOT_AVAILABLE,
+ _("Unable to create a GL context"));
+ return 0;
+ }
hglrc = NULL;
@@ -473,7 +503,7 @@ create_wgl_context (GdkGLContext *context,
GDK_GL_API_GL,
TRUE,
&version);
- if (ensure_legacy_wgl_context (hdc, hglrc_base, share, &version))
+ if (ensure_legacy_wgl_context (hdc, hglrc_base, share, &version, error))
hglrc = g_steal_pointer (&hglrc_base);
}
@@ -585,15 +615,10 @@ gdk_win32_gl_context_wgl_realize (GdkGLContext *context,
display_win32->hasWglARBCreateContext,
share,
flags,
- legacy_bit);
-
+ legacy_bit,
+ error);
if (hglrc == NULL)
- {
- g_set_error_literal (error, GDK_GL_ERROR,
- GDK_GL_ERROR_NOT_AVAILABLE,
- _("Unable to create a GL context"));
- return 0;
- }
+ return 0;
GDK_NOTE (OPENGL,
g_print ("Created WGL context[%p], pixel_format=%d\n",