diff --git a/SDLWrapper/Renderer.cpp b/SDLWrapper/Renderer.cpp index 89a25d7..85322ff 100644 --- a/SDLWrapper/Renderer.cpp +++ b/SDLWrapper/Renderer.cpp @@ -20,6 +20,40 @@ SDL_Renderer* Renderer::_get() const return _rnd.get(); } +// private +int Renderer::_createRenderer_Real(Window& wnd,Uint32 flags) +{ + SDL_Renderer* pSDLRnd=SDL_CreateRenderer(wnd._get(), -1, flags); + if(pSDLRnd!=nullptr) + { + _set(pSDLRnd); + return 0; + } + else + { + return -1; + } +} + +// private +Uint32 Renderer::_rendertype_caster(RendererType Type) +{ + switch(Type) + { + case RendererType::Accelerated: + return SDL_RENDERER_ACCELERATED; + case RendererType::PresentSync: + return SDL_RENDERER_PRESENTVSYNC; + case RendererType::Software: + return SDL_RENDERER_SOFTWARE; + case RendererType::TargetTexture: + return SDL_RENDERER_TARGETTEXTURE; + } + + /// If an error occurs, return 0 by default. + return 0; +} + Renderer::Renderer(Window& wnd,std::initializer_list RendererFlags) throw (ErrorViewer) { if(createRenderer(wnd,RendererFlags)!=0) @@ -28,6 +62,14 @@ Renderer::Renderer(Window& wnd,std::initializer_list RendererFlags } } +Renderer::Renderer(Surface& surf) throw (ErrorViewer) +{ + if(createSoftRenderer(surf)!=0) + { + throw ErrorViewer(); + } +} + int Renderer::createRenderer(Window& wnd,std::initializer_list RendererFlags) { Uint32 flag = 0; @@ -38,6 +80,20 @@ int Renderer::createRenderer(Window& wnd,std::initializer_list Ren return _createRenderer_Real(wnd,flag); } +int Renderer::createSoftRenderer(Surface& surf) +{ + SDL_Renderer* pRnd=SDL_CreateSoftwareRenderer(surf._get()); + if(pRnd!=nullptr) + { + _set(pRnd); + return 0; + } + else + { + return -1; + } +} + int Renderer::setColor(const RGBA& pack) { return SDL_SetRenderDrawColor(_get(), pack.r, pack.g, pack.b, pack.a); @@ -456,38 +512,4 @@ int Renderer::GetDriversNum() return SDL_GetNumRenderDrivers(); } -// private -Uint32 Renderer::_rendertype_caster(RendererType Type) -{ - switch(Type) - { - case RendererType::Accelerated: - return SDL_RENDERER_ACCELERATED; - case RendererType::PresentSync: - return SDL_RENDERER_PRESENTVSYNC; - case RendererType::Software: - return SDL_RENDERER_SOFTWARE; - case RendererType::TargetTexture: - return SDL_RENDERER_TARGETTEXTURE; - } - - /// If an error occurs, return 0 by default. - return 0; -} - -// private -int Renderer::_createRenderer_Real(Window& wnd,Uint32 flags) -{ - SDL_Renderer* pSDLRnd=SDL_CreateRenderer(wnd._get(), -1, flags); - if(pSDLRnd!=nullptr) - { - _set(pSDLRnd); - return 0; - } - else - { - return -1; - } -} - #include "end_code.h" diff --git a/SDLWrapper/Renderer.h b/SDLWrapper/Renderer.h index 6faa64e..b26084b 100644 --- a/SDLWrapper/Renderer.h +++ b/SDLWrapper/Renderer.h @@ -11,7 +11,10 @@ class Renderer { public: Renderer() = default; + /// Create a Renderer associated with Window Renderer(Window& wnd,std::initializer_list RendererFlags = { RendererType::Accelerated,RendererType::TargetTexture }) throw (ErrorViewer); + /// Create a software Renderer + Renderer(Surface& surf) throw (ErrorViewer); ~Renderer() = default; /// If Renderer is current not ready, setRenderer will create Renderer. @@ -31,6 +34,8 @@ public: int createRenderer(Window& wnd,std::initializer_list); + int createSoftRenderer(Surface& surf); + int setColor(const RGBA& pack); RGBA getColor() const; int setBlendMode(BlendMode mode);