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, &
size_.x, &
size_.y);
70 ERR_SDL <<
"When creating texture from surface: " << SDL_GetError();
81 reset(width, height, access);
112 (dsrc.x * rsize.x) /
size_.x,
113 (dsrc.y * rsize.y) /
size_.y,
114 (dsrc.w * rsize.x) /
size_.x,
115 (dsrc.h * rsize.y) /
size_.y
131 SDL_SetTextureAlphaMod(
texture_.get(), alpha);
141 SDL_GetTextureAlphaMod(
texture_.get(), &a);
153 SDL_SetTextureColorMod(
texture_.get(), r,
g,
b);
163 SDL_GetTextureColorMod(
texture_.get(), &
c.r, &
c.g, &
c.b);
170 SDL_SetTextureBlendMode(
texture_.get(),
b);
177 return SDL_BLENDMODE_NONE;
180 SDL_GetTextureBlendMode(
texture_.get(), &
b);
203 texture_.reset(SDL_CreateTexture(
renderer, default_texture_format, access, width, height), &cleanup_texture);
205 ERR_SDL <<
"When creating texture: " << SDL_GetError();
209 size_ = {width, height};
223 :
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 mode)
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.
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.
const info get_info() const
Queries metadata about the texture, such as its dimensions.
void set_color_mod(uint8_t r, uint8_t g, uint8_t b)
Colour modifier.
static SDL_Renderer * renderer()
Standard logging facilities (interface).
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
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")
void set_texture_scale_quality(const char *value)
Sets the texture scale quality.