SDL_gpu implementation for ttext::render_as_texture.

This commit is contained in:
Boldizsár Lipka 2014-07-03 21:37:00 +02:00
parent 6db593c623
commit dde5c00d08
2 changed files with 34 additions and 0 deletions

View File

@ -94,6 +94,9 @@ ttext::ttext() :
layout_(pango_layout_new(context_)),
rect_(),
surface_(),
#ifdef SDL_GPU
texture_(),
#endif
text_(),
markedup_text_(false),
font_size_(14),
@ -165,6 +168,14 @@ sdl::ttexture ttext::render_as_texture() const
rerender();
return texture_;
}
#else
#ifdef SDL_GPU
sdl::ttexture ttext::render_as_texture() const
{
rerender();
return texture_;
}
#endif
#endif
int ttext::get_width() const
@ -699,6 +710,10 @@ void ttext::rerender(const bool force) const
#if SDL_VERSION_ATLEAST(2,0,0)
texture_ = CVideo::get_window()->create_texture
(SDL_TEXTUREACCESS_STATIC, surface_);
#else
#ifdef SDL_GPU
texture_ = sdl::ttexture(surface_);
#endif
#endif
cairo_destroy(cr);
cairo_surface_destroy(cairo_surface);

View File

@ -29,6 +29,11 @@
#include "sdl/texture.hpp"
#endif
#ifdef SDL_GPU
#include "sdl/gpu.hpp"
#include "sdl/texture.hpp"
#endif
struct language_def;
namespace gui2 {
@ -84,6 +89,16 @@ public:
* redraws the texture before returning it.
*/
sdl::ttexture render_as_texture() const;
#else
#ifdef SDL_GPU
/**
* Returns the rendered text as a texture.
*
* Before rendering it tests whether a redraw is needed and if so it first
* redraws the texture before returning it.
*/
sdl::ttexture render_as_texture() const;
#endif
#endif
/** Returns the width needed for the text. */
@ -225,6 +240,10 @@ private:
#if SDL_VERSION_ATLEAST(2,0,0)
/** The texture to render upon used as a cache. */
mutable sdl::ttexture texture_;
#else
#ifdef SDL_GPU
mutable sdl::ttexture texture_;
#endif
#endif
/** The text to draw (stored as UTF-8). */