Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes bug #2040, prepare SDL_GL_CONTEXT_EGL for deprecation on v2.1
SDL_GL_CONTEXT_EGL = 1 is now internally treated as profile_mask = SDL_GL_CONTEXT_PROFILE_ES
  • Loading branch information
gabomdq committed Aug 29, 2013
1 parent eec4710 commit ace1e98
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/render/opengles/SDL_render_gles.c
Expand Up @@ -280,7 +280,7 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
GLint value;
Uint32 windowFlags;

SDL_GL_SetAttribute(SDL_GL_CONTEXT_EGL, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);

Expand Down
2 changes: 1 addition & 1 deletion src/render/opengles2/SDL_render_gles2.c
Expand Up @@ -1628,7 +1628,7 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
Uint32 windowFlags;
GLint window_framebuffer;

SDL_GL_SetAttribute(SDL_GL_CONTEXT_EGL, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);

Expand Down
28 changes: 17 additions & 11 deletions src/video/SDL_video.c
Expand Up @@ -477,26 +477,21 @@ SDL_VideoInit(const char *driver_name)
_this->gl_config.multisamplesamples = 0;
_this->gl_config.retained_backing = 1;
_this->gl_config.accelerated = -1; /* accelerated or not, both are fine */
_this->gl_config.profile_mask = 0;
#if SDL_VIDEO_OPENGL
_this->gl_config.major_version = 2;
_this->gl_config.minor_version = 1;
_this->gl_config.use_egl = 0;
#elif SDL_VIDEO_OPENGL_ES
_this->gl_config.major_version = 1;
_this->gl_config.minor_version = 1;
#if SDL_VIDEO_OPENGL_EGL
_this->gl_config.use_egl = 1;
#endif
_this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
#elif SDL_VIDEO_OPENGL_ES2
_this->gl_config.major_version = 2;
_this->gl_config.minor_version = 0;
#if SDL_VIDEO_OPENGL_EGL
_this->gl_config.use_egl = 1;
#endif

_this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
#endif
_this->gl_config.flags = 0;
_this->gl_config.profile_mask = 0;

_this->gl_config.share_with_current_context = 0;

_this->current_glwin_tls = SDL_TLSCreate();
Expand Down Expand Up @@ -2516,7 +2511,12 @@ SDL_GL_SetAttribute(SDL_GLattr attr, int value)
_this->gl_config.minor_version = value;
break;
case SDL_GL_CONTEXT_EGL:
_this->gl_config.use_egl = value;
/* FIXME: SDL_GL_CONTEXT_EGL to be deprecated in SDL 2.1 */
if (value != 0) {
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
} else {
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0);
};
break;
case SDL_GL_CONTEXT_FLAGS:
if( value & ~(SDL_GL_CONTEXT_DEBUG_FLAG |
Expand Down Expand Up @@ -2686,8 +2686,14 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
return 0;
}
case SDL_GL_CONTEXT_EGL:
/* FIXME: SDL_GL_CONTEXT_EGL to be deprecated in SDL 2.1 */
{
*value = _this->gl_config.use_egl;
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
*value = 1;
}
else {
*value = 0;
}
return 0;
}
case SDL_GL_CONTEXT_FLAGS:
Expand Down
49 changes: 22 additions & 27 deletions src/video/x11/SDL_x11opengl.c
Expand Up @@ -210,36 +210,31 @@ X11_GL_LoadLibrary(_THIS, const char *path)
/* Initialize extensions */
X11_GL_InitExtensions(_this);

/* If SDL_GL_CONTEXT_EGL has been changed to 1, and there's
* no GLX_EXT_create_context_es2_profile extension switch over to X11_GLES functions */
if (_this->gl_config.use_egl == 1) {
if (_this->gl_data->HAS_GLX_EXT_create_context_es2_profile) {
/* We cheat a little bit here by using GLX instead of EGL
* to improve our chances of getting hardware acceleration */
_this->gl_config.use_egl = 0;
_this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
} else {
/* If we need a GL ES context and there's no
* GLX_EXT_create_context_es2_profile extension, switch over to X11_GLES functions
*/
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES &&
! _this->gl_data->HAS_GLX_EXT_create_context_es2_profile ) {
#if SDL_VIDEO_OPENGL_EGL
X11_GL_UnloadLibrary(_this);
/* Better avoid conflicts! */
if (_this->gl_config.dll_handle != NULL ) {
GL_UnloadObject(_this->gl_config.dll_handle);
_this->gl_config.dll_handle = NULL;
}
_this->GL_LoadLibrary = X11_GLES_LoadLibrary;
_this->GL_GetProcAddress = X11_GLES_GetProcAddress;
_this->GL_UnloadLibrary = X11_GLES_UnloadLibrary;
_this->GL_CreateContext = X11_GLES_CreateContext;
_this->GL_MakeCurrent = X11_GLES_MakeCurrent;
_this->GL_SetSwapInterval = X11_GLES_SetSwapInterval;
_this->GL_GetSwapInterval = X11_GLES_GetSwapInterval;
_this->GL_SwapWindow = X11_GLES_SwapWindow;
_this->GL_DeleteContext = X11_GLES_DeleteContext;
return X11_GLES_LoadLibrary(_this, NULL);
X11_GL_UnloadLibrary(_this);
/* Better avoid conflicts! */
if (_this->gl_config.dll_handle != NULL ) {
GL_UnloadObject(_this->gl_config.dll_handle);
_this->gl_config.dll_handle = NULL;
}
_this->GL_LoadLibrary = X11_GLES_LoadLibrary;
_this->GL_GetProcAddress = X11_GLES_GetProcAddress;
_this->GL_UnloadLibrary = X11_GLES_UnloadLibrary;
_this->GL_CreateContext = X11_GLES_CreateContext;
_this->GL_MakeCurrent = X11_GLES_MakeCurrent;
_this->GL_SetSwapInterval = X11_GLES_SetSwapInterval;
_this->GL_GetSwapInterval = X11_GLES_GetSwapInterval;
_this->GL_SwapWindow = X11_GLES_SwapWindow;
_this->GL_DeleteContext = X11_GLES_DeleteContext;
return X11_GLES_LoadLibrary(_this, NULL);
#else
return SDL_SetError("SDL not configured with EGL support");
return SDL_SetError("SDL not configured with EGL support");
#endif
}
}

return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/video/x11/SDL_x11opengles.c
Expand Up @@ -33,8 +33,8 @@ X11_GLES_LoadLibrary(_THIS, const char *path) {

SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;

/* If SDL_GL_CONTEXT_EGL has been changed to 0, switch over to X11_GL functions */
if (_this->gl_config.use_egl == 0) {
/* If the profile requested is not GL ES, switch over to X11_GL functions */
if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) {
#if SDL_VIDEO_OPENGL_GLX
_this->GL_LoadLibrary = X11_GL_LoadLibrary;
_this->GL_GetProcAddress = X11_GL_GetProcAddress;
Expand Down
10 changes: 7 additions & 3 deletions src/video/x11/SDL_x11window.c
Expand Up @@ -366,10 +366,11 @@ X11_CreateWindow(_THIS, SDL_Window * window)

#if SDL_VIDEO_OPENGL_GLX || SDL_VIDEO_OPENGL_EGL
if (window->flags & SDL_WINDOW_OPENGL) {
XVisualInfo *vinfo;
XVisualInfo *vinfo = NULL;

#if SDL_VIDEO_OPENGL_EGL
if (_this->gl_config.use_egl == 1) {
if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES &&
( !_this->gl_data || ! _this->gl_data->HAS_GLX_EXT_create_context_es2_profile )) {
vinfo = X11_GLES_GetVisual(_this, display, screen);
} else
#endif
Expand All @@ -378,6 +379,7 @@ X11_CreateWindow(_THIS, SDL_Window * window)
vinfo = X11_GL_GetVisual(_this, display, screen);
#endif
}

if (!vinfo) {
return -1;
}
Expand Down Expand Up @@ -551,7 +553,9 @@ X11_CreateWindow(_THIS, SDL_Window * window)
windowdata = (SDL_WindowData *) window->driverdata;

#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
if ((window->flags & SDL_WINDOW_OPENGL) && (_this->gl_config.use_egl == 1)) {
if ((window->flags & SDL_WINDOW_OPENGL) &&
_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES &&
(!_this->gl_data || ! _this->gl_data->HAS_GLX_EXT_create_context_es2_profile) ) {
if (!_this->egl_data) {
XDestroyWindow(display, w);
return -1;
Expand Down

0 comments on commit ace1e98

Please sign in to comment.