Skip to content

Commit

Permalink
Allow render_target_setter to restore the last target when destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Aug 12, 2017
1 parent 1402bb8 commit c0bea34
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/sdl/render_utils.hpp
Expand Up @@ -24,31 +24,33 @@

/**
* Sets the renderer output target to the specified texture.
* @todo: add support for restoring last target.
*/
class render_target_setter
{
public:
explicit render_target_setter(texture& t)
: renderer_(CVideo::get_singleton().get_renderer())
, last_target_(nullptr)
{
if(renderer_) {
// Validate we can render to this texture.
assert(t.get_info().access == SDL_TEXTUREACCESS_TARGET);

last_target_ = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, t);
}
}

~render_target_setter()
{
if(renderer_) {
SDL_SetRenderTarget(renderer_, nullptr);
SDL_SetRenderTarget(renderer_, last_target_);
}
}

private:
SDL_Renderer* renderer_;
SDL_Texture* last_target_; // TODO: use the texture wrapper?
};

using sdl_rect_getter = void (*)(SDL_Renderer*, SDL_Rect*);
Expand Down

0 comments on commit c0bea34

Please sign in to comment.