Class Texture#

Inheritance Relationships#

Derived Type#

Class Documentation#

class Texture#

Subclassed by TRAP::Graphics::API::VulkanTexture

Public Functions

virtual ~Texture() = default#

Destructor.

consteval Texture(const Texture&) noexcept = delete#

Copy constructor.

consteval Texture &operator=(const Texture&) noexcept = delete#

Copy assignment operator.

Texture(Texture&&) noexcept = default#

Move constructor.

Texture &operator=(Texture&&) noexcept = default#

Move assignment operator.

virtual void Init(const RendererAPI::TextureDesc &desc) = 0#

Initialize the Texture.

Parameters:

descTexture description.

bool Reload()#

Reload texture.

Returns:

True on successful reload (valid texture), else (invalid texture) otherwise.

constexpr std::string GetName() const noexcept#

Retrieve the name of the texture.

Returns:

Name of the texture.

constexpr TextureType GetType() const noexcept#

Retrieve the texture type.

Returns:

Texture type.

constexpr u32 GetWidth() const noexcept#

Retrieve the texture width.

Returns:

Texture width.

constexpr u32 GetHeight() const noexcept#

Retrieve the texture height.

Returns:

Texture height.

constexpr Math::Vec2ui GetSize() const noexcept#

Retrieve the texture size.

Returns:

Texture size.

constexpr u32 GetDepth() const noexcept#

Retrieve the texture depth.

Returns:

Texture depth.

constexpr u32 GetArraySize() const noexcept#

Retrieve the texture array size.

Returns:

Texture array size.

constexpr u32 GetMipLevels() const noexcept#

Retrieve the textures mip level count.

Returns:

Textures mip level count.

constexpr u32 GetAspectMask() const noexcept#

Retrieve the textures aspect mask. Aspect mask specifies which aspects (Color, Depth, Stencil) are included in the texture.

Returns:

Aspect mask.

constexpr Image::ColorFormat GetColorFormat() const noexcept#

Retrieve the textures color format.

Returns:

Textures color format.

constexpr TRAP::Graphics::API::ImageFormat GetImageFormat() const noexcept#

Retrieve the textures image format.

Returns:

Image format.

constexpr RendererAPI::DescriptorType GetDescriptorTypes() const noexcept#

Retrieve the textures used descriptor types.

Returns:

Used descriptor types.

constexpr u32 GetBitsPerChannel() const noexcept#

Retrieve the textures bits per channel.

Returns:

Textures bits per channel.

constexpr u32 GetBytesPerChannel() const noexcept#

Retrieve the textures bytes per channel.

Returns:

Textures bytes per channel.

constexpr u32 GetBitsPerPixel() const noexcept#

Retrieve the textures bits per pixel.

Returns:

Textures bits per pixel.

constexpr u32 GetBytesPerPixel() const noexcept#

Retrieve the textures bytes per pixel.

Returns:

Textures bytes per pixel.

constexpr u32 GetMipWidth(u32 mipLevel) const#

Retrieve the textures mip width of a specific level.

Parameters:

mipLevel – Mip level.

Returns:

Mip width.

constexpr u32 GetMipHeight(u32 mipLevel) const#

Retrieve the textures mip height of a specific level.

Parameters:

mipLevel – Mip level.

Returns:

Mip height.

constexpr Math::Vec2ui GetMipSize(u32 mipLevel) const#

Retrieve the textures mip size of a specific level.

Parameters:

mipLevel – Mip level.

Returns:

Mip size.

constexpr const std::vector<std::filesystem::path> &GetFilePaths() const noexcept#

Retrieve the file paths of the texture.

Returns:

File paths of the texture.

constexpr TRAP::Optional<TextureCubeFormat> GetCubeFormat() const noexcept#

Retrieve the cube format of the texture.

Returns:

Cube format of the texture.

void Update(std::span<const u8>, u32 mipLevel = 0, u32 arrayLayer = 0)#

Update the texture with raw pixel data.

Note

Data array length and sizeInBytes must match the textures current size or it won’t update

Parameters:
  • data – Raw pixel data.

  • mipLevel – Mip level to update. Default: 0

  • arrayLayer – Array layer to update. Default: 0

void Update(std::span<const u16>, u32 mipLevel = 0, u32 arrayLayer = 0)#

Update the texture with raw pixel data.

Note

Data array length and sizeInBytes must match the textures current size or it won’t update

Parameters:
  • data – Raw pixel data.

  • mipLevel – Mip level to update. Default: 0

  • arrayLayer – Array layer to update. Default: 0

void Update(std::span<const f32>, u32 mipLevel = 0, u32 arrayLayer = 0)#

Update the texture with raw pixel data.

Note

Data array length and sizeInBytes must match the textures current size or it won’t update

Parameters:
  • data – Raw pixel data.

  • mipLevel – Mip level to update. Default: 0

  • arrayLayer – Array layer to update. Default: 0

constexpr bool OwnsImage() const noexcept#

Retrieve whether the texture owns the image data.

Returns:

True if texture owns the image data, false otherwise.

bool IsLoaded() const#

Check if texture finished loading.

Returns:

True if texture finished loading, false otherwise.

void AwaitLoading() const#

Wait for texture to finish loading.

Public Static Functions

static Ref<Texture> CreateCube(std::string name, std::span<const std::filesystem::path, 6> filePaths, TextureCreationFlags flags = TextureCreationFlags::None)#

Create a cube texture from 6 files.

Parameters:
  • name – Name for the texture.

  • filePaths – File paths of the 6 texture files. Order: +X, -X, +Y, -Y, +Z, -Z

  • flags – Additional flags. Default: None.

Returns:

Loaded texture on success, Fallback texture if texture loading failed, nullptr otherwise.

static Ref<Texture> CreateCube(std::string name, std::span<const Image*, 6> images, TextureCreationFlags flags = TextureCreationFlags::None)#

Create a cube texture from 6 TRAP::Images.

Note

The images must be valid till IsLoaded() returns true.

Parameters:
  • name – Name for the texture.

  • images – Images to create the texture from. Order: +X, -X, +Y, -Y, +Z, -Z

  • flags – Additional flags. Default: None.

Returns:

Loaded texture on success, Fallback texture if texture loading failed, nullptr otherwise.

static Ref<Texture> CreateCube(std::string name, const std::filesystem::path &filePath, TextureCubeFormat cubeFormat, TextureCreationFlags flags = TextureCreationFlags::None)#

Create a cube texture from 1 file.

Parameters:
  • name – Name for the texture.

  • filePath – File path of the texture file.

  • cubeFormat – Format for the cube texture.

  • flags – Additional flags. Default: None.

Returns:

Loaded texture on success, Fallback texture if texture loading failed, nullptr otherwise.

static Ref<Texture> CreateCube(std::string name, const Image &image, TextureCubeFormat cubeFormat, TextureCreationFlags flags = TextureCreationFlags::None)#

Create a cube texture from 1 TRAP::Image.

Note

The image must be valid till IsLoaded() returns true.

Parameters:
  • name – Name for the texture.

  • imageImage to create the texture from.

  • cubeFormat – Format for the cube texture.

  • flags – Additional flags. Default: None.

Returns:

Loaded texture on success, Fallback texture if texture loading failed, nullptr otherwise.

static Ref<Texture> CreateCube(std::string name, u32 width, u32 height, u32 bitsPerPixel, Image::ColorFormat format, TextureCreationFlags flags = TextureCreationFlags::None)#

Create an empty cube texture.

Parameters:
  • name – Name for the texture.

  • width – Width for the texture.

  • height – Height for the texture.

  • bitsPerPixel – Bits per pixel for the texture.

  • format – Color format for the texture.

  • flags – Additional flags. Default: None.

Returns:

Empty texture on success, nullptr otherwise.

static Ref<Texture> Create2D(std::string name, const std::filesystem::path &filePath, TextureCreationFlags flags = TextureCreationFlags::None)#

Create a 2d texture from file.

Parameters:
  • name – Name for the texture.

  • filePath – File path of the texture.

  • flags – Additional flags. Default: None.

Returns:

Loaded texture on success, Fallback texture if texture loading failed, nullptr otherwise.

static Ref<Texture> Create2D(std::string name, const Image &image, TextureCreationFlags flags = TextureCreationFlags::None)#

Create a 2d texture from TRAP::Image.

Note

The image must be valid till IsLoaded() returns true.

Parameters:
  • name – Name for the texture.

  • imageImage to create the texture from.

  • flags – Additional flags. Default: None.

Returns:

Loaded texture on success, Fallback texture if texture loading failed, nullptr otherwise.

static Ref<Texture> Create2D(std::string name, u32 width, u32 height, u32 bitsPerPixel, Image::ColorFormat format, TextureCreationFlags flags = TextureCreationFlags::None)#

Create an empty 2d texture.

Parameters:
  • name – Name for the texture.

  • width – Width for the texture.

  • height – Height for the texture.

  • bitsPerPixel – Bits per pixel for the texture.

  • format – Color format for the texture.

  • flags – Additional flags. Default: None.

Returns:

Empty texture on success, nullptr otherwise.

static Ref<Texture> CreateCustom(const RendererAPI::TextureDesc &desc)#

Create a custom texture.

Parameters:

descTexture description.

Returns:

Create texture on success, nullptr otherwise.

static Ref<Texture> CreateFallback2D()#

Create the fallback 2D texture.

Returns:

Fallback 2D texture.

static Ref<Texture> CreateFallbackCube()#

Create the fallback cube texture.

Returns:

Fallback cube texture.

static constexpr u32 CalculateMipLevels(u32 width, u32 height)#

Calculate the size of a mip level.

Parameters:
  • width – Width of the texture.

  • height – Height of the texture.

Returns:

Size of the mip level.

template<typename T>
static std::array<TRAP::Scope<TRAP::Image>, 6> SplitImageFromCross(const TRAP::Image &image)#

Split a horizontal or vertical cross texture into multiple textures.

Parameters:

imageImage to split.

Returns:

Array of splitted textures.

Protected Functions

virtual void Shutdown() = 0#

Shutdown API dependent texture.

explicit constexpr Texture(std::string name)#

Constructor.

Texture(std::string name, std::vector<std::filesystem::path> filePaths)#

Constructor.

Texture(std::string name, std::vector<std::filesystem::path> filePaths, const TRAP::Optional<TextureCubeFormat> &cubeFormat)#

Constructor.

Protected Attributes

std::string m_name#
API::SyncToken m_syncToken = 0#
u32 m_width = 2#
u32 m_height = 2#
u32 m_depth = 1#
u32 m_arraySize = 1#
u32 m_mipLevels = 1#
Graphics::API::ImageFormat m_imageFormat = Graphics::API::ImageFormat::R8G8B8A8_UNORM#
u32 m_aspectMask = 0#
RendererAPI::DescriptorType m_descriptorTypes = RendererAPI::DescriptorType::Texture#
bool m_ownsImage = true#
std::vector<std::filesystem::path> m_filepaths#
TRAP::Optional<TextureCubeFormat> m_textureCubeFormat = TRAP::NullOpt#

Protected Static Functions

static constexpr Image::ColorFormat ImageFormatToColorFormat(API::ImageFormat imageFormat) noexcept#

Convert image format to color format.

Parameters:

imageFormatImage format.

Returns:

Color format.

static constexpr u32 GetBitsPerChannelFromImageFormat(API::ImageFormat imageFormat) noexcept#

Retrieve bits per channel from image format.

Parameters:

imageFormatImage format.

Returns:

Bits per channel.