close window when falling back to opengles
This commit is contained in:
parent
ca22e52327
commit
dc9e312b4d
|
@ -44,6 +44,24 @@ static void update_viewport(void) {
|
||||||
GLRenderer_SetViewport(vp_x, vp_y, vp_width, vp_height);
|
GLRenderer_SetViewport(vp_x, vp_y, vp_width, vp_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void create_glcore_context(char* title) {
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
|
||||||
|
|
||||||
|
window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, window_width, window_height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
||||||
|
context = SDL_GL_CreateContext(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void create_gles_context(char* title) {
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
||||||
|
|
||||||
|
window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, window_width, window_height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
||||||
|
context = SDL_GL_CreateContext(window);
|
||||||
|
}
|
||||||
|
|
||||||
static void* create_window_and_renderer(char* title, int x, int y, int width, int height) {
|
static void* create_window_and_renderer(char* title, int x, int y, int width, int height) {
|
||||||
window_width = width;
|
window_width = width;
|
||||||
window_height = height;
|
window_height = height;
|
||||||
|
@ -55,28 +73,22 @@ static void* create_window_and_renderer(char* title, int x, int y, int width, in
|
||||||
LOG_PANIC("SDL_INIT_VIDEO error: %s", SDL_GetError());
|
LOG_PANIC("SDL_INIT_VIDEO error: %s", SDL_GetError());
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_GL_SetSwapInterval(1);
|
|
||||||
|
|
||||||
// prefer OpenGL core profile
|
// prefer OpenGL core profile
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
create_glcore_context(title);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
|
|
||||||
opengl_profile = eOpenGL_profile_core;
|
opengl_profile = eOpenGL_profile_core;
|
||||||
window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
|
||||||
context = SDL_GL_CreateContext(window);
|
|
||||||
|
|
||||||
if (window == NULL || context == NULL) {
|
if (window == NULL || context == NULL) {
|
||||||
|
if (window != NULL) {
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
}
|
||||||
|
|
||||||
LOG_WARN("Failed to create OpenGL core profile: %s. Trying OpenGLES...", SDL_GetError());
|
LOG_WARN("Failed to create OpenGL core profile: %s. Trying OpenGLES...", SDL_GetError());
|
||||||
// fallback to OpenGL ES 3
|
// fallback to OpenGL ES 3
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
create_gles_context(title);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
|
||||||
opengl_profile = eOpenGL_profile_es;
|
opengl_profile = eOpenGL_profile_es;
|
||||||
window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
|
|
||||||
context = SDL_GL_CreateContext(window);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window == NULL || context == NULL) {
|
if (window == NULL || context == NULL) {
|
||||||
LOG_PANIC("Failed to create window. %s", SDL_GetError());
|
LOG_PANIC("Failed to create OpenGL context: %s", SDL_GetError());
|
||||||
}
|
}
|
||||||
|
|
||||||
sdl_window_scale.x = ((float)render_width) / width;
|
sdl_window_scale.x = ((float)render_width) / width;
|
||||||
|
@ -92,6 +104,8 @@ static void* create_window_and_renderer(char* title, int x, int y, int width, in
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_GL_SetSwapInterval(1);
|
||||||
|
|
||||||
GLRenderer_Init(opengl_profile, render_width, render_height);
|
GLRenderer_Init(opengl_profile, render_width, render_height);
|
||||||
update_viewport();
|
update_viewport();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue