Engine → Renderer → texture_asset.h
texture_asset
| Type | Class |
| Namespace | conjure::renderer |
| Include File Path | engine/include/conjure/renderer/texture_asset.h |
| Source File Path | engine/src/renderer/assets/texture_asset.cpp |
| API ↗ | Rendering, JPEG XL images, Renderer assets |
Syntax
Constructors
| Access | Signature | Description |
|---|---|---|
| public | texture_asset(); | |
| public | texture_asset(
const texture_asset &) = default; | |
| public | texture_asset(
texture_asset &&) noexcept = default; |
Destructors
| Access | Signature | Description |
|---|---|---|
| public | ~texture_asset(); |
Variables
| Access | Name | Type | Default | Description |
|---|---|---|---|---|
| public | MAX_ | static constexpr u32 | 16384 | Largest width or height accepted (the D3D12 / Vulkan guaranteed limit). |
| private | mColourSpace | texture_colour_space | texture_ | |
| private | mFilter | sampler_filter | sampler_ | |
| private | mFormat | rhi::texture_format | rhi:: | |
| private | mMips | std::vector<texture_mip> | {} | |
| private | mName | std::string | {} | |
| private | mWrap | texture_wrap | texture_ |
Functions
Public
checker
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
colour_space[[nodiscard]] texture_colour_space colour_space() const noexcept;decode
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
filter[[nodiscard]] sampler_filter filter() const noexcept;format
format[[nodiscard]] rhi::texture_format format() const noexcept;from_image
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
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.
height
height[[nodiscard]] u32 height() const noexcept;load_from_file
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
mip_count[[nodiscard]] u32 mip_count() const noexcept;mips
mips[[nodiscard]] std::span<const texture_mip> mips() const noexcept;name
name[[nodiscard]] std::string_view name() const noexcept;parse_blob
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
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
set_filtervoid set_filter(
sampler_filter filter) noexcept;set_name
set_namevoid set_name(
std::string name);set_wrap
set_wrapvoid set_wrap(
texture_wrap wrap) noexcept;solid_colour
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
width[[nodiscard]] u32 width() const noexcept;wrap
wrap[[nodiscard]] texture_wrap wrap() const noexcept;write_blob
write_blob[[nodiscard]] std::vector<std::byte> write_blob() const;Serialises the texture as a .ctex blob (little-endian, deterministic).
Operator Overloads
Public
operator=
operator=texture_asset &operator=(
const texture_asset &) = default;texture_asset &operator=(
texture_asset &&) noexcept = default;operator==
operator==[[nodiscard]] bool operator==(
const texture_asset &other) const noexcept;