Skip to content

Engine → Renderer → texture_asset.h

texture_asset

Syntax

class CONJURE_API texture_asset

Constructors

AccessSignatureDescription
publictexture_asset();
publictexture_asset( const texture_asset &) = default;
publictexture_asset( texture_asset &&) noexcept = default;

Destructors

AccessSignatureDescription
public~texture_asset();

Variables

AccessNameTypeDefaultDescription
publicMAX_DIMENSIONstatic constexpr u3216384Largest width or height accepted (the D3D12 / Vulkan guaranteed limit).
privatemColourSpacetexture_colour_spacetexture_colour_space::SRGB
privatemFiltersampler_filtersampler_filter::LINEAR
privatemFormatrhi::texture_formatrhi::texture_format::RGBA8_SRGB
privatemMipsstd::vector<texture_mip>{}
privatemNamestd::string{}
privatemWraptexture_wraptexture_wrap::REPEAT

Functions

Public

checker

[[nodiscard]] static texture_asset checker(
    core::rgba8 first,
    core::rgba8 second,
    u32 size = 16,
    u32 cellSize = 4,
    texture_colour_space colourSpace = texture_colour_space::SRGB);

A checkerboard of two colours with cellSize pixel cells.

colour_space

[[nodiscard]] texture_colour_space colour_space() const noexcept;

decode

[[nodiscard]] static core::result<texture_asset> decode(
    std::span<const std::byte> encoded,
    texture_colour_space colourSpace,
    bool generateMips = true,
    core::jobs::job_system *jobs = nullptr);

Decodes an encoded image file (JPEG XL, PNG, JPEG, TGA, BMP), recognised by its signature. A JPEG XL file is colour-managed: SRGB converts its colour profile to sRGB, LINEAR keeps its samples as stored (data such as normals must not change). For SRGB a PQ or HLG file is taken to linear light with 1.0 at 203 nits (BT.2408's reference white), clipped at 1 and sRGB-encoded, so reference white is white and brighter highlights clip. Its orientation is applied, premultiplied alpha is divided out in the encoding the file stores, before any conversion, an animation keeps its first frame (with a warning), and colour and alpha deeper than 8 bits keep their high byte, as a 16-bit PNG does (8-bit colour beside a deeper alpha is rounded). The other formats ignore colour profiles. jobs (optional) decodes a JPEG XL file on its workers; the result is the same bytes either way, and so is the memory limit below. Fails with renderer_error::DECODE_FAILED for anything the decoder rejects, naming a truncated file apart from a corrupt one, and with INVALID_ARGUMENT for empty data, an image larger than MAX_DIMENSION, or a JPEG XL file whose header asks for more than its limits allow: more than 16 extra channels or a layer larger than MAX_DIMENSION (both refused before any frame is decoded), or more decoding memory than the image's size allows.

filter

[[nodiscard]] sampler_filter filter() const noexcept;

format

[[nodiscard]] rhi::texture_format format() const noexcept;

from_image

[[nodiscard]] static core::result<texture_asset> from_image(
    const core::image &source,
    texture_colour_space colourSpace,
    bool generateMips = true);

from_rgba8 over a core::image.

from_rgba8

[[nodiscard]] static core::result<texture_asset> from_rgba8(
    u32 width,
    u32 height,
    std::span<const std::byte> pixels,
    texture_colour_space colourSpace,
    bool generateMips = true);

Builds a texture from RGBA8 pixels (rows top to bottom, no padding). SRGB selects the RGBA8_SRGB format, LINEAR RGBA8_UNORM; with generateMips the full chain is built with a box filter in linear space. Fails with INVALID_ARGUMENT for a zero size, a size above MAX_DIMENSION or a pixel array of the wrong length.

gpu_byte_size

[[nodiscard]] u64 gpu_byte_size() const noexcept;

Bytes of every mip together.

height

[[nodiscard]] u32 height() const noexcept;

load_from_file

[[nodiscard]] static core::result<texture_asset> load_from_file(
    const std::filesystem::path &path,
    texture_colour_space colourSpace,
    bool generateMips = true,
    core::jobs::job_system *jobs = nullptr);

Reads and decodes a file. Fails with NOT_FOUND when the file does not exist, IO_FAILURE when it cannot be read, then as decode().

mip_count

[[nodiscard]] u32 mip_count() const noexcept;

mips

[[nodiscard]] std::span<const texture_mip> mips() const noexcept;

name

[[nodiscard]] std::string_view name() const noexcept;

parse_blob

[[nodiscard]] static core::result<texture_asset> parse_blob(
    std::span<const std::byte> bytes);

Parses a .ctex blob. Fails with renderer_error::INVALID_ASSET naming the problem.

pixel

[[nodiscard]] core::rgba8 pixel(
    u32 x,
    u32 y) const noexcept;

The pixel of mip 0 at (x, y) as RGBA8 (the 8-bit formats only; other formats read opaque black). Out of range asserts and reads black.

set_filter

void set_filter(
    sampler_filter filter) noexcept;

set_name

void set_name(
    std::string name);

set_wrap

void set_wrap(
    texture_wrap wrap) noexcept;

solid_colour

[[nodiscard]] static texture_asset solid_colour(
    core::rgba8 colour,
    texture_colour_space colourSpace,
    u32 width = 1,
    u32 height = 1);

A 1x1 (or width x height) texture of one colour.

width

[[nodiscard]] u32 width() const noexcept;

wrap

[[nodiscard]] texture_wrap wrap() const noexcept;

write_blob

[[nodiscard]] std::vector<std::byte> write_blob() const;

Serialises the texture as a .ctex blob (little-endian, deterministic).

Operator Overloads

Public

operator=

texture_asset &operator=(
    const texture_asset &) = default;
texture_asset &operator=(
    texture_asset &&) noexcept = default;

operator==

[[nodiscard]] bool operator==(
    const texture_asset &other) const noexcept;