mirror of
https://github.com/Kiritow/MiniEngine.git
synced 2024-03-22 13:11:22 +08:00
Enable software Renderer creating in class Renderer
This commit is contained in:
parent
ad34163fbf
commit
2d0b1b77a8
|
@ -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<RendererType> RendererFlags) throw (ErrorViewer)
|
||||
{
|
||||
if(createRenderer(wnd,RendererFlags)!=0)
|
||||
|
@ -28,6 +62,14 @@ Renderer::Renderer(Window& wnd,std::initializer_list<RendererType> RendererFlags
|
|||
}
|
||||
}
|
||||
|
||||
Renderer::Renderer(Surface& surf) throw (ErrorViewer)
|
||||
{
|
||||
if(createSoftRenderer(surf)!=0)
|
||||
{
|
||||
throw ErrorViewer();
|
||||
}
|
||||
}
|
||||
|
||||
int Renderer::createRenderer(Window& wnd,std::initializer_list<RendererType> RendererFlags)
|
||||
{
|
||||
Uint32 flag = 0;
|
||||
|
@ -38,6 +80,20 @@ int Renderer::createRenderer(Window& wnd,std::initializer_list<RendererType> 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"
|
||||
|
|
|
@ -11,7 +11,10 @@ class Renderer
|
|||
{
|
||||
public:
|
||||
Renderer() = default;
|
||||
/// Create a Renderer associated with Window
|
||||
Renderer(Window& wnd,std::initializer_list<RendererType> 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<RendererType>);
|
||||
|
||||
int createSoftRenderer(Surface& surf);
|
||||
|
||||
int setColor(const RGBA& pack);
|
||||
RGBA getColor() const;
|
||||
int setBlendMode(BlendMode mode);
|
||||
|
|
Loading…
Reference in New Issue
Block a user