|
Monad Engine da02fba2
> Undercity Codex_
|
2D OpenGL texture object wrapping a GL_TEXTURE_2D handle. More...
#include <Texture.h>
Public Member Functions | |
| Texture (int width, int height, int numChannels, unsigned char *data) | |
| Upload pixel data to the GPU immediately. | |
| ~Texture () | |
| Calls glDeleteTextures() to release the GPU handle. | |
| GLuint | GetID () const |
| Returns the underlying OpenGL texture handle (GL_TEXTURE_2D target). | |
| void | Init (int width, int height, int numChannels, unsigned char *data) |
| (Re-)initialise the texture with new pixel data. Called by the constructor; can also re-upload changed data. | |
Static Public Member Functions | |
| static std::shared_ptr< Texture > | Load (const std::string &path) |
| Load a texture from a file path using stb_image. | |
| static std::shared_ptr< Texture > | LoadFromMemory (const unsigned char *data, int sizeBytes) |
| Decode an in-memory image (PNG/JPG/...) into a GPU texture. | |
2D OpenGL texture object wrapping a GL_TEXTURE_2D handle.
Loaded from disk via stb_image. Once uploaded to the GPU the CPU pixel data is freed. The GL handle lives until the Texture is destroyed.
| mnd::Texture::Texture | ( | int | width, |
| int | height, | ||
| int | numChannels, | ||
| unsigned char * | data | ||
| ) |
Upload pixel data to the GPU immediately.
| width | Image width in pixels. |
| height | Image height in pixels. |
| numChannels | Number of channels (1 = greyscale, 3 = RGB, 4 = RGBA). |
| data | Raw pixel bytes (stb_image output). May be freed after this call. |
Definition at line 16 of file Texture.cpp.
References Init().
| mnd::Texture::~Texture | ( | ) |
Calls glDeleteTextures() to release the GPU handle.
Definition at line 24 of file Texture.cpp.
| GLuint mnd::Texture::GetID | ( | ) | const |
Returns the underlying OpenGL texture handle (GL_TEXTURE_2D target).
Definition at line 71 of file Texture.cpp.
Referenced by mnd::ShaderProgram::SetTexture().
| void mnd::Texture::Init | ( | int | width, |
| int | height, | ||
| int | numChannels, | ||
| unsigned char * | data | ||
| ) |
(Re-)initialise the texture with new pixel data. Called by the constructor; can also re-upload changed data.
Definition at line 32 of file Texture.cpp.
Referenced by Texture().
|
static |
Load a texture from a file path using stb_image.
| path | Filesystem path to a PNG/JPG/BMP/TGA image. |
Definition at line 76 of file Texture.cpp.
References mnd::FileSystem::GetAssetsFolder(), mnd::Engine::GetFileSystem(), mnd::Engine::GetInstance(), and LOG_INFO.
Referenced by mnd::TextureManager::GetOrLoadTexture(), mnd::Material::Load(), and mnd::MeshComponent::LoadProperties().
|
static |
Decode an in-memory image (PNG/JPG/...) into a GPU texture.
Used for textures embedded inside model containers (.glb, FBX with embedded media), where there's no path to read from disk.
Definition at line 104 of file Texture.cpp.