Fixed bug 2575 - Current GL context tracking fails
authorSam Lantinga <slouken@libsdl.org>
Sun, 15 Jun 2014 18:09:39 -0700
changeset 8869553e9f7cd10e
parent 8868 55b16e3a3fc4
child 8870 cd1113741ade
Fixed bug 2575 - Current GL context tracking fails

Ronie Salgado

The GL Renderer current context tracking fails when one window is used with an SDL renderer but another separate window is used with a user handled OpenGL context.

Attached is a small program that reproduces this bug, at least in some Linux machines where an OpenGL renderer is provided by default.

Expected Output:
-"First window" should be blue.
-"Second window" should be green.

Gotten Output:
- "First window" black.
- "Second window" blue.

What happened:
The renderer created for the "first window" ends rendering into the "second window" OpenGL context.

Bug location:

SDL_render_gl.c - line 286 on hg:
static SDL_GLContext SDL_CurrentContext = NULL;

When making SDL_GL_MakeCurrent from the user perspective, that variable or the GL renderer is not notified about the OpenGL context change.

Solution proposal:
- Move the current GL context cache into another place global.
src/render/opengl/SDL_render_gl.c
     1.1 --- a/src/render/opengl/SDL_render_gl.c	Sun Jun 15 17:37:35 2014 -0700
     1.2 +++ b/src/render/opengl/SDL_render_gl.c	Sun Jun 15 18:09:39 2014 -0700
     1.3 @@ -290,7 +290,8 @@
     1.4  {
     1.5      GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
     1.6  
     1.7 -    if (SDL_CurrentContext != data->context) {
     1.8 +    if (SDL_CurrentContext != data->context ||
     1.9 +        SDL_GL_GetCurrentContext() != data->context) {
    1.10          if (SDL_GL_MakeCurrent(renderer->window, data->context) < 0) {
    1.11              return -1;
    1.12          }
    1.13 @@ -310,7 +311,7 @@
    1.14  {
    1.15      GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
    1.16  
    1.17 -    if (SDL_CurrentContext == data->context) {
    1.18 +    if (SDL_GL_GetCurrentContext() == data->context) {
    1.19          GL_UpdateViewport(renderer);
    1.20      } else {
    1.21          GL_ActivateRenderer(renderer);