From 86b19d64c2692665aba33e44ee5db6cbf36b6342 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 13 Sep 2017 21:54:39 +0300 Subject: Add option to select any existing SDL renderer drivers for SDL2 default mode. --- src/utils/sdl2helper.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/utils/sdl2helper.h | 5 +++++ 2 files changed, 44 insertions(+) (limited to 'src/utils') diff --git a/src/utils/sdl2helper.cpp b/src/utils/sdl2helper.cpp index da86d2b41..ad559b0e6 100644 --- a/src/utils/sdl2helper.cpp +++ b/src/utils/sdl2helper.cpp @@ -28,10 +28,13 @@ #include "utils/sdl2logger.h" #include "utils/stringutils.h" +#include + PRAGMA48(GCC diagnostic push) PRAGMA48(GCC diagnostic ignored "-Wshadow") #include #include +#include #include PRAGMA48(GCC diagnostic pop) @@ -225,4 +228,40 @@ void SDL::allowScreenSaver(const bool allow) } } +void SDL::getRenderers(StringVect &list, + const std::string ¤tRenderer) +{ + SDL_RendererInfo info; + const int num = SDL_GetNumRenderDrivers(); + for (int f = 0; f < num; f ++) + { + if (!SDL_GetRenderDriverInfo(f, &info)) + list.push_back(info.name); + } + if (!currentRenderer.empty()) + { + bool found(false); + FOR_EACH (StringVectCIter, it, list) + { + if (*it == currentRenderer) + { + found = true; + break; + } + } + if (!found) + list.push_back(currentRenderer); + } + std::sort(list.begin(), list.end()); +} + +void SDL::setRendererHint(const std::string &driver) +{ + if (!driver.empty()) + { + SDL_SetHint(SDL_HINT_RENDER_DRIVER, + driver.c_str()); + } +} + #endif // USE_SDL2 diff --git a/src/utils/sdl2helper.h b/src/utils/sdl2helper.h index 4dbbad0f9..6c50bb1be 100644 --- a/src/utils/sdl2helper.h +++ b/src/utils/sdl2helper.h @@ -73,6 +73,11 @@ namespace SDL bool PollEvent(SDL_Event *event); void allowScreenSaver(const bool allow); + + void getRenderers(StringVect &list, + const std::string ¤tRenderer); + + void setRendererHint(const std::string &driver); } // namespace SDL #endif // USE_SDL2 -- cgit v1.2.3-60-g2f50