From e61bbd634ca5be26842574011a8e69ebf9903dc5 Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Sat, 30 Oct 2021 10:12:30 +0300 Subject: [PATCH] Added fallback to SW SDL renderer. --- SpaceCadetPinball/winmain.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/SpaceCadetPinball/winmain.cpp b/SpaceCadetPinball/winmain.cpp index 73b2ddd..15c2c34 100644 --- a/SpaceCadetPinball/winmain.cpp +++ b/SpaceCadetPinball/winmain.cpp @@ -37,7 +37,7 @@ bool winmain::LaunchBallEnabled = true; bool winmain::HighScoresEnabled = true; bool winmain::DemoActive = false; char* winmain::BasePath; -int winmain::MainMenuHeight = 0; +int winmain::MainMenuHeight = 0; std::string winmain::FpsDetails; double winmain::UpdateToFrameRatio; winmain::DurationMs winmain::TargetFrameTime; @@ -88,18 +88,25 @@ int winmain::WinMain(LPCSTR lpCmdLine) return 1; } - SDL_Renderer* renderer = SDL_CreateRenderer - ( - window, - -1, - SDL_RENDERER_ACCELERATED - ); - Renderer = renderer; + // If HW fails, fallback to SW SDL renderer. + SDL_Renderer* renderer = nullptr; + for (int i = 0; i < 2 && !renderer; i++) + { + Renderer = renderer = SDL_CreateRenderer + ( + window, + -1, + i == 0 ? SDL_RENDERER_ACCELERATED : SDL_RENDERER_SOFTWARE + ); + } if (!renderer) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Could not create renderer", SDL_GetError(), window); return 1; } + SDL_RendererInfo rendererInfo{}; + if (!SDL_GetRendererInfo(renderer, &rendererInfo)) + printf("Using SDL renderer: %s\n", rendererInfo.name); SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest");