Class Texture#
Defined in File Texture.h
Inheritance Relationships#
Derived Type#
public TRAP::Graphics::API::VulkanTexture
(Class VulkanTexture)
Class Documentation#
-
class Texture#
Subclassed by TRAP::Graphics::API::VulkanTexture
Public Functions
-
virtual ~Texture() = default#
Destructor.
-
virtual void Init(const RendererAPI::TextureDesc &desc) = 0#
Initialize the Texture.
- Parameters:
desc – Texture 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 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.
image – Image 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.
image – Image 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:
desc – Texture 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.
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#
-
Graphics::API::ImageFormat m_imageFormat = Graphics::API::ImageFormat::R8G8B8A8_UNORM#
-
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:
imageFormat – Image format.
- Returns:
Color format.
-
static constexpr u32 GetBitsPerChannelFromImageFormat(API::ImageFormat imageFormat) noexcept#
Retrieve bits per channel from image format.
- Parameters:
imageFormat – Image format.
- Returns:
Bits per channel.
-
virtual ~Texture() = default#