Navigation Menu

Skip to content

Commit

Permalink
Allow setting of GL_CONTEXT_RELEASE_BEHAVIOR when creating the GL con…
Browse files Browse the repository at this point in the history
…text 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
  • Loading branch information
Marc Di Luzio committed Mar 6, 2015
1 parent 70191a9 commit f5d9641
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
5 changes: 5 additions & 0 deletions include/SDL_opengl_glext.h
Expand Up @@ -2988,6 +2988,11 @@ GLAPI GLboolean APIENTRY glIsProgramARB (GLuint program);
#define GL_ARB_framebuffer_sRGB 1
#endif /* GL_ARB_framebuffer_sRGB */

#ifndef GL_KHR_context_flush_control
#define GL_CONTEXT_RELEASE_BEHAVIOR 0x82FB
#define GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH 0x82FC
#endif /* GL_KHR_context_flush_control */

#ifndef GL_ARB_geometry_shader4
#define GL_ARB_geometry_shader4 1
#define GL_LINES_ADJACENCY_ARB 0x000A
Expand Down
9 changes: 8 additions & 1 deletion include/SDL_video.h
Expand Up @@ -189,7 +189,8 @@ typedef enum
SDL_GL_CONTEXT_FLAGS,
SDL_GL_CONTEXT_PROFILE_MASK,
SDL_GL_SHARE_WITH_CURRENT_CONTEXT,
SDL_GL_FRAMEBUFFER_SRGB_CAPABLE
SDL_GL_FRAMEBUFFER_SRGB_CAPABLE,
SDL_GL_CONTEXT_RELEASE_BEHAVIOR
} SDL_GLattr;

typedef enum
Expand All @@ -207,6 +208,12 @@ typedef enum
SDL_GL_CONTEXT_RESET_ISOLATION_FLAG = 0x0008
} SDL_GLcontextFlag;

typedef enum
{
SDL_GL_CONTEXT_RELEASE_BEHAVIOR_NONE = 0x0000,
SDL_GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH = 0x0001
} SDL_GLcontextReleaseFlag;


/* Function prototypes */

Expand Down
1 change: 1 addition & 0 deletions src/video/SDL_sysvideo.h
Expand Up @@ -303,6 +303,7 @@ struct SDL_VideoDevice
int flags;
int profile_mask;
int share_with_current_context;
int release_behavior;
int framebuffer_srgb_capable;
int retained_backing;
int driver_loaded;
Expand Down
11 changes: 11 additions & 0 deletions src/video/SDL_video.c
Expand Up @@ -2637,6 +2637,7 @@ SDL_GL_ResetAttributes()
#endif
_this->gl_config.flags = 0;
_this->gl_config.framebuffer_srgb_capable = 0;
_this->gl_config.release_behavior = SDL_GL_CONTEXT_RELEASE_BEHAVIOR_FLUSH;

_this->gl_config.share_with_current_context = 0;
}
Expand Down Expand Up @@ -2743,6 +2744,9 @@ SDL_GL_SetAttribute(SDL_GLattr attr, int value)
case SDL_GL_FRAMEBUFFER_SRGB_CAPABLE:
_this->gl_config.framebuffer_srgb_capable = value;
break;
case SDL_GL_CONTEXT_RELEASE_BEHAVIOR:
_this->gl_config.release_behavior = value;
break;
default:
retval = SDL_SetError("Unknown OpenGL attribute");
break;
Expand Down Expand Up @@ -2843,6 +2847,13 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
attrib = GL_SAMPLES_ARB;
#else
attrib = GL_SAMPLES;
#endif
break;
case SDL_GL_CONTEXT_RELEASE_BEHAVIOR:
#if SDL_VIDEO_OPENGL
attrib = GL_CONTEXT_RELEASE_BEHAVIOR;
#else
attrib = GL_CONTEXT_RELEASE_BEHAVIOR_KHR;
#endif
break;
case SDL_GL_BUFFER_SIZE:
Expand Down
25 changes: 23 additions & 2 deletions src/video/x11/SDL_x11opengl.c
Expand Up @@ -122,6 +122,13 @@ typedef GLXContext(*PFNGLXCREATECONTEXTATTRIBSARBPROC) (Display * dpy,
#define GLX_LATE_SWAPS_TEAR_EXT 0x20F3
#endif

#ifndef GLX_ARB_context_flush_control
#define GLX_ARB_context_flush_control
#define GLX_CONTEXT_RELEASE_BEHAVIOR_ARB 0x2097
#define GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB 0x0000
#define GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB 0x2098
#endif

#define OPENGL_REQUIRES_DLOPEN
#if defined(OPENGL_REQUIRES_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
#include <dlfcn.h>
Expand Down Expand Up @@ -375,6 +382,11 @@ X11_GL_InitExtensions(_THIS)
if (HasExtension("GLX_EXT_create_context_es2_profile", extensions)) {
_this->gl_data->HAS_GLX_EXT_create_context_es2_profile = SDL_TRUE;
}

/* Check for GLX_ARB_context_flush_control */
if (HasExtension("GLX_ARB_context_flush_control", extensions)) {
_this->gl_data->HAS_GLX_ARB_context_flush_control = SDL_TRUE;
}
}

/* glXChooseVisual and glXChooseFBConfig have some small differences in
Expand Down Expand Up @@ -581,8 +593,8 @@ X11_GL_CreateContext(_THIS, SDL_Window * window)
context =
_this->gl_data->glXCreateContext(display, vinfo, share_context, True);
} else {
/* max 8 attributes plus terminator */
int attribs[9] = {
/* max 10 attributes plus terminator */
int attribs[11] = {
GLX_CONTEXT_MAJOR_VERSION_ARB,
_this->gl_config.major_version,
GLX_CONTEXT_MINOR_VERSION_ARB,
Expand All @@ -603,6 +615,15 @@ X11_GL_CreateContext(_THIS, SDL_Window * window)
attribs[iattr++] = _this->gl_config.flags;
}

/* only set if glx extension is available */
if( _this->gl_data->HAS_GLX_ARB_context_flush_control ) {
attribs[iattr++] = GLX_CONTEXT_RELEASE_BEHAVIOR_ARB;
attribs[iattr++] =
_this->gl_config.release_behavior ?
GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB :
GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB;
}

attribs[iattr++] = 0;

/* Get a pointer to the context creation function for GL 3.0 */
Expand Down
1 change: 1 addition & 0 deletions src/video/x11/SDL_x11opengl.h
Expand Up @@ -35,6 +35,7 @@ struct SDL_GLDriverData
SDL_bool HAS_GLX_EXT_visual_info;
SDL_bool HAS_GLX_EXT_swap_control_tear;
SDL_bool HAS_GLX_EXT_create_context_es2_profile;
SDL_bool HAS_GLX_ARB_context_flush_control;

Bool (*glXQueryExtension) (Display*,int*,int*);
void *(*glXGetProcAddress) (const GLubyte*);
Expand Down

0 comments on commit f5d9641

Please sign in to comment.