Class TextureLib
Global texture resource cache and factory. More...
#include <Texture.h>
Public Types
| Type | Name |
|---|---|
| enum | NoiseType Noise texture types for procedural generation. |
| typedef std::shared_ptr< Texture > | TextureRes Shared pointer to Texture (for resource sharing) |
Public Static Attributes
| Type | Name |
|---|---|
| std::string | root_dir = "res/tex/"Root directory for texture files. |
Public Static Functions
| Type | Name |
|---|---|
| TextureRes | GetTexture (const std::string & _name) Retrieves a cached texture by name. |
| GLuint | GetTextureID (const std::string & _name) Returns OpenGL texture ID for a cached texture. |
| TextureRes | IBL_LUT () Generates or retrieves IBL BRDF lookup table. |
| TextureRes | LTC1 () Generates or retrieves LTC matrix 1 lookup table. |
| TextureRes | LTC2 () Generates or retrieves LTC matrix 2 lookup table. |
| TextureRes | LoadTexture (std::string _name) Loads texture from file or returns cached instance. |
| TextureRes | Noise_2D_16x16xN (int n=6) Generates or retrieves 16x16xN layered 2D noise texture. |
| TextureRes | Noise_2D_4x4 () Generates or retrieves 4x4 2D noise texture. |
| TextureRes | Noise_2D_4x4xN (int n=6) Generates or retrieves 4x4xN layered 2D noise texture. |
| Texture::TextureType | ParseFileEXT (std::string path) Infers texture type from file extension. |
| void | ResetTexLib () Resets texture library and clears cache. |
Detailed Description
TextureLib provides centralized texture management with automatic caching to prevent duplicate loading of textures. All textures are reference-counted via shared_ptr, and resources are released when no longer referenced.
Functionality: * Load and cache textures from files * Generate procedural textures (noise, LUTs) * Provide built-in textures (IBL BRDF LUT, LTC tables, etc.) * Manage texture lifetime and sharing
Usage:
auto tex = TextureLib::LoadTexture("albedo.png"); // Loads or returns cached
auto brdf_lut = TextureLib::IBL_LUT(); // Built-in LUT
auto noise = TextureLib::Noise_2D_16x16xN(6); // Procedural noise
Note:
All methods are static (global texture pool).
Note:
Thread-safety: Not thread-safe. Access from main thread only.
Public Types Documentation
enum NoiseType
Noise texture types for procedural generation.
enum TextureLib::NoiseType {
NONE_NOISE,
UNIFORM_NOISE,
GAUSSIAN_NOISE,
UNI_2D_NOISE
};
typedef TextureRes
Shared pointer to Texture (for resource sharing)
using TextureLib::TextureRes = std::shared_ptr<Texture>;
Public Static Attributes Documentation
variable root_dir
Root directory for texture files.
std::string TextureLib::root_dir;
Public Static Functions Documentation
function GetTexture
Retrieves a cached texture by name.
static TextureRes TextureLib::GetTexture (
const std::string & _name
)
Parameters:
_nameTexture name (file name or procedural name)
Returns:
Shared pointer to Texture, or nullptr if not found
function GetTextureID
Returns OpenGL texture ID for a cached texture.
static GLuint TextureLib::GetTextureID (
const std::string & _name
)
Parameters:
_nameTexture name
Returns:
Texture ID, or 0 if not found
function IBL_LUT
Generates or retrieves IBL BRDF lookup table.
static TextureRes TextureLib::IBL_LUT ()
Returns:
Shared pointer to BRDF LUT texture (RG16F, 512x512)
Note:
Used for split-sum approximation in PBR IBL
function LTC1
Generates or retrieves LTC matrix 1 lookup table.
static TextureRes TextureLib::LTC1 ()
Returns:
Shared pointer to LTC1 texture
Note:
Used for linearly transformed cosines (area lights)
function LTC2
Generates or retrieves LTC matrix 2 lookup table.
static TextureRes TextureLib::LTC2 ()
Returns:
Shared pointer to LTC2 texture
Note:
Used for linearly transformed cosines (area lights)
function LoadTexture
Loads texture from file or returns cached instance.
static TextureRes TextureLib::LoadTexture (
std::string _name
)
Parameters:
_nameTexture file name (relative to root_dir)
Returns:
Shared pointer to Texture
Note:
If texture already loaded, returns cached instance
function Noise_2D_16x16xN
Generates or retrieves 16x16xN layered 2D noise texture.
static TextureRes TextureLib::Noise_2D_16x16xN (
int n=6
)
Parameters:
nNumber of noise layers (default 6)
Returns:
Shared pointer to layered noise texture
function Noise_2D_4x4
Generates or retrieves 4x4 2D noise texture.
static TextureRes TextureLib::Noise_2D_4x4 ()
Returns:
Shared pointer to noise texture
function Noise_2D_4x4xN
Generates or retrieves 4x4xN layered 2D noise texture.
static TextureRes TextureLib::Noise_2D_4x4xN (
int n=6
)
Parameters:
nNumber of noise layers (default 6)
Returns:
Shared pointer to layered noise texture
function ParseFileEXT
Infers texture type from file extension.
static Texture::TextureType TextureLib::ParseFileEXT (
std::string path
)
Parameters:
pathFile path
Returns:
TextureType enum (.png → RGBA_TEXTURE, .jpg → RGB_TEXTURE, .hdr → HDR_TEXTURE)
function ResetTexLib
Resets texture library and clears cache.
static void TextureLib::ResetTexLib ()
Note:
Releases all cached textures (if no external references)
The documentation for this class was generated from the following file src/render/Texture.h