Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.
authorMarc Di Luzio <mdiluzio@feralinteractive.com>
Fri, 06 Mar 2015 16:03:40 +0000
changeset 94128b1436ce1028
parent 9411 6810478a60e9
child 9413 eb50f63a5777
Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL context when GLX_ARB_context_flush_control is available.

This extension allows the user to specify whether a full flush is performed when making a context not current.
The only way to set this currently is at context creation, so this patch provides that functionality.
Defualt behaviour is set at FLUSH, as per the spec.

This patch does not contain the changes to WGL, appleGL or other platforms as I do not have access to GL 4.5 hardware on those platforms.

Full details on the use of KHR_context_flush_control can be found here:
https://www.opengl.org/registry/specs/KHR/context_flush_control.txt
include/SDL_opengl_glext.h
include/SDL_video.h
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/x11/SDL_x11opengl.c
src/video/x11/SDL_x11opengl.h
     1.1 --- a/include/SDL_opengl_glext.h	Fri Mar 20 11:51:03 2015 -0400
     1.2 +++ b/include/SDL_opengl_glext.h	Fri Mar 06 16:03:40 2015 +0000
     1.3 @@ -2988,6 +2988,11 @@
     1.4  #define GL_ARB_framebuffer_sRGB 1
     1.5  #endif /* GL_ARB_framebuffer_sRGB */
     1.6  
     1.7 +#ifndef GL_KHR_context_flush_control
     1.8 +#define GL_CONTEXT_RELEASE_BEHAVIOR       0x82FB
     1.9 +#define GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH 0x82FC
    1.10 +#endif /* GL_KHR_context_flush_control */
    1.11 +
    1.12  #ifndef GL_ARB_geometry_shader4
    1.13  #define GL_ARB_geometry_shader4 1
    1.14  #define GL_LINES_ADJACENCY_ARB            0x000A
     2.1 --- a/include/SDL_video.h	Fri Mar 20 11:51:03 2015 -0400
     2.2 +++ b/include/SDL_video.h	Fri Mar 06 16:03:40 2015 +0000
     2.3 @@ -189,7 +189,8 @@
     2.4      SDL_GL_CONTEXT_FLAGS,
     2.5      SDL_GL_CONTEXT_PROFILE_MASK,
     2.6      SDL_GL_SHARE_WITH_CURRENT_CONTEXT,
     2.7 -    SDL_GL_FRAMEBUFFER_SRGB_CAPABLE
     2.8 +    SDL_GL_FRAMEBUFFER_SRGB_CAPABLE,
     2.9 +    SDL_GL_CONTEXT_RELEASE_BEHAVIOR
    2.10  } SDL_GLattr;
    2.11  
    2.12  typedef enum
    2.13 @@ -207,6 +208,12 @@
    2.14      SDL_GL_CONTEXT_RESET_ISOLATION_FLAG    = 0x0008
    2.15  } SDL_GLcontextFlag;
    2.16  
    2.17 +typedef enum
    2.18 +{
    2.19 +    SDL_GL_CONTEXT_RELEASE_BEHAVIOR_NONE   = 0x0000,
    2.20 +    SDL_GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH  = 0x0001
    2.21 +} SDL_GLcontextReleaseFlag;
    2.22 +
    2.23  
    2.24  /* Function prototypes */
    2.25  
     3.1 --- a/src/video/SDL_sysvideo.h	Fri Mar 20 11:51:03 2015 -0400
     3.2 +++ b/src/video/SDL_sysvideo.h	Fri Mar 06 16:03:40 2015 +0000
     3.3 @@ -303,6 +303,7 @@
     3.4          int flags;
     3.5          int profile_mask;
     3.6          int share_with_current_context;
     3.7 +        int release_behavior;
     3.8          int framebuffer_srgb_capable;
     3.9          int retained_backing;
    3.10          int driver_loaded;
     4.1 --- a/src/video/SDL_video.c	Fri Mar 20 11:51:03 2015 -0400
     4.2 +++ b/src/video/SDL_video.c	Fri Mar 06 16:03:40 2015 +0000
     4.3 @@ -2637,6 +2637,7 @@
     4.4  #endif
     4.5      _this->gl_config.flags = 0;
     4.6      _this->gl_config.framebuffer_srgb_capable = 0;
     4.7 +    _this->gl_config.release_behavior = SDL_GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH;
     4.8  
     4.9      _this->gl_config.share_with_current_context = 0;
    4.10  }
    4.11 @@ -2743,6 +2744,9 @@
    4.12      case SDL_GL_FRAMEBUFFER_SRGB_CAPABLE:
    4.13          _this->gl_config.framebuffer_srgb_capable = value;
    4.14          break;
    4.15 +    case SDL_GL_CONTEXT_RELEASE_BEHAVIOR:
    4.16 +        _this->gl_config.release_behavior = value;
    4.17 +        break;
    4.18      default:
    4.19          retval = SDL_SetError("Unknown OpenGL attribute");
    4.20          break;
    4.21 @@ -2845,6 +2849,13 @@
    4.22          attrib = GL_SAMPLES;
    4.23  #endif
    4.24          break;
    4.25 +    case SDL_GL_CONTEXT_RELEASE_BEHAVIOR:
    4.26 +#if SDL_VIDEO_OPENGL
    4.27 +        attrib = GL_CONTEXT_RELEASE_BEHAVIOR;
    4.28 +#else
    4.29 +        attrib = GL_CONTEXT_RELEASE_BEHAVIOR_KHR;
    4.30 +#endif
    4.31 +        break;
    4.32      case SDL_GL_BUFFER_SIZE:
    4.33          {
    4.34              GLint bits = 0;
     5.1 --- a/src/video/x11/SDL_x11opengl.c	Fri Mar 20 11:51:03 2015 -0400
     5.2 +++ b/src/video/x11/SDL_x11opengl.c	Fri Mar 06 16:03:40 2015 +0000
     5.3 @@ -122,6 +122,13 @@
     5.4  #define GLX_LATE_SWAPS_TEAR_EXT 0x20F3
     5.5  #endif
     5.6  
     5.7 +#ifndef GLX_ARB_context_flush_control
     5.8 +#define GLX_ARB_context_flush_control
     5.9 +#define GLX_CONTEXT_RELEASE_BEHAVIOR_ARB   0x2097
    5.10 +#define GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB           0x0000
    5.11 +#define GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB          0x2098
    5.12 +#endif
    5.13 +
    5.14  #define OPENGL_REQUIRES_DLOPEN
    5.15  #if defined(OPENGL_REQUIRES_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
    5.16  #include <dlfcn.h>
    5.17 @@ -375,6 +382,11 @@
    5.18      if (HasExtension("GLX_EXT_create_context_es2_profile", extensions)) {
    5.19          _this->gl_data->HAS_GLX_EXT_create_context_es2_profile = SDL_TRUE;
    5.20      }
    5.21 +
    5.22 +    /* Check for GLX_ARB_context_flush_control */
    5.23 +    if (HasExtension("GLX_ARB_context_flush_control", extensions)) {
    5.24 +        _this->gl_data->HAS_GLX_ARB_context_flush_control = SDL_TRUE;
    5.25 +    }
    5.26  }
    5.27  
    5.28  /* glXChooseVisual and glXChooseFBConfig have some small differences in
    5.29 @@ -581,8 +593,8 @@
    5.30              context =
    5.31                  _this->gl_data->glXCreateContext(display, vinfo, share_context, True);
    5.32          } else {
    5.33 -            /* max 8 attributes plus terminator */
    5.34 -            int attribs[9] = {
    5.35 +            /* max 10 attributes plus terminator */
    5.36 +            int attribs[11] = {
    5.37                  GLX_CONTEXT_MAJOR_VERSION_ARB,
    5.38                  _this->gl_config.major_version,
    5.39                  GLX_CONTEXT_MINOR_VERSION_ARB,
    5.40 @@ -603,6 +615,15 @@
    5.41                  attribs[iattr++] = _this->gl_config.flags;
    5.42              }
    5.43  
    5.44 +            /* only set if glx extension is available */
    5.45 +            if( _this->gl_data->HAS_GLX_ARB_context_flush_control ) {
    5.46 +                attribs[iattr++] = GLX_CONTEXT_RELEASE_BEHAVIOR_ARB;
    5.47 +                attribs[iattr++] = 
    5.48 +                    _this->gl_config.release_behavior ? 
    5.49 +                    GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB : 
    5.50 +                    GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB;
    5.51 +            }
    5.52 +
    5.53              attribs[iattr++] = 0;
    5.54  
    5.55              /* Get a pointer to the context creation function for GL 3.0 */
     6.1 --- a/src/video/x11/SDL_x11opengl.h	Fri Mar 20 11:51:03 2015 -0400
     6.2 +++ b/src/video/x11/SDL_x11opengl.h	Fri Mar 06 16:03:40 2015 +0000
     6.3 @@ -35,6 +35,7 @@
     6.4      SDL_bool HAS_GLX_EXT_visual_info;
     6.5      SDL_bool HAS_GLX_EXT_swap_control_tear;
     6.6      SDL_bool HAS_GLX_EXT_create_context_es2_profile;
     6.7 +    SDL_bool HAS_GLX_ARB_context_flush_control;
     6.8  
     6.9      Bool (*glXQueryExtension) (Display*,int*,int*);
    6.10      void *(*glXGetProcAddress) (const GLubyte*);