mirror of
https://github.com/Kiritow/MiniEngine.git
synced 2024-03-22 13:11:22 +08:00
Move Renderer settings out of class Window
This commit is contained in:
parent
a96b48b0c0
commit
112c1081aa
|
@ -1467,7 +1467,6 @@ namespace MiniEngine
|
||||||
}
|
}
|
||||||
|
|
||||||
Window::Window(std::string Title, int Width, int Height,
|
Window::Window(std::string Title, int Width, int Height,
|
||||||
std::initializer_list<RendererType> RendererFlags,
|
|
||||||
std::initializer_list<WindowType> WindowFlags , int WindowPositionX, int WindowPositionY) throw(ErrorViewer)
|
std::initializer_list<WindowType> WindowFlags , int WindowPositionX, int WindowPositionY) throw(ErrorViewer)
|
||||||
{
|
{
|
||||||
/// Calculate Window Flags
|
/// Calculate Window Flags
|
||||||
|
@ -1484,23 +1483,26 @@ namespace MiniEngine
|
||||||
e.fetch();
|
e.fetch();
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
_set(temp);
|
_set(temp);
|
||||||
setRenderer(RendererFlags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer Window::getRenderer() const
|
Renderer::Renderer(Window& wnd,std::initializer_list<RendererType> RendererFlags) throw (ErrorViewer)
|
||||||
{
|
{
|
||||||
return _winrnd;
|
if(createRenderer(wnd,RendererFlags)!=0)
|
||||||
|
{
|
||||||
|
throw ErrorViewer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setRenderer(std::initializer_list<RendererType> RendererFlags)
|
int Renderer::createRenderer(Window& wnd,std::initializer_list<RendererType> RendererFlags)
|
||||||
{
|
{
|
||||||
Uint32 flag = 0;
|
Uint32 flag = 0;
|
||||||
for (auto v : RendererFlags)
|
for (auto v : RendererFlags)
|
||||||
{
|
{
|
||||||
flag |= _render_caster(v);
|
flag |= _rendertype_caster(v);
|
||||||
}
|
}
|
||||||
_setRenderer_Real(flag);
|
return _createRenderer_Real(wnd,flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect Window::getSize() const
|
Rect Window::getSize() const
|
||||||
|
@ -1621,7 +1623,7 @@ namespace MiniEngine
|
||||||
}
|
}
|
||||||
|
|
||||||
// private
|
// private
|
||||||
Uint32 Window::_render_caster(RendererType Type)
|
Uint32 Renderer::_rendertype_caster(RendererType Type)
|
||||||
{
|
{
|
||||||
switch(Type)
|
switch(Type)
|
||||||
{
|
{
|
||||||
|
@ -1640,9 +1642,18 @@ namespace MiniEngine
|
||||||
}
|
}
|
||||||
|
|
||||||
// private
|
// private
|
||||||
void Window::_setRenderer_Real(Uint32 flags)
|
int Renderer::_createRenderer_Real(Window& wnd,Uint32 flags)
|
||||||
{
|
{
|
||||||
_winrnd._rnd.reset(SDL_CreateRenderer(_get(), -1, flags), SDL_DestroyRenderer);
|
SDL_Renderer* pSDLRnd=SDL_CreateRenderer(wnd._get(), -1, flags);
|
||||||
|
if(pSDLRnd!=nullptr)
|
||||||
|
{
|
||||||
|
_set(pSDLRnd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Window::showSimpleMessageBox(MessageBoxType type,const std::string& Title,const std::string& Message) const
|
int Window::showSimpleMessageBox(MessageBoxType type,const std::string& Title,const std::string& Message) const
|
||||||
|
@ -1736,24 +1747,6 @@ namespace MiniEngine
|
||||||
return SDL_IsScreenKeyboardShown(_get())==SDL_TRUE;
|
return SDL_IsScreenKeyboardShown(_get())==SDL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Experimental
|
|
||||||
void Window::resetRenderer()
|
|
||||||
{
|
|
||||||
/// Check if there is a renderer exists.
|
|
||||||
if(SDL_GetRenderer(_get())!=nullptr)
|
|
||||||
{
|
|
||||||
/// Clear internal Renderer class.
|
|
||||||
_winrnd._clear();
|
|
||||||
/// Check again.
|
|
||||||
if(SDL_GetRenderer(_get())!=nullptr)
|
|
||||||
{
|
|
||||||
/// If it still exists, (May be some other Renderer is holding)
|
|
||||||
/// then destroy it.
|
|
||||||
SDL_DestroyRenderer(SDL_GetRenderer(_get()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Font::_set(TTF_Font* p)
|
void Font::_set(TTF_Font* p)
|
||||||
{
|
{
|
||||||
_font.reset(p,TTF_CloseFont);
|
_font.reset(p,TTF_CloseFont);
|
||||||
|
|
271
MiniEngine.h
271
MiniEngine.h
|
@ -207,103 +207,6 @@ namespace MiniEngine
|
||||||
friend class Renderer;
|
friend class Renderer;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class RendererType { Software, Accelerated, PresentSync, TargetTexture };
|
|
||||||
|
|
||||||
enum class FlipMode { None, Horizontal, Vertical };
|
|
||||||
|
|
||||||
class Renderer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Renderer() = default;
|
|
||||||
int setColor(const RGBA& pack);
|
|
||||||
RGBA getColor() const;
|
|
||||||
int setBlendMode(BlendMode mode);
|
|
||||||
BlendMode getBlendMode() const;
|
|
||||||
|
|
||||||
int setTarget(Texture& t);
|
|
||||||
int setTarget();
|
|
||||||
Texture getTarget();
|
|
||||||
|
|
||||||
int fillRect(const Rect& rect);
|
|
||||||
int drawRect(const Rect& rect);
|
|
||||||
int drawPoint(const Point& p);
|
|
||||||
int drawLine(const Point& A,const Point& B);
|
|
||||||
|
|
||||||
/// Experimental
|
|
||||||
int fillRects(const SDL_Rect* pRectArray,int n);
|
|
||||||
int drawRects(const SDL_Rect* pRectArray,int n);
|
|
||||||
int drawPoints(const SDL_Point* pPointArray,int n);
|
|
||||||
int drawLines(const SDL_Point* pPointArray,int n);
|
|
||||||
/// Experimental
|
|
||||||
int fillRects(const std::vector<SDL_Rect>& rectvec);
|
|
||||||
int drawRects(const std::vector<SDL_Rect>& rectvec);
|
|
||||||
int drawPoints(const std::vector<SDL_Point>& pointvec);
|
|
||||||
int drawLines(const std::vector<SDL_Point>& pointvec);
|
|
||||||
|
|
||||||
int setScale(float scaleX,float scaleY);
|
|
||||||
std::tuple<float,float> getScale() const;
|
|
||||||
|
|
||||||
int setViewport(const Rect& viewport);
|
|
||||||
Rect getViewport() const;
|
|
||||||
|
|
||||||
int setLogicalSize(int w,int h);
|
|
||||||
Rect getLogicalSize() const;
|
|
||||||
|
|
||||||
int setClipRect(const Rect& cliprect);
|
|
||||||
Rect getClipRect() const;
|
|
||||||
bool isClipEnabled() const;
|
|
||||||
|
|
||||||
Rect getOutputSize() const;
|
|
||||||
|
|
||||||
int clear();
|
|
||||||
void update();
|
|
||||||
|
|
||||||
int copy(const Texture& t, const Rect& src, const Rect& dst);
|
|
||||||
int copyTo(const Texture& t, const Rect& dst);
|
|
||||||
int copyTo(const Texture& t, const Point& lupoint);
|
|
||||||
int copyFill(const Texture& t, const Rect& src);
|
|
||||||
int copyFullFill(const Texture& t);
|
|
||||||
|
|
||||||
/// Super copy without center point.
|
|
||||||
int copy(const Texture& t, const Rect& src, const Rect& dst,double angle,FlipMode mode);
|
|
||||||
int copyTo(const Texture& t, const Rect& dst,double angle,FlipMode mode);
|
|
||||||
int copyTo(const Texture& t, const Point& lupoint,double angle,FlipMode mode);
|
|
||||||
int copyFill(const Texture& t, const Rect& src,double angle,FlipMode mode);
|
|
||||||
int copyFullFill(const Texture& t,double angle,FlipMode mode);
|
|
||||||
/// Super copy with center point
|
|
||||||
int copy(const Texture& t, const Rect& src, const Rect& dst,const Point& centerPoint,double angle,FlipMode mode);
|
|
||||||
int copyTo(const Texture& t, const Rect& dst,const Point& centerPoint,double angle,FlipMode mode);
|
|
||||||
int copyTo(const Texture& t, const Point& lupoint,const Point& centerPoint,double angle,FlipMode mode);
|
|
||||||
int copyFill(const Texture& t, const Rect& src,const Point& centerPoint,double angle,FlipMode mode);
|
|
||||||
int copyFullFill(const Texture& t,const Point& centerPoint,double angle,FlipMode mode);
|
|
||||||
|
|
||||||
/// Reserved for compatibility
|
|
||||||
int supercopy(const Texture& t,
|
|
||||||
bool srcfull,const Rect& src,bool dstfull,const Rect& dst,
|
|
||||||
double angle,
|
|
||||||
bool haspoint,const Point& center,FlipMode mode);
|
|
||||||
|
|
||||||
Texture render(const Surface& surf) const throw (ErrorViewer);
|
|
||||||
Texture loadTexture(const std::string& FileName) const throw(ErrorViewer);
|
|
||||||
Texture loadTextureRW(const RWOP& rwop) const throw(ErrorViewer);
|
|
||||||
Texture createTexture(int Width, int Height) const throw(ErrorViewer);
|
|
||||||
|
|
||||||
bool isRenderTargetSupported() const;
|
|
||||||
bool isReady() const;
|
|
||||||
|
|
||||||
void release();
|
|
||||||
|
|
||||||
/// Experimental
|
|
||||||
static int GetDriversNum();
|
|
||||||
private:
|
|
||||||
std::shared_ptr<SDL_Renderer> _rnd;
|
|
||||||
void _set(SDL_Renderer*);
|
|
||||||
void _clear();
|
|
||||||
SDL_Renderer* _get() const;
|
|
||||||
|
|
||||||
friend class Window;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class SystemCursorType
|
enum class SystemCursorType
|
||||||
{
|
{
|
||||||
Arrow, Ibeam, CrossHair,
|
Arrow, Ibeam, CrossHair,
|
||||||
|
@ -391,25 +294,8 @@ namespace MiniEngine
|
||||||
public:
|
public:
|
||||||
Window()=default;
|
Window()=default;
|
||||||
Window(std::string Title, int Width, int Height,
|
Window(std::string Title, int Width, int Height,
|
||||||
std::initializer_list<RendererType> RendererFlags = { RendererType::Accelerated,RendererType::TargetTexture },
|
|
||||||
std::initializer_list<WindowType> WindowFlags = {WindowType::Shown} ,
|
std::initializer_list<WindowType> WindowFlags = {WindowType::Shown} ,
|
||||||
int WindowPositionX=SDL_WINDOWPOS_CENTERED, int WindowPositionY=SDL_WINDOWPOS_CENTERED) throw(ErrorViewer);
|
int WindowPositionX=SDL_WINDOWPOS_CENTERED, int WindowPositionY=SDL_WINDOWPOS_CENTERED) throw(ErrorViewer);
|
||||||
Renderer getRenderer() const;
|
|
||||||
|
|
||||||
void setRenderer(RendererType Type)
|
|
||||||
{
|
|
||||||
int flagcalc=0;
|
|
||||||
_setRenderer(flagcalc,Type);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename... Args>
|
|
||||||
void setRenderer(RendererType Type,Args&&... args)
|
|
||||||
{
|
|
||||||
int flagcalc=0;
|
|
||||||
_setRenderer(flagcalc,Type,std::forward<RendererType>(args...));
|
|
||||||
}
|
|
||||||
|
|
||||||
void setRenderer(std::initializer_list<RendererType>);
|
|
||||||
|
|
||||||
Rect getSize() const;
|
Rect getSize() const;
|
||||||
void setSize(const Rect& sizeRect);
|
void setSize(const Rect& sizeRect);
|
||||||
|
@ -451,34 +337,147 @@ namespace MiniEngine
|
||||||
bool isScreenKeyboardShown();
|
bool isScreenKeyboardShown();
|
||||||
|
|
||||||
void release();
|
void release();
|
||||||
|
|
||||||
/// Experimental : Free current renderer.
|
|
||||||
/// This will cause all existing Renderer class throw an error on delete.
|
|
||||||
/// This function destroy current renderer (if exist) and all Renderer class will not be notified.
|
|
||||||
void resetRenderer();
|
|
||||||
protected:
|
|
||||||
template<typename... Args>
|
|
||||||
void _setRenderer(int& refcalc,RendererType Type,Args&&... args)
|
|
||||||
{
|
|
||||||
refcalc|=_render_caster(Type);
|
|
||||||
_setRenderer(refcalc,args...);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _setRenderer(int& refcalc,RendererType Type)
|
|
||||||
{
|
|
||||||
refcalc|=_render_caster(Type);
|
|
||||||
_setRenderer_Real(refcalc);
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
void _setRenderer_Real(Uint32 flags);
|
|
||||||
Uint32 _render_caster(RendererType);
|
|
||||||
|
|
||||||
std::shared_ptr<SDL_Window> _wnd;
|
std::shared_ptr<SDL_Window> _wnd;
|
||||||
|
|
||||||
void _set(SDL_Window*);
|
void _set(SDL_Window*);
|
||||||
void _clear();
|
void _clear();
|
||||||
SDL_Window* _get() const;
|
SDL_Window* _get() const;
|
||||||
|
|
||||||
Renderer _winrnd;
|
friend class Renderer;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class RendererType { Software, Accelerated, PresentSync, TargetTexture };
|
||||||
|
|
||||||
|
enum class FlipMode { None, Horizontal, Vertical };
|
||||||
|
|
||||||
|
class Renderer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Renderer() = default;
|
||||||
|
Renderer(Window& wnd,std::initializer_list<RendererType> RendererFlags = { RendererType::Accelerated,RendererType::TargetTexture }) throw (ErrorViewer);
|
||||||
|
~Renderer() = default;
|
||||||
|
|
||||||
|
/// If Renderer is current not ready, setRenderer will create Renderer.
|
||||||
|
/// Otherwise, setRenderer will fail.
|
||||||
|
int createRenderer(Window& wnd,RendererType Type)
|
||||||
|
{
|
||||||
|
int flagcalc=0;
|
||||||
|
return _createRenderer(wnd,flagcalc,Type);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename... Args>
|
||||||
|
int createRenderer(Window& wnd,RendererType Type,Args&&... args)
|
||||||
|
{
|
||||||
|
int flagcalc=0;
|
||||||
|
return _createRenderer(wnd,flagcalc,Type,std::forward<RendererType>(args...));
|
||||||
|
}
|
||||||
|
|
||||||
|
int createRenderer(Window& wnd,std::initializer_list<RendererType>);
|
||||||
|
|
||||||
|
int setColor(const RGBA& pack);
|
||||||
|
RGBA getColor() const;
|
||||||
|
int setBlendMode(BlendMode mode);
|
||||||
|
BlendMode getBlendMode() const;
|
||||||
|
|
||||||
|
int setTarget(Texture& t);
|
||||||
|
int setTarget();
|
||||||
|
Texture getTarget();
|
||||||
|
|
||||||
|
int fillRect(const Rect& rect);
|
||||||
|
int drawRect(const Rect& rect);
|
||||||
|
int drawPoint(const Point& p);
|
||||||
|
int drawLine(const Point& A,const Point& B);
|
||||||
|
|
||||||
|
/// Experimental
|
||||||
|
int fillRects(const SDL_Rect* pRectArray,int n);
|
||||||
|
int drawRects(const SDL_Rect* pRectArray,int n);
|
||||||
|
int drawPoints(const SDL_Point* pPointArray,int n);
|
||||||
|
int drawLines(const SDL_Point* pPointArray,int n);
|
||||||
|
/// Experimental
|
||||||
|
int fillRects(const std::vector<SDL_Rect>& rectvec);
|
||||||
|
int drawRects(const std::vector<SDL_Rect>& rectvec);
|
||||||
|
int drawPoints(const std::vector<SDL_Point>& pointvec);
|
||||||
|
int drawLines(const std::vector<SDL_Point>& pointvec);
|
||||||
|
|
||||||
|
int setScale(float scaleX,float scaleY);
|
||||||
|
std::tuple<float,float> getScale() const;
|
||||||
|
|
||||||
|
int setViewport(const Rect& viewport);
|
||||||
|
Rect getViewport() const;
|
||||||
|
|
||||||
|
int setLogicalSize(int w,int h);
|
||||||
|
Rect getLogicalSize() const;
|
||||||
|
|
||||||
|
int setClipRect(const Rect& cliprect);
|
||||||
|
Rect getClipRect() const;
|
||||||
|
bool isClipEnabled() const;
|
||||||
|
|
||||||
|
Rect getOutputSize() const;
|
||||||
|
|
||||||
|
int clear();
|
||||||
|
void update();
|
||||||
|
|
||||||
|
int copy(const Texture& t, const Rect& src, const Rect& dst);
|
||||||
|
int copyTo(const Texture& t, const Rect& dst);
|
||||||
|
int copyTo(const Texture& t, const Point& lupoint);
|
||||||
|
int copyFill(const Texture& t, const Rect& src);
|
||||||
|
int copyFullFill(const Texture& t);
|
||||||
|
|
||||||
|
/// Super copy without center point.
|
||||||
|
int copy(const Texture& t, const Rect& src, const Rect& dst,double angle,FlipMode mode);
|
||||||
|
int copyTo(const Texture& t, const Rect& dst,double angle,FlipMode mode);
|
||||||
|
int copyTo(const Texture& t, const Point& lupoint,double angle,FlipMode mode);
|
||||||
|
int copyFill(const Texture& t, const Rect& src,double angle,FlipMode mode);
|
||||||
|
int copyFullFill(const Texture& t,double angle,FlipMode mode);
|
||||||
|
/// Super copy with center point
|
||||||
|
int copy(const Texture& t, const Rect& src, const Rect& dst,const Point& centerPoint,double angle,FlipMode mode);
|
||||||
|
int copyTo(const Texture& t, const Rect& dst,const Point& centerPoint,double angle,FlipMode mode);
|
||||||
|
int copyTo(const Texture& t, const Point& lupoint,const Point& centerPoint,double angle,FlipMode mode);
|
||||||
|
int copyFill(const Texture& t, const Rect& src,const Point& centerPoint,double angle,FlipMode mode);
|
||||||
|
int copyFullFill(const Texture& t,const Point& centerPoint,double angle,FlipMode mode);
|
||||||
|
|
||||||
|
/// Reserved for compatibility
|
||||||
|
int supercopy(const Texture& t,
|
||||||
|
bool srcfull,const Rect& src,bool dstfull,const Rect& dst,
|
||||||
|
double angle,
|
||||||
|
bool haspoint,const Point& center,FlipMode mode);
|
||||||
|
|
||||||
|
Texture render(const Surface& surf) const throw (ErrorViewer);
|
||||||
|
Texture loadTexture(const std::string& FileName) const throw(ErrorViewer);
|
||||||
|
Texture loadTextureRW(const RWOP& rwop) const throw(ErrorViewer);
|
||||||
|
Texture createTexture(int Width, int Height) const throw(ErrorViewer);
|
||||||
|
|
||||||
|
bool isRenderTargetSupported() const;
|
||||||
|
bool isReady() const;
|
||||||
|
|
||||||
|
void release();
|
||||||
|
|
||||||
|
/// Experimental
|
||||||
|
static int GetDriversNum();
|
||||||
|
protected:
|
||||||
|
template<typename... Args>
|
||||||
|
int _createRenderer(Window& wnd,int& refcalc,RendererType Type,Args&&... args)
|
||||||
|
{
|
||||||
|
refcalc|=_rendertype_caster(Type);
|
||||||
|
return _createRenderer(wnd,refcalc,args...);
|
||||||
|
}
|
||||||
|
|
||||||
|
// template<>
|
||||||
|
int _createRenderer(Window& wnd,int& refcalc,RendererType Type)
|
||||||
|
{
|
||||||
|
refcalc|=_rendertype_caster(Type);
|
||||||
|
return _createRenderer_Real(wnd,refcalc);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
std::shared_ptr<SDL_Renderer> _rnd;
|
||||||
|
|
||||||
|
int _createRenderer_Real(Window& wnd,Uint32 flags);
|
||||||
|
Uint32 _rendertype_caster(RendererType);
|
||||||
|
|
||||||
|
void _set(SDL_Renderer*);
|
||||||
|
void _clear();
|
||||||
|
SDL_Renderer* _get() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class FontStyle { Normal, Bold, Italic, UnderLine, StrikeThrough };
|
enum class FontStyle { Normal, Bold, Italic, UnderLine, StrikeThrough };
|
||||||
|
|
Loading…
Reference in New Issue
Block a user