Skip to content

EntropyCanvas::TextureLoader

Texture loading utility class. More…

#include <TextureLoader.h>

Name
structOptions
Loading options.
Name
TextureDataloadFromMemory(std::span< const uint8_t > data, const std::string & formatHint ="", const Options & options =defaultOptions()) =default
Load texture from memory buffer.
TextureDataloadFromFile(const std::string & filePath, const Options & options =defaultOptions()) =default
Load texture from file.
boolisFormatSupported(const std::string & extension)
Check if a file format is supported.
std::vector< std::string >getSupportedExtensions()
Get list of supported file extensions.
voidgenerateMipChain(TextureData & texture)
Generate mip chain for existing texture.
const Options &defaultOptions()
Get default loading options.
class EntropyCanvas::TextureLoader;

Texture loading utility class.

Loads textures from files or memory using OpenImageIO. Supports PNG, JPEG, TGA, BMP, PSD, GIF, HDR, PIC, EXR, TIFF, DPX, DDS, WebP formats.

Usage:

// Load with default options
TextureData tex = TextureLoader::loadFromFile("diffuse.png");
// Load with custom options
TextureLoader::Options opts;
opts.generateMips = true;
opts.maxDimension = 2048;
TextureData tex = TextureLoader::loadFromFile("diffuse.png", opts);
// Load from memory
std::vector<uint8_t> pngData = readFileContents("texture.png");
TextureData tex = TextureLoader::loadFromMemory(pngData, "png");
static TextureData loadFromMemory(
std::span< const uint8_t > data,
const std::string & formatHint ="",
const Options & options =defaultOptions()
) =default

Load texture from memory buffer.

Parameters:

  • data Raw image file data (not raw pixels)
  • formatHint File extension hint (e.g., “png”, “jpg”) - may be empty
  • options Loading options

Return: TextureData with loaded pixels, or invalid TextureData on failure

static TextureData loadFromFile(
const std::string & filePath,
const Options & options =defaultOptions()
) =default

Load texture from file.

Parameters:

  • filePath Path to image file
  • options Loading options

Return: TextureData with loaded pixels, or invalid TextureData on failure

Supports: PNG, JPEG, TGA, BMP, PSD (composited only), GIF (first frame), HDR (converted to LDR), PIC

static bool isFormatSupported(
const std::string & extension
)

Check if a file format is supported.

Parameters:

  • extension File extension (e.g., “png”, “.jpg”)

Return: true if format is supported

static std::vector< std::string > getSupportedExtensions()

Get list of supported file extensions.

Return: Vector of supported extensions (e.g., {“png”, “jpg”, “tga”, …})

static void generateMipChain(
TextureData & texture
)

Generate mip chain for existing texture.

Parameters:

  • texture Texture to generate mips for (must have mipData[0] populated)

Uses box filter downsampling to generate mip levels. Modifies the texture in place.

static inline const Options & defaultOptions()

Get default loading options.


Updated on 2026-01-26 at 16:50:32 -0500