Skip to content

EntropyCanvas::TextureData

CPU-side texture pixel container. More…

#include <TextureData.h>

Name
size_ttotalBytes() const
Get total size in bytes across all mip levels.
TextureMetadatatoMetadata() const
Convert to TextureMetadata for network transfer.
boolisValid() const
Check if texture has valid data.
size_texpectedMipBytes(uint32_t mipLevel) const
Compute expected byte count for a mip level.
AssetIdcomputeAssetId() const
Compute content-addressed AssetId for this texture.
uint32_tcalculateMipLevels(uint32_t w, uint32_t h)
Calculate number of mip levels for given dimensions.
size_tbytesPerPixel() const
Get bytes per pixel for the current format.
Name
uint32_twidth
Width in pixels.
TextureTypetype
Texture dimension type.
std::stringrawFileFormat
File format hint (e.g., “tga”, “png”) for decoding on the receiver side.
std::vector< uint8_t >rawFileData
Original file bytes (PNG, TGA, etc.) if loaded from file When present, this is preferred for network transfer so the receiver can decode with stb_image.
std::stringname
Display name only (no file paths for privacy).
uint32_tmipLevels
Number of mip levels.
std::vector< std::vector< uint8_t > >mipData
Pixel data per mip level mipData[level] contains the bytes for that mip level.
uint32_theight
Height in pixels.
TextureFormatformat
Pixel format.
uint32_tdepth
Depth (for 3D textures, otherwise 1).
ColorSpacecolorSpace
Color space interpretation.
uint32_tarrayLayers
Number of array layers (for texture arrays).
struct EntropyCanvas::TextureData;

CPU-side texture pixel container.

Holds pixel data for a texture, ready for GPU upload. Supports multiple mip levels and various formats.

Usage:

// Load from file using TextureLoader
TextureData texture = TextureLoader::loadFromFile("diffuse.png");
// Build metadata for upload
AssetMetadataData metadata;
metadata.type = AssetMetadataType::Texture;
metadata.textureMetadata = texture.toMetadata();
// Upload via AssetClient
auto handle = assetClient->upload(
std::span<const uint8_t>(texture.mipData[0]),
ContentType::Texture,
true,
metadata
);
size_t totalBytes() const

Get total size in bytes across all mip levels.

Return: Total byte count

TextureMetadata toMetadata() const

Convert to TextureMetadata for network transfer.

Return: TextureMetadata for network transfer

Creates a TextureMetadata struct suitable for AssetClient upload. Does NOT include file paths (privacy protection).

bool isValid() const

Check if texture has valid data.

Return: true if dimensions are non-zero and at least one mip level has data

size_t expectedMipBytes(
uint32_t mipLevel
) const

Compute expected byte count for a mip level.

Parameters:

  • mipLevel Mip level (0 = base)

Return: Expected byte count for that mip level

AssetId computeAssetId() const

Compute content-addressed AssetId for this texture.

Return: Content-addressed AssetId for this texture

Computes a SHA-256 hash of the texture data to produce a deterministic, content-addressed identifier. Same texture always produces the same AssetId.

The hash includes:

  • name, dimensions, format, type, colorSpace
  • all mip level pixel data
static uint32_t calculateMipLevels(
uint32_t w,
uint32_t h
)

Calculate number of mip levels for given dimensions.

Parameters:

  • w Width
  • h Height

Return: floor(log2(max(w,h))) + 1

size_t bytesPerPixel() const

Get bytes per pixel for the current format.

Return: Bytes per pixel (0 for compressed formats)

uint32_t width = 0;

Width in pixels.

TextureType type = TextureType::Texture2D;

Texture dimension type.

std::string rawFileFormat;

File format hint (e.g., “tga”, “png”) for decoding on the receiver side.

std::vector< uint8_t > rawFileData;

Original file bytes (PNG, TGA, etc.) if loaded from file When present, this is preferred for network transfer so the receiver can decode with stb_image.

If empty, mipData is used instead.

std::string name;

Display name only (no file paths for privacy).

uint32_t mipLevels = 1;

Number of mip levels.

std::vector< std::vector< uint8_t > > mipData;

Pixel data per mip level mipData[level] contains the bytes for that mip level.

uint32_t height = 0;

Height in pixels.

TextureFormat format = TextureFormat::RGBA8;

Pixel format.

uint32_t depth = 1;

Depth (for 3D textures, otherwise 1).

ColorSpace colorSpace = ColorSpace::sRGB;

Color space interpretation.

uint32_t arrayLayers = 1;

Number of array layers (for texture arrays).


Updated on 2026-01-26 at 17:14:35 -0500