mirror of
https://github.com/encounter/SDL.git
synced 2025-12-18 17:35:39 +00:00
Fixes #2308, recreate window if GL requirements for the renderer are not met
If the window has been created with values for SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_MAJOR_VERSION and SDL_GL_CONTEXT_MINOR_VERSION not matching those required by the renderer, attempt to recreate the window. This is needed on platforms where both GL and GLES 1/2 surfaces are supported by the video backend, requiring that the window be recreated when switching between context types.
This commit is contained in:
@@ -26,6 +26,9 @@
|
||||
#include "SDL_opengles.h"
|
||||
#include "../SDL_sysrender.h"
|
||||
|
||||
#define RENDERER_CONTEXT_MAJOR 1
|
||||
#define RENDERER_CONTEXT_MINOR 1
|
||||
|
||||
#if defined(SDL_VIDEO_DRIVER_PANDORA)
|
||||
|
||||
/* Empty function stub to get OpenGL ES 1.x support without */
|
||||
@@ -279,24 +282,24 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
|
||||
GLES_RenderData *data;
|
||||
GLint value;
|
||||
Uint32 windowFlags;
|
||||
int profileMask, majorVersion, minorVersion;
|
||||
int profile_mask, major, minor;
|
||||
|
||||
SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profileMask);
|
||||
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &majorVersion);
|
||||
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minorVersion);
|
||||
SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profile_mask);
|
||||
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
|
||||
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
|
||||
|
||||
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);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
|
||||
|
||||
windowFlags = SDL_GetWindowFlags(window);
|
||||
if (!(windowFlags & SDL_WINDOW_OPENGL) ||
|
||||
profileMask != SDL_GL_CONTEXT_PROFILE_ES || majorVersion != 1 || minorVersion != 1) {
|
||||
profile_mask != SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {
|
||||
if (SDL_RecreateWindow(window, windowFlags | SDL_WINDOW_OPENGL) < 0) {
|
||||
/* Uh oh, better try to put it back... */
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profileMask);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, majorVersion);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minorVersion);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
|
||||
SDL_RecreateWindow(window, windowFlags);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user