sdl: fall back to open gl if vulkan init fails

This commit is contained in:
flyinghead 2021-01-16 19:09:22 +01:00
parent 49627eaf53
commit 417b470cbb
4 changed files with 19 additions and 12 deletions

View File

@ -691,7 +691,8 @@ bool VulkanContext::Init()
std::vector<const char *> extensions; std::vector<const char *> extensions;
extensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME); extensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
#if defined(USE_SDL) #if defined(USE_SDL)
sdl_recreate_window(SDL_WINDOW_VULKAN); if (!sdl_recreate_window(SDL_WINDOW_VULKAN))
return false;
uint32_t extensionsCount = 0; uint32_t extensionsCount = 0;
SDL_Vulkan_GetInstanceExtensions((SDL_Window *)window, &extensionsCount, NULL); SDL_Vulkan_GetInstanceExtensions((SDL_Window *)window, &extensionsCount, NULL);
extensions.resize(extensionsCount + 1); extensions.resize(extensionsCount + 1);

View File

@ -271,7 +271,7 @@ static void get_window_state()
SDL_GetWindowSize(window, &window_width, &window_height); SDL_GetWindowSize(window, &window_width, &window_height);
} }
void sdl_recreate_window(u32 flags) bool sdl_recreate_window(u32 flags)
{ {
int x = SDL_WINDOWPOS_UNDEFINED; int x = SDL_WINDOWPOS_UNDEFINED;
int y = SDL_WINDOWPOS_UNDEFINED; int y = SDL_WINDOWPOS_UNDEFINED;
@ -295,8 +295,11 @@ void sdl_recreate_window(u32 flags)
flags |= SDL_WINDOW_MAXIMIZED; flags |= SDL_WINDOW_MAXIMIZED;
#endif #endif
window = SDL_CreateWindow("Flycast", x, y, window_width, window_height, flags); window = SDL_CreateWindow("Flycast", x, y, window_width, window_height, flags);
if (!window) if (window == nullptr)
die("error creating SDL window"); {
ERROR_LOG(COMMON, "Window creation failed: %s", SDL_GetError());
return false;
}
#ifndef _WIN32 #ifndef _WIN32
// Set the window icon // Set the window icon
@ -305,7 +308,7 @@ void sdl_recreate_window(u32 flags)
pixels[i] = reicast_icon[i + 2]; pixels[i] = reicast_icon[i + 2];
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(pixels, 48, 48, 32, 4 * 48, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(pixels, 48, 48, 32, 4 * 48, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
if (surface == NULL) if (surface == NULL)
INFO_LOG(COMMON, "Creating surface failed: %s", SDL_GetError()); INFO_LOG(COMMON, "Creating icon surface failed: %s", SDL_GetError());
else else
{ {
SDL_SetWindowIcon(window, surface); SDL_SetWindowIcon(window, surface);
@ -317,6 +320,8 @@ void sdl_recreate_window(u32 flags)
theVulkanContext.SetWindow(window, nullptr); theVulkanContext.SetWindow(window, nullptr);
#endif #endif
theGLContext.SetWindow(window); theGLContext.SetWindow(window);
return true;
} }
void sdl_window_create() void sdl_window_create()

View File

@ -2,12 +2,12 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "types.h" #include "types.h"
extern void input_sdl_init(); void input_sdl_init();
extern void input_sdl_handle(); void input_sdl_handle();
extern void sdl_window_create(); void sdl_window_create();
extern void sdl_window_set_text(const char* text); void sdl_window_set_text(const char* text);
extern void sdl_window_destroy(); void sdl_window_destroy();
extern void sdl_recreate_window(u32 flags); bool sdl_recreate_window(u32 flags);
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>

View File

@ -47,7 +47,8 @@ bool SDLGLGraphicsContext::Init()
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
sdl_recreate_window(SDL_WINDOW_OPENGL); if (!sdl_recreate_window(SDL_WINDOW_OPENGL))
return false;
glcontext = SDL_GL_CreateContext(window); glcontext = SDL_GL_CreateContext(window);
if (!glcontext) if (!glcontext)