SDL3pp
A slim C++ wrapper for SDL3
|
An efficient driver-specific representation of pixel data. More...
Public Member Functions | |
constexpr | Texture ()=default |
Default ctor. | |
constexpr | Texture (const TextureRaw resource) |
Constructs from TextureParam. More... | |
constexpr | Texture (const Texture &other) |
Copy constructor. | |
constexpr | Texture (Texture &&other) |
Move constructor. | |
Texture (RendererParam renderer, PixelFormat format, TextureAccess access, const PointRaw &size) | |
Create a texture for a rendering context. More... | |
Texture (RendererParam renderer, SurfaceParam surface) | |
Create a texture from an existing surface. More... | |
Texture (RendererParam renderer, PropertiesParam props) | |
Create a texture for a rendering context with the specified properties. More... | |
Texture (RendererParam renderer, StringParam file) | |
Load an image from a filesystem path into a GPU texture. More... | |
Texture (RendererParam renderer, IOStreamParam src, bool closeio=false) | |
Load an image from an SDL data source into a GPU texture. More... | |
~Texture () | |
Destructor. | |
Texture & | operator= (Texture other) |
Assignment operator. | |
constexpr TextureRaw | get () const |
Retrieves underlying TextureRaw. | |
constexpr TextureRaw | release () |
Retrieves underlying TextureRaw and clear this. | |
constexpr auto | operator<=> (const Texture &other) const =default |
Comparison. | |
constexpr bool | operator== (std::nullptr_t _) const |
Comparison. | |
constexpr | operator bool () const |
Converts to bool. | |
constexpr | operator TextureParam () const |
Converts to TextureParam. | |
void | Destroy () |
Destroy the specified texture. More... | |
PropertiesRef | GetProperties () const |
Get the properties associated with a texture. More... | |
RendererRef | GetRenderer () const |
Get the renderer that created an Texture. More... | |
void | SetMod (Color c) |
Set an additional color and alpha values multiplied into render copy operations. More... | |
void | SetModFloat (FColor c) |
Set an additional color and alpha values multiplied into render copy operations. More... | |
Color | GetMod () const |
Get the additional color value multiplied into render copy operations. More... | |
FColor | GetModFloat () const |
Get the additional color value multiplied into render copy operations. More... | |
void | SetColorMod (Uint8 r, Uint8 g, Uint8 b) |
Set an additional color value multiplied into render copy operations. More... | |
void | SetColorModFloat (float r, float g, float b) |
Set an additional color value multiplied into render copy operations. More... | |
void | GetColorMod (Uint8 *r, Uint8 *g, Uint8 *b) const |
Get the additional color value multiplied into render copy operations. More... | |
void | GetColorModFloat (float *r, float *g, float *b) const |
Get the additional color value multiplied into render copy operations. More... | |
void | SetAlphaMod (Uint8 alpha) |
Set an additional alpha value multiplied into render copy operations. More... | |
void | SetAlphaModFloat (float alpha) |
Set an additional alpha value multiplied into render copy operations. More... | |
Uint8 | GetAlphaMod () const |
Get the additional alpha value multiplied into render copy operations. More... | |
float | GetAlphaModFloat () const |
Get the additional alpha value multiplied into render copy operations. More... | |
void | SetBlendMode (BlendMode blendMode) |
Set the blend mode for a texture, used by Renderer.RenderTexture(). More... | |
BlendMode | GetBlendMode () const |
Get the blend mode used for texture copy operations. More... | |
void | SetScaleMode (ScaleMode scaleMode) |
Set the scale mode used for texture scale operations. More... | |
ScaleMode | GetScaleMode () const |
Get the scale mode used for texture scale operations. More... | |
void | Update (OptionalRef< const RectRaw > rect, const void *pixels, int pitch) |
Update the given texture rectangle with new pixel data. More... | |
void | UpdateYUV (OptionalRef< const RectRaw > rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, const Uint8 *Vplane, int Vpitch) |
Update a rectangle within a planar YV12 or IYUV texture with new pixel data. More... | |
void | UpdateNV (OptionalRef< const RectRaw > rect, const Uint8 *Yplane, int Ypitch, const Uint8 *UVplane, int UVpitch) |
Update a rectangle within a planar NV12 or NV21 texture with new pixels. More... | |
void | Lock (OptionalRef< const SDL_Rect > rect, void **pixels, int *pitch) |
Lock a portion of the texture for write-only pixel access. More... | |
Surface | LockToSurface (OptionalRef< const SDL_Rect > rect=std::nullopt) |
Lock a portion of the texture for write-only pixel access, and expose it as a SDL surface. More... | |
void | Unlock () |
Unlock a texture, uploading the changes to video memory, if needed. More... | |
int | GetWidth () const |
Get the width in pixels. | |
int | GetHeight () const |
Get the height in pixels. | |
Point | GetSize () const |
Get the size in pixels. | |
void | GetSize (float *w, float *h) const |
Get the size of a texture, as floating point values. More... | |
FPoint | GetSizeFloat () const |
Get the size in pixels. | |
PixelFormat | GetFormat () const |
Get the pixel format. | |
Static Public Member Functions | |
static constexpr Texture | Borrow (TextureParam resource) |
Safely borrows the from TextureParam. More... | |
|
inlineexplicitconstexpr |
resource | a TextureRaw to be wrapped. |
This assumes the ownership, call release() if you need to take back.
|
inline |
The contents of a texture when first created are not defined.
renderer | the rendering context. |
format | one of the enumerated values in PixelFormat. |
access | one of the enumerated values in TextureAccess. |
size | the width and height of the texture in pixels. |
Error | on failure. |
|
inline |
The surface is not modified or freed by this function.
The TextureAccess hint for the created texture is TEXTUREACCESS_STATIC
.
The pixel format of the created texture may be different from the pixel format of the surface, and can be queried using the prop::Texture.FORMAT_NUMBER property.
renderer | the rendering context. |
surface | the Surface structure containing pixel data used to fill the texture. |
Error | on failure. |
|
inline |
These are the supported properties:
prop::Texture.CREATE_COLORSPACE_NUMBER
: an Colorspace value describing the texture colorspace, defaults to COLORSPACE_SRGB_LINEAR for floating point textures, COLORSPACE_HDR10 for 10-bit textures, COLORSPACE_SRGB for other RGB textures and COLORSPACE_JPEG for YUV textures.prop::Texture.CREATE_FORMAT_NUMBER
: one of the enumerated values in PixelFormat, defaults to the best RGBA format for the rendererprop::Texture.CREATE_ACCESS_NUMBER
: one of the enumerated values in TextureAccess, defaults to TEXTUREACCESS_STATICprop::Texture.CREATE_WIDTH_NUMBER
: the width of the texture in pixels, requiredprop::Texture.CREATE_HEIGHT_NUMBER
: the height of the texture in pixels, requiredprop::Texture.CREATE_SDR_WHITE_POINT_FLOAT
: for HDR10 and floating point textures, this defines the value of 100% diffuse white, with higher values being displayed in the High Dynamic Range headroom. This defaults to 100 for HDR10 textures and 1.0 for floating point textures.prop::Texture.CREATE_HDR_HEADROOM_FLOAT
: for HDR10 and floating point textures, this defines the maximum dynamic range used by the content, in terms of the SDR white point. This would be equivalent to maxCLL / prop::Texture.CREATE_SDR_WHITE_POINT_FLOAT for HDR10 content. If this is defined, any values outside the range supported by the display will be scaled into the available HDR headroom, otherwise they are clipped.With the direct3d11 renderer:
prop::Texture.CREATE_D3D11_TEXTURE_POINTER
: the ID3D11Texture2D associated with the texture, if you want to wrap an existing texture.prop::Texture.CREATE_D3D11_TEXTURE_U_POINTER
: the ID3D11Texture2D associated with the U plane of a YUV texture, if you want to wrap an existing texture.prop::Texture.CREATE_D3D11_TEXTURE_V_POINTER
: the ID3D11Texture2D associated with the V plane of a YUV texture, if you want to wrap an existing texture.With the direct3d12 renderer:
prop::Texture.CREATE_D3D12_TEXTURE_POINTER
: the ID3D12Resource associated with the texture, if you want to wrap an existing texture.prop::Texture.CREATE_D3D12_TEXTURE_U_POINTER
: the ID3D12Resource associated with the U plane of a YUV texture, if you want to wrap an existing texture.prop::Texture.CREATE_D3D12_TEXTURE_V_POINTER
: the ID3D12Resource associated with the V plane of a YUV texture, if you want to wrap an existing texture.With the metal renderer:
prop::Texture.CREATE_METAL_PIXELBUFFER_POINTER
: the CVPixelBufferRef associated with the texture, if you want to create a texture from an existing pixel buffer.With the opengl renderer:
prop::Texture.CREATE_OPENGL_TEXTURE_NUMBER
: the GLuint texture associated with the texture, if you want to wrap an existing texture.prop::Texture.CREATE_OPENGL_TEXTURE_UV_NUMBER
: the GLuint texture associated with the UV plane of an NV12 texture, if you want to wrap an existing texture.prop::Texture.CREATE_OPENGL_TEXTURE_U_NUMBER
: the GLuint texture associated with the U plane of a YUV texture, if you want to wrap an existing texture.prop::Texture.CREATE_OPENGL_TEXTURE_V_NUMBER
: the GLuint texture associated with the V plane of a YUV texture, if you want to wrap an existing texture.With the opengles2 renderer:
prop::Texture.CREATE_OPENGLES2_TEXTURE_NUMBER
: the GLuint texture associated with the texture, if you want to wrap an existing texture.prop::Texture.CREATE_OPENGLES2_TEXTURE_NUMBER
: the GLuint texture associated with the texture, if you want to wrap an existing texture.prop::Texture.CREATE_OPENGLES2_TEXTURE_UV_NUMBER
: the GLuint texture associated with the UV plane of an NV12 texture, if you want to wrap an existing texture.prop::Texture.CREATE_OPENGLES2_TEXTURE_U_NUMBER
: the GLuint texture associated with the U plane of a YUV texture, if you want to wrap an existing texture.prop::Texture.CREATE_OPENGLES2_TEXTURE_V_NUMBER
: the GLuint texture associated with the V plane of a YUV texture, if you want to wrap an existing texture.With the vulkan renderer:
prop::Texture.CREATE_VULKAN_TEXTURE_NUMBER
: the VkImage with layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL associated with the texture, if you want to wrap an existing texture.renderer | the rendering context. |
props | the properties to use. |
Error | on failure. |
|
inlinestaticconstexpr |
resource | a TextureRaw or Texture. |
This does not takes ownership!
|
inline |
Error | on failure. |
|
inline |
Error | on failure. |
|
inline |
When this texture is rendered, during the copy operation each source color and alpha channels are modulated by the appropriate color value according to the following formula:
srcC = srcC * (color / 255) srcA = srcA * (alpha / 255)
Color and alpha modulation is not always supported by the renderer; it will return false if either modulation is not supported.
c | the color and alpha channel values multiplied into copy operations. |
Error | on failure. |
|
inline |
When this texture is rendered, during the copy operation each source color and alpha channels are modulated by the appropriate color value according to the following formula:
srcC = srcC * (color / 255) srcA = srcA * (alpha / 255)
Color and alpha modulation is not always supported by the renderer; it will return false if either modulation is not supported.
c | the color and alpha channel values multiplied into copy operations. |
Error | on failure. |