Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
Engine::Assets::RuntimeTexture Class Reference

Runtime-owned Vulkan texture resource. More...

#include <Texture.h>

Collaboration diagram for Engine::Assets::RuntimeTexture:

Public Member Functions

 RuntimeTexture ()=default
 Creates an empty texture with no image data or Vulkan resources.
void setupImageFormat (const tinygltf::Image &imageData)
 Selects a Vulkan format from tinygltf image bit depth and component count.
 RuntimeTexture (const tinygltf::Image &imageData, TextureType type, Core::ApplicationContext *context)
 Construct a texture with explicit type for correct format selection.
 RuntimeTexture (Textures::Ktx2TextureData ktx2Data, TextureType type, Core::ApplicationContext *context)
 Construct a texture from KTX2 data with pre-computed mipmaps.
 RuntimeTexture (const tinygltf::Image &imageData, Core::ApplicationContext *context)
 Construct a texture with default type (BaseColor/SRGB)
 ~RuntimeTexture ()=default
 Destroys the C++ object without automatically releasing Vulkan resources.
 RuntimeTexture (const RuntimeTexture &)=delete
 Runtime textures are move-only because they own Vulkan handles.
RuntimeTextureoperator= (const RuntimeTexture &)=delete
 Runtime textures are move-only because they own Vulkan handles.
 RuntimeTexture (RuntimeTexture &&other) noexcept
 Move-constructs a texture and transfers Vulkan handles and prepared upload data.
RuntimeTextureoperator= (RuntimeTexture &&other) noexcept
 Move-assigns a texture and transfers Vulkan handles and prepared upload data.
VkImage getVkImage () const
 Gets the Vulkan image handle.
VkDeviceMemory getVkImageMemory () const
 Gets the device memory backing the VMA image allocation.
VkImageView getVkImageView () const
 Gets the Vulkan image view used for sampling.
VkSampler getVkImageSampler () const
 Gets the sampler used for shader reads.
bool isDescriptorIndexInitialized () const
 Checks whether this texture has a descriptor array slot.
uint32_t getDescriptorIndex () const
 Gets the descriptor array slot assigned by the asset manager.
void createDataUploadCommand (VkCommandBuffer commandBuffer, Rendering::Renderer *renderer) const
 Records commands that upload prepared image data into the Vulkan texture.
VkFormat getTextureFormat () const
 Gets the Vulkan image format selected for this texture.
TextureType getTextureType () const
 Get the semantic texture type.
uint32_t getMipLevels () const
 Gets the number of mip levels in the Vulkan image.
uint32_t getSourceMipLevels () const
 Gets the number of mip levels present in the source texture data.
uint32_t getSourceBaseMip () const
 Gets the base mip represented by the source texture data.
uint32_t getSourceWidth () const
 Gets the original source texture width.
uint32_t getSourceHeight () const
 Gets the original source texture height.
bool hasPrecomputedMipmaps () const
 Checks whether source data already contains mipmaps.
void generateMipmaps (VkCommandBuffer commandBuffer) const
 Generate mipmaps for this texture using vkCmdBlitImage.
void createResources ()
 Create Vulkan resources (VkImage, VkImageView, VkSampler) for this texture. Safe to call from worker threads when VMA is configured for thread safety.
void discardPreparedResources ()
 Destroy Vulkan resources without registering the texture.

Static Public Member Functions

static uint32_t calculateMipLevels (uint32_t width, uint32_t height)
 Calculates the full mip chain length for a texture size.

Private Member Functions

void addPaddingToImage ()
void dilateLightmapImage ()
template<typename T>
void addPaddingHelper ()
void setDebugName (const std::string &debugName) const
void cleanup () const
void reset ()

Private Attributes

VkImage vkTexture {}
VmaAllocation textureAllocation_ = VK_NULL_HANDLE
 VMA allocation for texture memory.
VkImageView vkTextureView {}
VkSampler vkTextureSampler {}
uint32_t descriptorIndex = std::numeric_limits<uint32_t>::max()
VkFormat format = VK_FORMAT_R8G8B8A8_SRGB
TextureType textureType_ = TextureType::BaseColor
uint32_t mipLevels_ = 1
uint32_t sourceMipLevels_ = 1
uint32_t sourceBaseMip_ = 0
uint32_t sourceWidth_ = 1
uint32_t sourceHeight_ = 1
bool hasPrecomputedMipmaps_ = false
tinygltf::Image imageData
std::optional< Textures::Ktx2TextureDataktx2Data_
Core::ApplicationContextcontext = nullptr

Detailed Description

Runtime-owned Vulkan texture resource.

RuntimeTexture stores decoded image data or prepared KTX2 data, creates the Vulkan image, image view, and sampler, and records upload commands for the renderer. It owns the image and VMA allocation. Samplers are shared through the application sampler cache.

Definition at line 32 of file Texture.h.

Constructor & Destructor Documentation

◆ RuntimeTexture() [1/6]

Engine::Assets::RuntimeTexture::RuntimeTexture ( )
default

Creates an empty texture with no image data or Vulkan resources.

Referenced by operator=(), operator=(), RuntimeTexture(), and RuntimeTexture().

Here is the caller graph for this function:

◆ RuntimeTexture() [2/6]

Engine::Assets::RuntimeTexture::RuntimeTexture ( const tinygltf::Image & imageData,
TextureType type,
Core::ApplicationContext * context )

Construct a texture with explicit type for correct format selection.

This constructor uses the TextureType to determine the correct VkFormat:

  • BaseColor/Emissive use SRGB formats for gamma-correct rendering
  • Normal/MetallicRoughness use LINEAR formats for correct data interpretation
  • Lightmap uses floating-point formats for HDR data
Parameters
imageDataThe image data from tinygltf
typeThe semantic texture type (determines VkFormat)
contextThe application context for Vulkan operations

References context, and imageData.

◆ RuntimeTexture() [3/6]

Engine::Assets::RuntimeTexture::RuntimeTexture ( Textures::Ktx2TextureData ktx2Data,
TextureType type,
Core::ApplicationContext * context )

Construct a texture from KTX2 data with pre-computed mipmaps.

Used for BC6H-compressed lightmaps loaded from KTX2 files. Skips dilation and padding since data is already compressed.

Parameters
ktx2DataThe loaded KTX2 texture data including all mip levels
typeThe semantic texture type
contextThe application context for Vulkan operations

References context.

◆ RuntimeTexture() [4/6]

Engine::Assets::RuntimeTexture::RuntimeTexture ( const tinygltf::Image & imageData,
Core::ApplicationContext * context )

Construct a texture with default type (BaseColor/SRGB)

Deprecated
Use the constructor with explicit TextureType for correct format selection. This constructor defaults to SRGB which is incorrect for normal maps and other linear data textures.

References context, and imageData.

◆ ~RuntimeTexture()

Engine::Assets::RuntimeTexture::~RuntimeTexture ( )
default

Destroys the C++ object without automatically releasing Vulkan resources.

RuntimeTexture resources are released explicitly by AssetManager paths through reset(), discardPreparedResources(), or move assignment cleanup.

◆ RuntimeTexture() [5/6]

Engine::Assets::RuntimeTexture::RuntimeTexture ( const RuntimeTexture & )
delete

Runtime textures are move-only because they own Vulkan handles.

References RuntimeTexture().

Here is the call graph for this function:

◆ RuntimeTexture() [6/6]

Engine::Assets::RuntimeTexture::RuntimeTexture ( RuntimeTexture && other)
noexcept

Move-constructs a texture and transfers Vulkan handles and prepared upload data.

Parameters
otherTexture to move from.

References RuntimeTexture().

Here is the call graph for this function:

Member Function Documentation

◆ addPaddingHelper()

template<typename T>
void Engine::Assets::RuntimeTexture::addPaddingHelper ( )
private

Definition at line 303 of file Texture.h.

References imageData.

◆ addPaddingToImage()

void Engine::Assets::RuntimeTexture::addPaddingToImage ( )
private

◆ calculateMipLevels()

uint32_t Engine::Assets::RuntimeTexture::calculateMipLevels ( uint32_t width,
uint32_t height )
static

Calculates the full mip chain length for a texture size.

Parameters
widthTexture width in pixels.
heightTexture height in pixels.
Returns
Number of mip levels down to 1x1.

◆ cleanup()

void Engine::Assets::RuntimeTexture::cleanup ( ) const
private

◆ createDataUploadCommand()

void Engine::Assets::RuntimeTexture::createDataUploadCommand ( VkCommandBuffer commandBuffer,
Rendering::Renderer * renderer ) const

Records commands that upload prepared image data into the Vulkan texture.

For KTX2 textures this uploads all precomputed mip levels. For regular images this uploads the base level and schedules generated mipmaps when needed.

Parameters
commandBufferCommand buffer to record transfer commands into.
rendererRenderer that owns temporary staging buffer cleanup for the current frame.

◆ createResources()

void Engine::Assets::RuntimeTexture::createResources ( )

Create Vulkan resources (VkImage, VkImageView, VkSampler) for this texture. Safe to call from worker threads when VMA is configured for thread safety.

◆ dilateLightmapImage()

void Engine::Assets::RuntimeTexture::dilateLightmapImage ( )
private

◆ discardPreparedResources()

void Engine::Assets::RuntimeTexture::discardPreparedResources ( )

Destroy Vulkan resources without registering the texture.

Used when async preparation completes after the owning scene has been unloaded.

◆ generateMipmaps()

void Engine::Assets::RuntimeTexture::generateMipmaps ( VkCommandBuffer commandBuffer) const

Generate mipmaps for this texture using vkCmdBlitImage.

Must be called after the base mip level has been uploaded. All mip levels must be in VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL before calling. After calling, mip levels 0..N-2 are in TRANSFER_SRC_OPTIMAL and mip level N-1 is in TRANSFER_DST_OPTIMAL.

Parameters
commandBufferThe graphics command buffer to record blit commands into
Author
Konstantin Passig
Date
2026-02-12

◆ getDescriptorIndex()

uint32_t Engine::Assets::RuntimeTexture::getDescriptorIndex ( ) const
nodiscard

Gets the descriptor array slot assigned by the asset manager.

Returns
Descriptor index, or std::numeric_limits<uint32_t>::max() when unset.

◆ getMipLevels()

uint32_t Engine::Assets::RuntimeTexture::getMipLevels ( ) const
inlinenodiscard

Gets the number of mip levels in the Vulkan image.

Returns
Runtime mip level count.

Definition at line 184 of file Texture.h.

References mipLevels_.

◆ getSourceBaseMip()

uint32_t Engine::Assets::RuntimeTexture::getSourceBaseMip ( ) const
inlinenodiscard

Gets the base mip represented by the source texture data.

Returns
Source base mip index.

Definition at line 202 of file Texture.h.

References sourceBaseMip_.

◆ getSourceHeight()

uint32_t Engine::Assets::RuntimeTexture::getSourceHeight ( ) const
inlinenodiscard

Gets the original source texture height.

Returns
Source height in pixels.

Definition at line 220 of file Texture.h.

References sourceHeight_.

◆ getSourceMipLevels()

uint32_t Engine::Assets::RuntimeTexture::getSourceMipLevels ( ) const
inlinenodiscard

Gets the number of mip levels present in the source texture data.

Returns
Source mip level count.

Definition at line 193 of file Texture.h.

References sourceMipLevels_.

◆ getSourceWidth()

uint32_t Engine::Assets::RuntimeTexture::getSourceWidth ( ) const
inlinenodiscard

Gets the original source texture width.

Returns
Source width in pixels.

Definition at line 211 of file Texture.h.

References sourceWidth_.

◆ getTextureFormat()

VkFormat Engine::Assets::RuntimeTexture::getTextureFormat ( ) const
nodiscard

Gets the Vulkan image format selected for this texture.

Returns
Texture VkFormat.

◆ getTextureType()

TextureType Engine::Assets::RuntimeTexture::getTextureType ( ) const
inlinenodiscard

Get the semantic texture type.

Returns
The TextureType used to determine the VkFormat

Definition at line 175 of file Texture.h.

References textureType_.

◆ getVkImage()

VkImage Engine::Assets::RuntimeTexture::getVkImage ( ) const
nodiscard

Gets the Vulkan image handle.

Returns
Image handle, or VK_NULL_HANDLE when resources have not been created.

◆ getVkImageMemory()

VkDeviceMemory Engine::Assets::RuntimeTexture::getVkImageMemory ( ) const
nodiscard

Gets the device memory backing the VMA image allocation.

Returns
Device memory handle, or VK_NULL_HANDLE when unavailable.

◆ getVkImageSampler()

VkSampler Engine::Assets::RuntimeTexture::getVkImageSampler ( ) const
nodiscard

Gets the sampler used for shader reads.

Returns
Sampler handle from the application sampler cache.

◆ getVkImageView()

VkImageView Engine::Assets::RuntimeTexture::getVkImageView ( ) const
nodiscard

Gets the Vulkan image view used for sampling.

Returns
Image view handle, or VK_NULL_HANDLE when resources have not been created.

◆ hasPrecomputedMipmaps()

bool Engine::Assets::RuntimeTexture::hasPrecomputedMipmaps ( ) const
inlinenodiscard

Checks whether source data already contains mipmaps.

Returns
True for KTX2 textures with precomputed mip levels.

Definition at line 229 of file Texture.h.

References hasPrecomputedMipmaps_.

◆ isDescriptorIndexInitialized()

bool Engine::Assets::RuntimeTexture::isDescriptorIndexInitialized ( ) const
nodiscard

Checks whether this texture has a descriptor array slot.

Returns
True when descriptorIndex has been assigned.

◆ operator=() [1/2]

RuntimeTexture & Engine::Assets::RuntimeTexture::operator= ( const RuntimeTexture & )
delete

Runtime textures are move-only because they own Vulkan handles.

References RuntimeTexture().

Here is the call graph for this function:

◆ operator=() [2/2]

RuntimeTexture & Engine::Assets::RuntimeTexture::operator= ( RuntimeTexture && other)
noexcept

Move-assigns a texture and transfers Vulkan handles and prepared upload data.

Parameters
otherTexture to move from.
Returns
This texture.

References RuntimeTexture().

Here is the call graph for this function:

◆ reset()

void Engine::Assets::RuntimeTexture::reset ( )
private

◆ setDebugName()

void Engine::Assets::RuntimeTexture::setDebugName ( const std::string & debugName) const
private

◆ setupImageFormat()

void Engine::Assets::RuntimeTexture::setupImageFormat ( const tinygltf::Image & imageData)

Selects a Vulkan format from tinygltf image bit depth and component count.

Parameters
imageDataSource image metadata.

References imageData.

Member Data Documentation

◆ context

Core::ApplicationContext* Engine::Assets::RuntimeTexture::context = nullptr
private

Definition at line 299 of file Texture.h.

Referenced by RuntimeTexture(), RuntimeTexture(), and RuntimeTexture().

◆ descriptorIndex

uint32_t Engine::Assets::RuntimeTexture::descriptorIndex = std::numeric_limits<uint32_t>::max()
private

Definition at line 286 of file Texture.h.

◆ format

VkFormat Engine::Assets::RuntimeTexture::format = VK_FORMAT_R8G8B8A8_SRGB
private

Definition at line 288 of file Texture.h.

◆ hasPrecomputedMipmaps_

bool Engine::Assets::RuntimeTexture::hasPrecomputedMipmaps_ = false
private

Definition at line 295 of file Texture.h.

Referenced by hasPrecomputedMipmaps().

◆ imageData

tinygltf::Image Engine::Assets::RuntimeTexture::imageData
private

Definition at line 297 of file Texture.h.

Referenced by addPaddingHelper(), RuntimeTexture(), RuntimeTexture(), and setupImageFormat().

◆ ktx2Data_

std::optional<Textures::Ktx2TextureData> Engine::Assets::RuntimeTexture::ktx2Data_
private

Definition at line 298 of file Texture.h.

◆ mipLevels_

uint32_t Engine::Assets::RuntimeTexture::mipLevels_ = 1
private

Definition at line 290 of file Texture.h.

Referenced by getMipLevels().

◆ sourceBaseMip_

uint32_t Engine::Assets::RuntimeTexture::sourceBaseMip_ = 0
private

Definition at line 292 of file Texture.h.

Referenced by getSourceBaseMip().

◆ sourceHeight_

uint32_t Engine::Assets::RuntimeTexture::sourceHeight_ = 1
private

Definition at line 294 of file Texture.h.

Referenced by getSourceHeight().

◆ sourceMipLevels_

uint32_t Engine::Assets::RuntimeTexture::sourceMipLevels_ = 1
private

Definition at line 291 of file Texture.h.

Referenced by getSourceMipLevels().

◆ sourceWidth_

uint32_t Engine::Assets::RuntimeTexture::sourceWidth_ = 1
private

Definition at line 293 of file Texture.h.

Referenced by getSourceWidth().

◆ textureAllocation_

VmaAllocation Engine::Assets::RuntimeTexture::textureAllocation_ = VK_NULL_HANDLE
private

VMA allocation for texture memory.

Definition at line 282 of file Texture.h.

◆ textureType_

TextureType Engine::Assets::RuntimeTexture::textureType_ = TextureType::BaseColor
private

Definition at line 289 of file Texture.h.

Referenced by getTextureType().

◆ vkTexture

VkImage Engine::Assets::RuntimeTexture::vkTexture {}
private

Definition at line 281 of file Texture.h.

◆ vkTextureSampler

VkSampler Engine::Assets::RuntimeTexture::vkTextureSampler {}
private

Definition at line 284 of file Texture.h.

◆ vkTextureView

VkImageView Engine::Assets::RuntimeTexture::vkTextureView {}
private

Definition at line 283 of file Texture.h.


The documentation for this class was generated from the following file:
  • /home/magerbeton/Documents/gl3-vulkan/Engine/include/Engine/Texture/Texture.h