GNOME Bugzilla – Bug 756142
Bring back support for legacy OpenGL contexts
Last modified: 2015-10-07 15:23:45 UTC
We can sneak back in support for legacy GL contexts, as a fallback in case the underlying GL implementation does not support core 3.2 profiles. The important part is to ensure that any GL contexts created after the first one — i.e. the paint context for a GdkWindow — follow the same version of GL; if the paint context uses the legacy GL, then all GL contexts that are sharing resources with it must be legacy ones.
Created attachment 312759 [details] [review] gdk: Allow querying if a GL context is in legacy mode We want to have the ability to fall back to legacy GL contexts when creating them. In order to do so, we need to store the legacy bit on the GdkGLContext, as well as being able to query it. Setting the legacy bit from outside GDK is not possible; we cannot create GL contexts in 3.2 core profile *and* compatibility modes at the same time, and if we allowed users to select the legacy mode themselves, it would break the creation of the GdkWindow's paint GL context. What we do allow is falling back to legacy GL context if the platform does not support 3.2 core profiles — for instance, on older GPUs or inside virtualized environments. We are also going to use the legacy bit internally, to choose which GL API we can use when drawing GL content.
Created attachment 312760 [details] [review] gl: Store the legacy bit in the GL program data We need to know if we're using a legacy GL context in various places.
Created attachment 312761 [details] [review] gl: Use older GLSL shaders with legacy contexts If we're using modern GLSL, then we should stop using deprecated modifiers, like 'varying' and 'attribute', as well as deprecated global variables, like 'gl_FragColor'. On the other hand, with legacy contexts we should be using older GLSL shaders, to maximize compatibility.
Created attachment 312762 [details] [review] x11: Create legacy GLX contexts If GLX has support for the GLX_ARB_create_context_profile extension, then we use the GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; if it does not, we fall back to the old glXCreateNewContext() API. We use the shared GdkGLContext to decide whether the GLX context should use the legacy bit or not.
Created attachment 312763 [details] [review] x11: Control legacy GL context via environment variable For testing purposes, we may want to force the creation of legacy GLX contexts via an environment variable.
Created attachment 312765 [details] [review] fixup! x11: Create legacy GLX contexts
Created attachment 312767 [details] [review] Allow testglarea to work with legacy GL contexts Use the 1.30 GLSL shading language for the fragment and vertex shaders.
I pushed the rebased patch set to wip/ebassi/legacy-gl. With these patches, I can run testglarea using a GLX context created in legacy mode, and it works reasonably well. I haven't done Wayland — though it'd be pretty similar. I can very likely resurrect the changes needed to get legacy GL contexts on Windows from pre-3.16 master, but I wouldn't be able to test it.
Review of attachment 312759 [details] [review]: ::: gdk/gdkglcontext.c @@ +560,3 @@ + * @context: a #GdkGLContext + * + * Whether the #GdkGLContext is in legacy mode or not. I think there should be some explanation here (or in the long desc) what legacy mode actually means.
Review of attachment 312760 [details] [review]: ok
Review of attachment 312761 [details] [review]: ::: gdk/gdkgl.c @@ +151,2 @@ "#version 150\n" "uniform sampler2D map;" Missing \n ? I know these are probably optional, but if you have them everywhere else... @@ +207,2 @@ "#version 150\n" "uniform sampler2DRect map;" Missing \n ? @@ +223,3 @@ + static const char *vertex_shader_code_130 = + "#version 130\n" + "uniform sampler2DRect map;" Missing \n ?
Review of attachment 312762 [details] [review]: looks ok
Review of attachment 312762 [details] [review]: ::: gdk/x11/gdkglcontext-x11.c @@ +682,3 @@ + { + context_x11->glx_context = create_legacy_context (display, context_x11->glx_config, share); + legacy_bit = TRUE; Here you change the legacy_bit after you've already printed "legacy no" further up. Might be better to move the GDK_NOTE down and print the data for the gl context we actually ended up with ?
Review of attachment 312763 [details] [review]: ::: gdk/x11/gdkglcontext-x11.c @@ +639,3 @@ /* If there is no glXCreateContextAttribsARB() then we default to legacy */ + legacy_bit = !GDK_X11_DISPLAY (display)->has_glx_create_context || + g_getenv ("GDK_GL_USE_LEGACY") != NULL; I would prefer to extend the existing GDK_GL env var instead of adding more one-offs.
Review of attachment 312765 [details] [review]: I guess this answers my comment on the earlier patch
Review of attachment 312767 [details] [review]: not that I can read that GLSL code, but sure...
This looks ok to me, and somewhat important.
Created attachment 312791 [details] [review] gdk: Allow querying if a GL context is in legacy mode - v2
Created attachment 312792 [details] [review] gl: Store the legacy bit in the GL program data - v2
Created attachment 312793 [details] [review] gl: Use older GLSL shaders with legacy contexts - v2: Fixed the missing newlines
Created attachment 312794 [details] [review] x11: Create legacy GLX contexts - v2
Created attachment 312795 [details] [review] x11: Control legacy GL context via environment variable - v2: Ported to use GDK_GL instead of an ad hoc envvar
Created attachment 312796 [details] [review] Allow testglarea to work with legacy GL contexts - v2
Created attachment 312797 [details] [review] docs: Improve description of gdk_gl_context_is_legacy() Explain why this function is available, and why you may need it.
Looks all good to me now
Created attachment 312831 [details] [review] wayland: Allow falling back to compatibility EGL contexts If the shared context is in legacy mode, or if the creation of a core profile context failed, we fall back to an EGL context in compatibility mode. Since we're relying on a fairly new EGL implementation for Wayland, we don't fall back to the older EGL API, and instead we always require the EGL_KHR_create_context extension.
Had to do a couple of fixup runs because I'm dumb, and I was setting the compatibility bit on the flags instead of using it in the profile. By default, when I run testglarea on my Mesa 10.6.1 with GDK_DEBUG=opengl, I get: Realized GLX context[0x172a390], direct Making GLX context current to drawable 39845899 → OpenGL version: 3.3 Extensions checked: - GL_ARB_texture_non_power_of_two: yes - GL_ARB_texture_rectangle: yes - GL_EXT_framebuffer_blit: yes - GL_GREMEDY_frame_terminator: no When forcing legacy GL via GDK_GL=legacy, I get: Realized GLX context[0x2ff5a90], direct Making GLX context current to drawable 39845900 → OpenGL version: 3.0 Extensions checked: - GL_ARB_texture_non_power_of_two: yes - GL_ARB_texture_rectangle: yes - GL_EXT_framebuffer_blit: yes - GL_GREMEDY_frame_terminator: no
Pushed the latest wip/ebassi/legacy-gl branch to master.