diff --git a/src/cloonelgraphics/sdlmain.cpp b/src/cloonelgraphics/sdlmain.cpp index 2e00bd1..a7c4e7a 100644 --- a/src/cloonelgraphics/sdlmain.cpp +++ b/src/cloonelgraphics/sdlmain.cpp @@ -27,6 +27,8 @@ #include #include #include +#include +#include #if defined(RASPBERRY_PI) #include @@ -73,6 +75,7 @@ namespace cloonel { } //unnamed namespace struct SDLMain::LocalData { + std::vector customRenderers; SDL_Window* window; SDL_Renderer* renderer; SizeRatio sizeratio; @@ -150,6 +153,10 @@ namespace cloonel { ///------------------------------------------------------------------------ ///------------------------------------------------------------------------ void SDLMain::ClearIFN (LocalData& parInitSDL) noexcept { + for (auto* renderer : m_localData->customRenderers) { + SDL_DestroyRenderer(renderer); + } + m_localData->customRenderers.clear(); if (parInitSDL.renderer) SDL_DestroyRenderer(parInitSDL.renderer); if (parInitSDL.window) @@ -175,6 +182,45 @@ namespace cloonel { return nullptr; } + ///------------------------------------------------------------------------ + ///------------------------------------------------------------------------ + SDL_Renderer* SDLMain::CreateRenderer() { + if (not m_localData->initialized) + return nullptr; + + const auto rendererDriver = GetRenderingDriver(); + SDL_Renderer* const new_renderer = SDL_CreateRenderer(m_localData->window, rendererDriver.first, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); + if (new_renderer) { + m_localData->customRenderers.push_back(new_renderer); + } + return new_renderer; + } + + ///------------------------------------------------------------------------ + ///------------------------------------------------------------------------ + void SDLMain::DestroyRenderer (SDL_Renderer* parRenderer) { + if (not parRenderer) + return; + + auto it_dele = std::find(m_localData->customRenderers.begin(), m_localData->customRenderers.end(), parRenderer); + if (m_localData->customRenderers.end() != it_dele) + m_localData->customRenderers.erase(it_dele); + SDL_DestroyRenderer(parRenderer); + } + + ///------------------------------------------------------------------------ + ///------------------------------------------------------------------------ + unsigned int SDLMain::CustomRenderersCount() const { + return static_cast(m_localData->customRenderers.size()); + } + + ///------------------------------------------------------------------------ + ///------------------------------------------------------------------------ + SDL_Renderer* SDLMain::GetCustomRenderer (unsigned int parIndex) const { + assert(parIndex < static_cast(m_localData->customRenderers.size())); + return m_localData->customRenderers[parIndex]; + } + ///------------------------------------------------------------------------ ///------------------------------------------------------------------------ void SDLMain::SetResolution (ushort2 parRes) { diff --git a/src/cloonelgraphics/sdlmain.hpp b/src/cloonelgraphics/sdlmain.hpp index 4cd56ee..cbb3f07 100644 --- a/src/cloonelgraphics/sdlmain.hpp +++ b/src/cloonelgraphics/sdlmain.hpp @@ -36,6 +36,10 @@ namespace cloonel { void Init ( void ); SDL_Renderer* GetRenderer ( void ); + SDL_Renderer* CreateRenderer ( void ); + unsigned int CustomRenderersCount ( void ) const; + SDL_Renderer* GetCustomRenderer ( unsigned int parIndex ) const; + void DestroyRenderer ( SDL_Renderer* parRenderer ); ushort2 WidthHeight ( void ) const noexcept; void SetResolution ( ushort2 parRes );