Files
hdk-sdl/include/hdk/sdl/render/Texture.hpp
T
2026-05-11 10:28:21 +00:00

81 lines
4.4 KiB
C++

#pragma once
/// @file Texture.hpp
/// For complete documentation, see src/render/Texture.cpp
#include <SDL3/SDL.h>
#include <hdk/grid/SharedPtrWrapper.hpp>
#include <hdk/sdl/Properties.hpp>
#include <hdk/sdl/pixels/Palette.hpp>
namespace hdk::sdl {
/// Forward declare to avoid circular dependency with Renderer
class Renderer;
/** */
class Texture : public hdk::grid::SharedPtrWrapper<SDL_Texture> {
public:
friend class Renderer;
using hdk::grid::SharedPtrWrapper<SDL_Texture>::SharedPtrWrapper;
static Texture Create(SDL_Renderer* renderer, SDL_PixelFormat format, SDL_TextureAccess access, int w, int h) {
return Texture(get_or_cache(SDL_CreateTexture(renderer, format, access, w, h), SDL_DestroyTexture));
}
static Texture CreateFromSurface(SDL_Renderer* renderer, SDL_Surface* surface) {
return Texture(get_or_cache(SDL_CreateTextureFromSurface(renderer, surface), SDL_DestroyTexture));
}
static Texture CreateWithProperties(SDL_Renderer* renderer, SDL_PropertiesID properties) {
return Texture(get_or_cache(SDL_CreateTextureWithProperties(renderer, properties), SDL_DestroyTexture));
}
bool GetAlphaMod(Uint8* alpha) const { return SDL_GetTextureAlphaMod(*this, alpha); }
Uint8 GetAlphaMod() const {
Uint8 alpha;
SDL_GetTextureAlphaMod(*this, &alpha);
return alpha;
}
bool GetAlphaModFloat(float* alpha) const { return SDL_GetTextureAlphaModFloat(*this, alpha); }
float GetAlphaModFloat() const {
float alpha;
SDL_GetTextureAlphaModFloat(*this, &alpha);
return alpha;
}
bool GetBlendMode(SDL_BlendMode* blendMode) const { return SDL_GetTextureBlendMode(*this, blendMode); }
SDL_BlendMode GetBlendMode() const {
SDL_BlendMode blendMode;
SDL_GetTextureBlendMode(*this, &blendMode);
return blendMode;
}
bool GetColorMod(Uint8* r, Uint8* g, Uint8* b) const { return SDL_GetTextureColorMod(*this, r, g, b); }
bool GetColorModFloat(float* r, float* g, float* b) const { return SDL_GetTextureColorModFloat(*this, r, g, b); }
Palette GetPalette() const { return Palette(Palette::get_or_cache(SDL_GetTexturePalette(*this), SDL_DestroyPalette)); }
Properties GetProperties() const { return Properties(SDL_GetTextureProperties(*this)); }
/// Implemented in `../render.hpp` to avoid circular dependency with Renderer
Renderer GetRenderer() const;
bool GetScaleMode(SDL_ScaleMode* scaleMode) const { return SDL_GetTextureScaleMode(*this, scaleMode); }
SDL_ScaleMode GetScaleMode() const {
SDL_ScaleMode scaleMode;
SDL_GetTextureScaleMode(*this, &scaleMode);
return scaleMode;
}
bool GetSize(float* w, float* h) const { return SDL_GetTextureSize(*this, w, h); }
bool Lock(const SDL_Rect* rect, void** pixels, int* pitch) const {
return SDL_LockTexture(*this, rect, pixels, pitch);
}
bool LockToSurface(const SDL_Rect* rect, SDL_Surface** surface) const {
return SDL_LockTextureToSurface(*this, rect, surface);
}
bool SetAlphaMod(Uint8 alpha) const { return SDL_SetTextureAlphaMod(*this, alpha); }
bool SetAlphaModFloat(float alpha) const { return SDL_SetTextureAlphaModFloat(*this, alpha); }
bool SetBlendMode(SDL_BlendMode blendMode) const { return SDL_SetTextureBlendMode(*this, blendMode); }
bool SetColorMod(Uint8 r, Uint8 g, Uint8 b) const { return SDL_SetTextureColorMod(*this, r, g, b); }
bool SetColorModFloat(float r, float g, float b) const { return SDL_SetTextureColorModFloat(*this, r, g, b); }
bool SetPalette(SDL_Palette* palette) const { return SDL_SetTexturePalette(*this, palette); }
bool SetScaleMode(SDL_ScaleMode scaleMode) const { return SDL_SetTextureScaleMode(*this, scaleMode); }
void Unlock() const { SDL_UnlockTexture(*this); }
bool UpdateNV(const SDL_Rect* rect, const Uint8* Yplane, int Ypitch, const Uint8* UVplane, int UVpitch) const {
return SDL_UpdateNVTexture(*this, rect, Yplane, Ypitch, UVplane, UVpitch);
}
bool Update(const SDL_Rect* rect, const void* pixels, int pitch) const {
return SDL_UpdateTexture(*this, rect, pixels, pitch);
}
bool UpdateYUV(const SDL_Rect* rect, const Uint8* Yplane, int Ypitch, const Uint8* Uplane, int Upitch, const Uint8* Vplane, int Vpitch) const {
return SDL_UpdateYUVTexture(*this, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
}
};
}