mirror of
https://github.com/wesnoth/wesnoth
synced 2025-04-16 09:07:41 +00:00
Allow draw::set_render_target to switch to the main render buffer.
This is done by passing it an empty texture.
This commit is contained in:
parent
0eada04f55
commit
08144affdf
16
src/draw.cpp
16
src/draw.cpp
|
@ -577,7 +577,7 @@ draw::render_target_setter::render_target_setter(const texture& t)
|
||||||
, viewport_()
|
, viewport_()
|
||||||
{
|
{
|
||||||
// Validate we can render to this texture.
|
// Validate we can render to this texture.
|
||||||
assert(t.get_access() == SDL_TEXTUREACCESS_TARGET);
|
assert(!t || t.get_access() == SDL_TEXTUREACCESS_TARGET);
|
||||||
|
|
||||||
if (!renderer()) {
|
if (!renderer()) {
|
||||||
WRN_D << "can't set render target with null renderer";
|
WRN_D << "can't set render target with null renderer";
|
||||||
|
@ -587,7 +587,11 @@ draw::render_target_setter::render_target_setter(const texture& t)
|
||||||
target_ = video::get_render_target();
|
target_ = video::get_render_target();
|
||||||
SDL_RenderGetViewport(renderer(), &viewport_);
|
SDL_RenderGetViewport(renderer(), &viewport_);
|
||||||
|
|
||||||
video::force_render_target(t);
|
if (t) {
|
||||||
|
video::force_render_target(t);
|
||||||
|
} else {
|
||||||
|
video::reset_render_target();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
draw::render_target_setter::~render_target_setter()
|
draw::render_target_setter::~render_target_setter()
|
||||||
|
@ -602,7 +606,11 @@ draw::render_target_setter::~render_target_setter()
|
||||||
|
|
||||||
draw::render_target_setter draw::set_render_target(const texture& t)
|
draw::render_target_setter draw::set_render_target(const texture& t)
|
||||||
{
|
{
|
||||||
DBG_D << "setting render target to "
|
if (t) {
|
||||||
<< t.w() << 'x' << t.h() << " texture";
|
DBG_D << "setting render target to "
|
||||||
|
<< t.w() << 'x' << t.h() << " texture";
|
||||||
|
} else {
|
||||||
|
DBG_D << "setting render target to main render buffer";
|
||||||
|
}
|
||||||
return draw::render_target_setter(t);
|
return draw::render_target_setter(t);
|
||||||
}
|
}
|
||||||
|
|
|
@ -446,7 +446,9 @@ private:
|
||||||
* SDL_TEXTUREACCESS_TARGET access mode.
|
* SDL_TEXTUREACCESS_TARGET access mode.
|
||||||
*
|
*
|
||||||
* @param t The new render target. This must be a texture created
|
* @param t The new render target. This must be a texture created
|
||||||
* with SDL_TEXTUREACCESS_TARGET.
|
* with SDL_TEXTUREACCESS_TARGET, or an empty texture.
|
||||||
|
* If empty, it will set the render target to Wesnoth's
|
||||||
|
* primary render buffer.
|
||||||
* @returns A render_target_setter object. When this object is
|
* @returns A render_target_setter object. When this object is
|
||||||
* destroyed the render target will be restored to
|
* destroyed the render target will be restored to
|
||||||
* whatever it was before this call.
|
* whatever it was before this call.
|
||||||
|
|
|
@ -522,6 +522,11 @@ void clear_render_target()
|
||||||
force_render_target({});
|
force_render_target({});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void reset_render_target()
|
||||||
|
{
|
||||||
|
force_render_target(render_texture_);
|
||||||
|
}
|
||||||
|
|
||||||
texture get_render_target()
|
texture get_render_target()
|
||||||
{
|
{
|
||||||
// This should always be up-to-date, but assert for sanity.
|
// This should always be up-to-date, but assert for sanity.
|
||||||
|
@ -564,7 +569,7 @@ void render_screen()
|
||||||
SDL_RenderPresent(*window);
|
SDL_RenderPresent(*window);
|
||||||
|
|
||||||
// Reset the render target to the render texture.
|
// Reset the render target to the render texture.
|
||||||
force_render_target(render_texture_);
|
reset_render_target();
|
||||||
}
|
}
|
||||||
|
|
||||||
surface read_pixels(SDL_Rect* r)
|
surface read_pixels(SDL_Rect* r)
|
||||||
|
|
|
@ -290,6 +290,9 @@ void force_render_target(const texture& t);
|
||||||
/** Reset the render target to the main window / screen. */
|
/** Reset the render target to the main window / screen. */
|
||||||
void clear_render_target();
|
void clear_render_target();
|
||||||
|
|
||||||
|
/** Reset the render target to the primary render buffer. */
|
||||||
|
void reset_render_target();
|
||||||
|
|
||||||
/** Get the current render target.
|
/** Get the current render target.
|
||||||
*
|
*
|
||||||
* Will return an empty texture if the render target is the underlying
|
* Will return an empty texture if the render target is the underlying
|
||||||
|
|
Loading…
Reference in New Issue
Block a user