Add methods to create additional renderers.

This commit is contained in:
King_DuckZ 2017-03-03 23:01:43 +00:00
parent c6e7f68a0f
commit 012daa47d7
2 changed files with 50 additions and 0 deletions

View file

@ -27,6 +27,8 @@
#include <ciso646>
#include <cstring>
#include <utility>
#include <vector>
#include <algorithm>
#if defined(RASPBERRY_PI)
#include <bcm_host.h>
@ -73,6 +75,7 @@ namespace cloonel {
} //unnamed namespace
struct SDLMain::LocalData {
std::vector<SDL_Renderer*> 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<unsigned int>(m_localData->customRenderers.size());
}
///------------------------------------------------------------------------
///------------------------------------------------------------------------
SDL_Renderer* SDLMain::GetCustomRenderer (unsigned int parIndex) const {
assert(parIndex < static_cast<unsigned int>(m_localData->customRenderers.size()));
return m_localData->customRenderers[parIndex];
}
///------------------------------------------------------------------------
///------------------------------------------------------------------------
void SDLMain::SetResolution (ushort2 parRes) {

View file

@ -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 );