|
libmx2 2.2.1
C++20 multimedia and game-engine library (SDL2 / OpenGL / Vulkan)
|
RAII wrapper around an SDL_Texture. More...
#include <texture.hpp>
Public Member Functions | |
| Texture ()=default | |
| Default constructor — no texture loaded. | |
| Texture (const Texture &tex)=delete | |
| Texture (Texture &&tex) | |
| Move constructor — transfers ownership of the SDL_Texture. | |
| Texture & | operator= (const Texture &tex)=delete |
| Texture & | operator= (Texture &&tex) |
| Move-assign — transfers ownership of the SDL_Texture. | |
| ~Texture () | |
| Destructor — destroys the SDL_Texture if held. | |
| void | createTexture (mxWindow *window, int width, int height) |
| Create an empty (blank) texture of the given dimensions. | |
| void | loadTexture (mxWindow *window, const std::string &filename) |
| Load a texture from an image file. | |
| void | loadTexture (mxWindow *window, const std::string &filename, int &w, int &h, bool color, SDL_Color key) |
| Load a texture with optional colour-key transparency. | |
| bool | saveTexture (mxWindow *window, const std::string &filename) |
| Save the texture to a file. | |
| std::optional< SDL_Texture * > | handle () const |
| Return the SDL_Texture as an optional. | |
| SDL_Texture * | unwrap () const |
| Unwrap the SDL_Texture pointer, throwing on null. | |
| Wrapper< SDL_Texture * > | wrapper () const |
| Return a Wrapper around the SDL_Texture handle. | |
| int | width () const |
| int | height () const |
Static Public Member Functions | |
| static SDL_Surface * | flipSurface (SDL_Surface *surface) |
| Flip an SDL_Surface vertically (in-place). | |
Private Member Functions | |
| int | imageType (const std::string &type) |
| bool | saveBMP (SDL_Texture *texture, SDL_Renderer *renderer, const std::string &name) |
Private Attributes | |
| SDL_Texture * | texture = nullptr |
| Managed SDL texture handle. | |
| int | width_ = 0 |
| Cached texture width. | |
| int | height_ = 0 |
| Cached texture height. | |
RAII wrapper around an SDL_Texture.
Manages the lifetime of an SDL_Texture and provides helpers for loading from image files, creating blank textures, saving to BMP, and an in-place vertical flip of an SDL_Surface. Only move semantics are supported; copying is disabled to prevent double-free.
Definition at line 29 of file texture.hpp.
|
default |
Default constructor — no texture loaded.
Referenced by operator=(), operator=(), Texture(), and Texture().
|
delete |
References Texture().
| mx::Texture::Texture | ( | Texture && | tex | ) |
| mx::Texture::~Texture | ( | ) |
Destructor — destroys the SDL_Texture if held.
Definition at line 119 of file texture.cpp.
References texture.
| void mx::Texture::createTexture | ( | mxWindow * | window, |
| int | width, | ||
| int | height ) |
Create an empty (blank) texture of the given dimensions.
| window | Owning window supplying the renderer. |
| width | Texture width in pixels. |
| height | Texture height in pixels. |
Definition at line 34 of file texture.cpp.
References height(), mx::mxWindow::renderer, texture, and width().
|
inlinestatic |
Flip an SDL_Surface vertically (in-place).
| surface | Surface to flip. |
Definition at line 118 of file texture.hpp.
Referenced by gl::GLText::createText(), gl::createTexture(), gl::loadTexture(), gl::loadTexture(), and gl::updateTexture().
|
inline |
Return the SDL_Texture as an optional.
Definition at line 83 of file texture.hpp.
References texture.
|
inline |
Definition at line 139 of file texture.hpp.
References height_.
Referenced by createTexture(), operator=(), and saveBMP().
|
private |
Definition at line 124 of file texture.cpp.
Referenced by loadTexture(), and saveTexture().
| void mx::Texture::loadTexture | ( | mxWindow * | window, |
| const std::string & | filename ) |
Load a texture from an image file.
| window | Owning window supplying the renderer. |
| filename | Path to the image file (PNG, BMP, etc.). |
Definition at line 44 of file texture.cpp.
References loadTexture().
Referenced by loadTexture().
| void mx::Texture::loadTexture | ( | mxWindow * | window, |
| const std::string & | filename, | ||
| int & | w, | ||
| int & | h, | ||
| bool | color, | ||
| SDL_Color | key ) |
Load a texture with optional colour-key transparency.
| window | Owning window. |
| filename | Image file path. |
| w | Output: loaded image width. |
| h | Output: loaded image height. |
| color | If true, apply the colour key. |
| key | Colour to treat as transparent. |
Definition at line 49 of file texture.cpp.
References height_, imageType(), jpeg::LoadJPEG(), png::LoadPNG(), mx::mxWindow::renderer, texture, and width_.
|
private |
Definition at line 137 of file texture.cpp.
References height(), and width().
Referenced by saveTexture().
| bool mx::Texture::saveTexture | ( | mxWindow * | window, |
| const std::string & | filename ) |
Save the texture to a file.
| window | Owning window supplying the renderer. |
| filename | Destination file path (BMP format). |
true on success. Definition at line 99 of file texture.cpp.
References imageType(), mx::mxWindow::renderer, saveBMP(), jpeg::SaveJPEG(), png::SavePNG(), and texture.
|
inline |
Unwrap the SDL_Texture pointer, throwing on null.
| mx::Exception | if texture is not loaded. |
Definition at line 94 of file texture.hpp.
References texture.
|
inline |
Definition at line 137 of file texture.hpp.
References width_.
Referenced by createTexture(), operator=(), and saveBMP().
|
inline |
Return a Wrapper around the SDL_Texture handle.
Definition at line 106 of file texture.hpp.
References texture.
|
private |
Cached texture height.
Definition at line 143 of file texture.hpp.
Referenced by height(), loadTexture(), operator=(), and Texture().
|
private |
Managed SDL texture handle.
Definition at line 141 of file texture.hpp.
Referenced by createTexture(), handle(), loadTexture(), operator=(), saveTexture(), Texture(), unwrap(), wrapper(), and ~Texture().
|
private |
Cached texture width.
Definition at line 142 of file texture.hpp.
Referenced by loadTexture(), operator=(), Texture(), and width().