24 #define ERR_SDL LOG_STREAM(err, log_sdl)
29 const SDL_PixelFormat default_texture_format = SDL_PIXELFORMAT_ARGB8888;
31 void cleanup_texture(SDL_Texture*
t)
34 SDL_DestroyTexture(
t);
41 : texture_(txt, &cleanup_texture)
44 SDL_PropertiesID props = SDL_GetTextureProperties(txt);
45 size_.x = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_WIDTH_NUMBER, 0);
46 size_.y = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_HEIGHT_NUMBER, 0);
69 ERR_SDL <<
"When creating texture from surface: " << SDL_GetError();
71 SDL_SetTextureScaleMode(
texture_.get(), linear_interpolation ? SDL_SCALEMODE_LINEAR : SDL_SCALEMODE_NEAREST);
81 reset(width, height, access);
92 SDL_PropertiesID props = SDL_GetTextureProperties(
texture_.get());
93 return SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_FORMAT_NUMBER, 0);
95 return SDL_PIXELFORMAT_UNKNOWN;
102 SDL_PropertiesID props = SDL_GetTextureProperties(
texture_.get());
103 return SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_ACCESS_NUMBER, 0);
112 SDL_PropertiesID props = SDL_GetTextureProperties(
texture_.get());
114 static_cast<int>(SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_WIDTH_NUMBER, 0)),
115 static_cast<int>(SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_HEIGHT_NUMBER, 0))
130 (dsrc.x * rsize.x) /
size_.x,
131 (dsrc.y * rsize.y) /
size_.y,
132 (dsrc.w * rsize.x) /
size_.x,
133 (dsrc.h * rsize.y) /
size_.y
149 SDL_SetTextureAlphaMod(
texture_.get(), alpha);
159 SDL_GetTextureAlphaMod(
texture_.get(), &a);
171 SDL_SetTextureColorMod(
texture_.get(), r,
g,
b);
181 SDL_GetTextureColorMod(
texture_.get(), &
c.r, &
c.g, &
c.b);
188 SDL_SetTextureBlendMode(
texture_.get(),
b);
195 return SDL_BLENDMODE_NONE;
198 SDL_GetTextureBlendMode(
texture_.get(), &
b);
221 texture_.reset(SDL_CreateTexture(
renderer, default_texture_format, access, width, height), &cleanup_texture);
223 ERR_SDL <<
"When creating texture: " << SDL_GetError();
227 size_ = {width, height};
241 :
format(SDL_PIXELFORMAT_UNKNOWN)
246 SDL_PropertiesID props = SDL_GetTextureProperties(
t);
247 format = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_FORMAT_NUMBER, 0);
248 access = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_ACCESS_NUMBER, 0);
249 size.x = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_WIDTH_NUMBER, 0);
250 size.y = SDL_GetNumberProperty(props, SDL_PROP_TEXTURE_HEIGHT_NUMBER, 0);
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.
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 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")