diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-18 10:53:01 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-18 10:53:01 +0300 |
commit | ef297dafa84154d8f28f014410ab742f7994c557 (patch) | |
tree | ae092c965eb93ec855f6f833606d6904cefa263e /src/ui/paint.c | |
parent | 6a550da2b01921e66f49badff11ac6ab9b88cd21 (diff) |
Render target switching
Diffstat (limited to 'src/ui/paint.c')
-rw-r--r-- | src/ui/paint.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/ui/paint.c b/src/ui/paint.c index 85e75f15..a55670e9 100644 --- a/src/ui/paint.c +++ b/src/ui/paint.c | |||
@@ -1,5 +1,7 @@ | |||
1 | #include "paint.h" | 1 | #include "paint.h" |
2 | 2 | ||
3 | #include <SDL_version.h> | ||
4 | |||
3 | iLocalDef SDL_Renderer *renderer_Paint_(const iPaint *d) { | 5 | iLocalDef SDL_Renderer *renderer_Paint_(const iPaint *d) { |
4 | iAssert(d->dst); | 6 | iAssert(d->dst); |
5 | return d->dst->render; | 7 | return d->dst->render; |
@@ -12,6 +14,18 @@ static void setColor_Paint_(const iPaint *d, int color) { | |||
12 | 14 | ||
13 | void init_Paint(iPaint *d) { | 15 | void init_Paint(iPaint *d) { |
14 | d->dst = get_Window(); | 16 | d->dst = get_Window(); |
17 | d->oldTarget = NULL; | ||
18 | } | ||
19 | |||
20 | void beginTarget_Paint(iPaint *d, SDL_Texture *target) { | ||
21 | SDL_Renderer *rend = renderer_Paint_(d); | ||
22 | d->oldTarget = SDL_GetRenderTarget(rend); | ||
23 | SDL_SetRenderTarget(rend, target); | ||
24 | } | ||
25 | |||
26 | void endTarget_Paint(iPaint *d) { | ||
27 | SDL_SetRenderTarget(renderer_Paint_(d), d->oldTarget); | ||
28 | d->oldTarget = NULL; | ||
15 | } | 29 | } |
16 | 30 | ||
17 | void setClip_Paint(iPaint *d, iRect rect) { | 31 | void setClip_Paint(iPaint *d, iRect rect) { |
@@ -19,8 +33,12 @@ void setClip_Paint(iPaint *d, iRect rect) { | |||
19 | } | 33 | } |
20 | 34 | ||
21 | void unsetClip_Paint(iPaint *d) { | 35 | void unsetClip_Paint(iPaint *d) { |
36 | #if SDL_VERSION_ATLEAST(2, 0, 12) | ||
37 | SDL_RenderSetClipRect(renderer_Paint_(d), NULL); | ||
38 | #else | ||
22 | const SDL_Rect winRect = { 0, 0, d->dst->root->rect.size.x, d->dst->root->rect.size.y }; | 39 | const SDL_Rect winRect = { 0, 0, d->dst->root->rect.size.x, d->dst->root->rect.size.y }; |
23 | SDL_RenderSetClipRect(renderer_Paint_(d), &winRect); | 40 | SDL_RenderSetClipRect(renderer_Paint_(d), &winRect); |
41 | #endif | ||
24 | } | 42 | } |
25 | 43 | ||
26 | void drawRect_Paint(const iPaint *d, iRect rect, int color) { | 44 | void drawRect_Paint(const iPaint *d, iRect rect, int color) { |