Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
mnd::Texture Class Reference

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< TextureLoad (const std::string &path)
 Load a texture from a file path using stb_image.
 
static std::shared_ptr< TextureLoadFromMemory (const unsigned char *data, int sizeBytes)
 Decode an in-memory image (PNG/JPG/...) into a GPU texture.
 

Detailed Description

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.

Definition at line 40 of file Texture.h.

Constructor & Destructor Documentation

◆ Texture()

mnd::Texture::Texture ( int  width,
int  height,
int  numChannels,
unsigned char *  data 
)

Upload pixel data to the GPU immediately.

Parameters
widthImage width in pixels.
heightImage height in pixels.
numChannelsNumber of channels (1 = greyscale, 3 = RGB, 4 = RGBA).
dataRaw pixel bytes (stb_image output). May be freed after this call.

Definition at line 16 of file Texture.cpp.

References Init().

◆ ~Texture()

mnd::Texture::~Texture ( )

Calls glDeleteTextures() to release the GPU handle.

Definition at line 24 of file Texture.cpp.

Member Function Documentation

◆ GetID()

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().

◆ Init()

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().

◆ Load()

std::shared_ptr< Texture > mnd::Texture::Load ( const std::string &  path)
static

Load a texture from a file path using stb_image.

Parameters
pathFilesystem path to a PNG/JPG/BMP/TGA image.
Returns
Shared pointer to the loaded Texture, or nullptr on failure.

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().

◆ LoadFromMemory()

std::shared_ptr< Texture > mnd::Texture::LoadFromMemory ( const unsigned char *  data,
int  sizeBytes 
)
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.


The documentation for this class was generated from the following files: