mirror of https://github.com/encounter/SDL.git
Improve window recreation logic in OpenGL* renderers
This commit is contained in:
parent
0d5957dfee
commit
f61602b434
|
@ -32,8 +32,12 @@
|
||||||
#include <OpenGL/OpenGL.h>
|
#include <OpenGL/OpenGL.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* To prevent unnecessary window recreation,
|
||||||
|
* these should match the defaults selected in SDL_GL_ResetAttributes
|
||||||
|
*/
|
||||||
|
|
||||||
#define RENDERER_CONTEXT_MAJOR 2
|
#define RENDERER_CONTEXT_MAJOR 2
|
||||||
#define RENDERER_CONTEXT_MINOR 0
|
#define RENDERER_CONTEXT_MINOR 1
|
||||||
|
|
||||||
/* OpenGL renderer implementation */
|
/* OpenGL renderer implementation */
|
||||||
|
|
||||||
|
@ -389,13 +393,14 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
||||||
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
|
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
|
||||||
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
|
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
|
||||||
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
window_flags = SDL_GetWindowFlags(window);
|
||||||
|
if (!(window_flags & SDL_WINDOW_OPENGL) ||
|
||||||
|
profile_mask == SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {
|
||||||
|
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
|
||||||
|
|
||||||
window_flags = SDL_GetWindowFlags(window);
|
|
||||||
if (!(window_flags & SDL_WINDOW_OPENGL) ||
|
|
||||||
profile_mask != SDL_GL_CONTEXT_PROFILE_CORE || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {
|
|
||||||
if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
|
if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
|
||||||
/* Uh oh, better try to put it back... */
|
/* Uh oh, better try to put it back... */
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
|
||||||
|
|
|
@ -26,6 +26,10 @@
|
||||||
#include "SDL_opengles.h"
|
#include "SDL_opengles.h"
|
||||||
#include "../SDL_sysrender.h"
|
#include "../SDL_sysrender.h"
|
||||||
|
|
||||||
|
/* To prevent unnecessary window recreation,
|
||||||
|
* these should match the defaults selected in SDL_GL_ResetAttributes
|
||||||
|
*/
|
||||||
|
|
||||||
#define RENDERER_CONTEXT_MAJOR 1
|
#define RENDERER_CONTEXT_MAJOR 1
|
||||||
#define RENDERER_CONTEXT_MINOR 1
|
#define RENDERER_CONTEXT_MINOR 1
|
||||||
|
|
||||||
|
@ -288,13 +292,14 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
|
||||||
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
|
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
|
||||||
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
|
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
|
||||||
|
|
||||||
|
windowFlags = SDL_GetWindowFlags(window);
|
||||||
|
if (!(windowFlags & SDL_WINDOW_OPENGL) ||
|
||||||
|
profile_mask != SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {
|
||||||
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
|
||||||
|
|
||||||
windowFlags = SDL_GetWindowFlags(window);
|
|
||||||
if (!(windowFlags & SDL_WINDOW_OPENGL) ||
|
|
||||||
profile_mask != SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {
|
|
||||||
if (SDL_RecreateWindow(window, windowFlags | SDL_WINDOW_OPENGL) < 0) {
|
if (SDL_RecreateWindow(window, windowFlags | SDL_WINDOW_OPENGL) < 0) {
|
||||||
/* Uh oh, better try to put it back... */
|
/* Uh oh, better try to put it back... */
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
|
||||||
|
|
|
@ -28,6 +28,9 @@
|
||||||
#include "../../video/SDL_blit.h"
|
#include "../../video/SDL_blit.h"
|
||||||
#include "SDL_shaders_gles2.h"
|
#include "SDL_shaders_gles2.h"
|
||||||
|
|
||||||
|
/* To prevent unnecessary window recreation,
|
||||||
|
* these should match the defaults selected in SDL_GL_ResetAttributes
|
||||||
|
*/
|
||||||
#define RENDERER_CONTEXT_MAJOR 2
|
#define RENDERER_CONTEXT_MAJOR 2
|
||||||
#define RENDERER_CONTEXT_MINOR 0
|
#define RENDERER_CONTEXT_MINOR 0
|
||||||
|
|
||||||
|
@ -1749,13 +1752,14 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
|
||||||
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
|
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
|
||||||
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
|
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor);
|
||||||
|
|
||||||
|
windowFlags = SDL_GetWindowFlags(window);
|
||||||
|
if (!(windowFlags & SDL_WINDOW_OPENGL) ||
|
||||||
|
profile_mask != SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {
|
||||||
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR);
|
||||||
|
|
||||||
windowFlags = SDL_GetWindowFlags(window);
|
|
||||||
if (!(windowFlags & SDL_WINDOW_OPENGL) ||
|
|
||||||
profile_mask != SDL_GL_CONTEXT_PROFILE_ES || major != RENDERER_CONTEXT_MAJOR || minor != RENDERER_CONTEXT_MINOR) {
|
|
||||||
if (SDL_RecreateWindow(window, windowFlags | SDL_WINDOW_OPENGL) < 0) {
|
if (SDL_RecreateWindow(window, windowFlags | SDL_WINDOW_OPENGL) < 0) {
|
||||||
/* Uh oh, better try to put it back... */
|
/* Uh oh, better try to put it back... */
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, profile_mask);
|
||||||
|
|
Loading…
Reference in New Issue