From 46085084763d5d85c259e5deb67c9e8ab818e595 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Wed, 7 Jun 2017 19:52:37 +0800 Subject: [PATCH] class Renderer supports getting rendering target now. --- MiniEngine.cpp | 14 ++++++++++++++ MiniEngine.h | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/MiniEngine.cpp b/MiniEngine.cpp index 5fb648f..d3d4263 100644 --- a/MiniEngine.cpp +++ b/MiniEngine.cpp @@ -779,6 +779,13 @@ namespace MiniEngine updateInfo(); } + //private + void Texture::_set_no_delete(SDL_Texture* p) + { + _text.reset(p,[](SDL_Texture*){}); + updateInfo(); + } + //private void Texture::_clear() { @@ -940,6 +947,13 @@ namespace MiniEngine return SDL_SetRenderTarget(_get(), nullptr); } + Texture Renderer::getTarget() + { + Texture t; + t._set_no_delete(SDL_GetRenderTarget(_get())); + return t; + } + int Renderer::fillRect(const Rect& rect) { auto inr = rect.toSDLRect(); diff --git a/MiniEngine.h b/MiniEngine.h index 62c0cfb..a0c50e1 100644 --- a/MiniEngine.h +++ b/MiniEngine.h @@ -15,7 +15,7 @@ namespace MiniEngine public: int x, y, w, h; Rect(int X, int Y, int W, int H); - Rect(const SDL_Rect&); + explicit Rect(const SDL_Rect&); Rect(); SDL_Rect toSDLRect() const; bool isEmpty(); @@ -199,6 +199,8 @@ namespace MiniEngine private: std::shared_ptr _text; void _set(SDL_Texture*); + /// Just used for "SDL_GetRenderTarget" + void _set_no_delete(SDL_Texture*); void _clear(); SDL_Texture* _get() const; Rect rect; @@ -220,6 +222,7 @@ namespace MiniEngine int setTarget(Texture& t); int setTarget(); + Texture getTarget(); int fillRect(const Rect& rect); int drawRect(const Rect& rect);