24 #define ERR_SDL LOG_STREAM(err, log_sdl)
29 const int default_texture_format = SDL_PIXELFORMAT_ARGB8888;
31 void cleanup_texture(SDL_Texture*
t)
34 SDL_DestroyTexture(
t);
41 : texture_(txt, &cleanup_texture)
44 SDL_QueryTexture(txt,
nullptr,
nullptr, &
w_, &
h_);
66 const char*
scale_quality = linear_interpolation ?
"linear" :
"nearest";
71 ERR_SDL <<
"When creating texture from surface: " << SDL_GetError();
82 reset(width, height, access);
94 SDL_QueryTexture(
texture_.get(), &ret,
nullptr,
nullptr,
nullptr);
96 ret = SDL_PIXELFORMAT_UNKNOWN;
105 SDL_QueryTexture(
texture_.get(),
nullptr, &ret,
nullptr,
nullptr);
116 SDL_QueryTexture(
texture_.get(),
nullptr,
nullptr, &ret.x, &ret.y);
136 src_.x = (dsrc.x * rsize.x) /
w_;
137 src_.y = (dsrc.y * rsize.y) /
h_;
138 src_.w = (dsrc.w * rsize.x) /
w_;
139 src_.h = (dsrc.h * rsize.y) /
h_;
154 SDL_SetTextureAlphaMod(
texture_.get(), alpha);
164 SDL_GetTextureAlphaMod(
texture_.get(), &a);
171 SDL_SetTextureColorMod(
texture_.get(),
c.r,
c.g,
c.b);
177 SDL_SetTextureColorMod(
texture_.get(), r,
g,
b);
187 SDL_GetTextureColorMod(
texture_.get(), &
c.r, &
c.g, &
c.b);
194 SDL_SetTextureBlendMode(
texture_.get(),
b);
201 return SDL_BLENDMODE_NONE;
204 SDL_GetTextureBlendMode(
texture_.get(), &
b);
227 texture_.reset(SDL_CreateTexture(
renderer, default_texture_format, access, width, height), &cleanup_texture);
229 ERR_SDL <<
"When creating texture: " << SDL_GetError();
233 w_ = width;
h_ = height;
243 SDL_QueryTexture(
t,
nullptr,
nullptr, &
w_, &
h_);
252 :
format(SDL_PIXELFORMAT_UNKNOWN)
Wrapper class to encapsulate creation and management of an SDL_Texture.
uint8_t get_alpha_mod() const
rect src_
uninitialized by default.
SDL_BlendMode get_blend_mode() const
int get_access() const
The texture access mode.
uint32_t get_format() const
The internal texture format.
std::shared_ptr< SDL_Texture > texture_
void set_blend_mode(SDL_BlendMode)
Blend mode.
bool has_src_
true iff the source rect is valid
void reset()
Releases ownership of the managed texture and resets the ptr to null.
void set_src(const rect &r)
Set the source region of the texture used for drawing operations.
texture()=default
Default ctor.
point draw_size() const
The size of the texture in draw-space.
void set_draw_size(int w, int h)
Set the intended size of the texture, in draw-space.
point get_raw_size() const
The raw internal texture size.
void assign(SDL_Texture *t)
Replaces ownership of the managed texture with the given one.
void set_alpha_mod(uint8_t alpha)
Alpha modifier.
color_t get_color_mod() const
void set_src_raw(const rect &r)
Set the source region of the texture used for drawing operations.
void set_color_mod(uint8_t r, uint8_t g, uint8_t b)
Colour modifier.
static SDL_Renderer * renderer()
Standard logging facilities (interface).
SDL_Renderer * get_renderer()
The basic class for representing 8-bit RGB or RGBA colour values.
An abstract description of a rectangle with integer coordinates.
rect intersect(const SDL_Rect &r) const
Calculates the intersection of this rectangle and another; that is, the maximal rectangle that is con...
static lg::log_domain log_sdl("SDL")