From 8824963c806ce80ed919feeb8cae41dbf3116e50 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sat, 12 Sep 2020 23:14:58 +0300 Subject: Paint: Keeping track of the set render target --- src/ui/paint.c | 18 ++++++++++++++---- src/ui/paint.h | 3 ++- 2 files changed, 16 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/ui/paint.c b/src/ui/paint.c index 0166e398..d0a4a579 100644 --- a/src/ui/paint.c +++ b/src/ui/paint.c @@ -36,18 +36,28 @@ static void setColor_Paint_(const iPaint *d, int color) { void init_Paint(iPaint *d) { d->dst = get_Window(); + d->setTarget = NULL; d->oldTarget = NULL; } void beginTarget_Paint(iPaint *d, SDL_Texture *target) { SDL_Renderer *rend = renderer_Paint_(d); - d->oldTarget = SDL_GetRenderTarget(rend); - SDL_SetRenderTarget(rend, target); + if (!d->setTarget) { + d->oldTarget = SDL_GetRenderTarget(rend); + SDL_SetRenderTarget(rend, target); + d->setTarget = target; + } + else { + iAssert(d->setTarget == target); + } } void endTarget_Paint(iPaint *d) { - SDL_SetRenderTarget(renderer_Paint_(d), d->oldTarget); - d->oldTarget = NULL; + if (d->setTarget) { + SDL_SetRenderTarget(renderer_Paint_(d), d->oldTarget); + d->oldTarget = NULL; + d->setTarget = NULL; + } } void setClip_Paint(iPaint *d, iRect rect) { diff --git a/src/ui/paint.h b/src/ui/paint.h index 7c9e5e51..28931815 100644 --- a/src/ui/paint.h +++ b/src/ui/paint.h @@ -30,7 +30,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ iDeclareType(Paint) struct Impl_Paint { - iWindow *dst; + iWindow * dst; + SDL_Texture *setTarget; SDL_Texture *oldTarget; }; -- cgit v1.2.3