9#include <vk_mem_alloc.h>
10#include <vulkan/vulkan_core.h>
166 template <
typename T>
180 VkFormat
format = VK_FORMAT_R8G8B8A8_SRGB;
194 template <
typename T>
197 constexpr size_t oldComponents = 3;
198 constexpr size_t newComponents = 4;
199 constexpr size_t oldPixelBytes = oldComponents *
sizeof( T );
200 constexpr size_t newPixelBytes = newComponents *
sizeof( T );
204 std::vector<unsigned char> paddedImage( pixelCount * newPixelBytes );
207 if constexpr ( std::is_floating_point_v<T> )
209 alphaVal =
static_cast<T
>( 1.0 );
213 alphaVal = std::numeric_limits<T>::max();
216 const unsigned char * src =
imageData.image.data();
217 unsigned char * dst = paddedImage.data();
219 for (
size_t i = 0; i < pixelCount; ++i )
221 memcpy( dst, src, oldPixelBytes );
222 memcpy( dst + oldPixelBytes, &alphaVal,
sizeof( T ) );
223 src += oldPixelBytes;
224 dst += newPixelBytes;
227 imageData.image = std::move( paddedImage );
RuntimeTexture(const tinygltf::Image &imageData, TextureType type, Core::ApplicationContext *context)
Construct a texture with explicit type for correct format selection.
RuntimeTexture & operator=(const RuntimeTexture &)=delete
bool hasPrecomputedMipmaps_
VkImageView getVkImageView() const
VkSampler vkTextureSampler
RuntimeTexture(RuntimeTexture &&other) noexcept
static uint32_t calculateMipLevels(uint32_t width, uint32_t height)
~RuntimeTexture()=default
void setDebugName(const std::string &debugName) const
TextureType getTextureType() const
Get the semantic texture type.
uint32_t getSourceWidth() const
bool hasPrecomputedMipmaps() const
void createResources()
Create Vulkan resources (VkImage, VkImageView, VkSampler) for this texture. Safe to call from worker ...
uint32_t getDescriptorIndex() const
VkImage getVkImage() const
uint32_t getSourceBaseMip() const
uint32_t getMipLevels() const
RuntimeTexture(const tinygltf::Image &imageData, Core::ApplicationContext *context)
Construct a texture with default type (BaseColor/SRGB)
RuntimeTexture & operator=(RuntimeTexture &&other) noexcept
VkSampler getVkImageSampler() const
Core::ApplicationContext * context
RuntimeTexture(Textures::Ktx2TextureData ktx2Data, TextureType type, Core::ApplicationContext *context)
Construct a texture from KTX2 data with pre-computed mipmaps.
RuntimeTexture(const RuntimeTexture &)=delete
void dilateLightmapImage()
VkDeviceMemory getVkImageMemory() const
uint32_t getSourceMipLevels() const
VkFormat getTextureFormat() const
uint32_t getSourceHeight() const
VmaAllocation textureAllocation_
VMA allocation for texture memory.
void generateMipmaps(VkCommandBuffer commandBuffer) const
Generate mipmaps for this texture using vkCmdBlitImage.
VkImageView vkTextureView
std::optional< Textures::Ktx2TextureData > ktx2Data_
void setupImageFormat(const tinygltf::Image &imageData)
uint32_t sourceMipLevels_
tinygltf::Image imageData
void createDataUploadCommand(VkCommandBuffer commandBuffer, Rendering::Renderer *renderer) const
bool isDescriptorIndexInitialized() const
void discardPreparedResources()
Destroy Vulkan resources without registering the texture.
The application context is the core class which stores the basic openxr and vulkan objects.
The renderer is the main class for rendering. It owns all data which is used any time in any frame....
TextureType
Represents the semantic type of a texture, determining its Vulkan format.
@ BaseColor
Color data with gamma (SRGB format for 8-bit)
Core audio subsystem owning the miniaudio engine and managing playback.
Stores all data loaded from a KTX2 file including mip chain.