This class manages resources like textures, descriptor sets, and uniform buffers. More...
#include <Resources.hpp>
Public Member Functions | |
| VulkanResources (VulkanContext &context, VirtualFileSystem *vfs) | |
| Simple constructor. | |
| ~VulkanResources () | |
| Simple destructor. | |
| void | createUniformBuffers () |
| Creates uniform buffers. | |
| void | updateSceneUBO (const SceneUBO &data) |
| Updates the scene uniform buffer. | |
| void | updateLightUBO (uint32_t frameIndex, uint32_t modelIndex, const SceneLightsUBO &data) |
| Updates the light uniform buffer for a specific model. | |
| void | createDefaultTexture () |
| Creates a default texture. | |
| void | updateTextureDescriptor (uint32_t frameIndex, VkImageView textureView, uint32_t textureIndex) |
| Updates the texture descriptor. | |
| const std::string & | getDefaultTextureName () const |
| Returns the default texture name. | |
| VkDescriptorSet | getUBODescriptorSet (uint32_t frameIndex) const |
| Returns the uniform buffer descriptor set for the given frame index. | |
| bool | loadTexture (const std::string &path, const std::string &name) |
| Loads a texture from a file. | |
| void | loadTexturesBatched (const std::vector< std::string > &paths) |
| Loads multiple textures in batches. | |
| void | unloadTexture (const std::string &name) |
| Unloads a texture. | |
| VkImageView | getTextureView (const std::string &name) const |
| Returns the texture view for the given texture name. | |
| void | createTextureFromRaw (const std::vector< unsigned char > &rgba, int w, int h, const std::string &name) |
| Creates a texture from raw data. | |
| VkDescriptorSet | getDescriptorSet (uint32_t frameIndex) const |
| Returns the descriptor set for the given frame index. | |
| VkDescriptorSet * | getDescriptorSetPtr (uint32_t frameIndex) |
| Returns a pointer to the descriptor set for the given frame index. | |
| VkDescriptorSet | getTextureDescriptorSet (uint32_t frameIndex, uint32_t textureIndex) const |
| Returns a descriptor set for the given frame index and texture index. | |
| VkDescriptorSetLayout | getDescriptorLayout () const |
| Returns a descriptor set layout. | |
| bool | textureExists (const std::string &name) const |
| Returns if a texture with the given name exists. | |
| uint32_t | getTextureIndex (const std::string &name) |
| Returns the index of a texture with the given name. | |
| VkSampler | getTextureSampler () const |
| Returns the texture sampler. | |
| VkDescriptorSet | getBindlessDescriptorSet () const |
| Returns the bindless descriptor set. | |
| VkDescriptorSetLayout | getBindlessLayout () const |
| Returns the bindless descriptor set layout. | |
| VkDescriptorSet | getParticleDescriptorSet (uint32_t frameIndex) const |
| Returns the particle descriptor set for the given frame index. | |
| void * | getParticleMappedData (uint32_t frameIndex) const |
| Returns the mapped data for the particle SSBO for the given frame index. | |
| void | createColorLUT () |
| Generates and uploads a 32x32x32 3D Lookup Texture (LUT) to the GPU. Bakes PS1 5-bit color quantization, saturation, and brightness boost into a 3D texture. The data is transferred via a staging buffer to a VK_IMAGE_TYPE_3D image stored in the VulkanContext. This allows the composite shader to replace heavy color math with a single hardware-accelerated trilinear texture fetch. | |
Private Member Functions | |
| void | createDescriptorResources () |
| Internal function to create descriptor resources. | |
| void | createTextureSampler () |
| Internal function to create texture sampler. | |
| void | createPerMeshTextureSets () |
| Internal function to create per-mesh texture sets. | |
| void | createParticleSSBOs () |
| Internal function to create particle SSBOs. | |
Private Attributes | |
| const std::string | defaultTextureName = "default" |
| VulkanContext & | m_r_context |
| VirtualFileSystem * | m_vfs |
| std::vector< VkBuffer > | m_sceneBuffers |
| std::vector< VkBuffer > | m_lightBuffers |
| std::vector< VmaAllocation > | m_sceneAllocs |
| std::vector< VmaAllocation > | m_lightAllocs |
| std::vector< VkBuffer > | m_particleSSBOs |
| std::vector< VmaAllocation > | m_particleAllocs |
| std::vector< void * > | m_particleMappedData |
| VkDescriptorPool | m_particleDescriptorPool = VK_NULL_HANDLE |
| std::vector< VkDescriptorSet > | m_particleDescriptorSets |
| VkDescriptorSetLayout | m_descriptorSetLayout |
| std::vector< VkDescriptorSet > | m_descriptorSets |
| VkDescriptorPool | m_descriptorPool |
| std::vector< VkDescriptorSet > | m_textureDescriptorSets |
| vex_map< std::string, VkImageView > | m_textures |
| VkSampler | m_textureSampler |
| vex_map< std::string, VkImage > | m_textureImages |
| vex_map< std::string, VmaAllocation > | m_textureAllocations |
| vex_map< std::string, VkImageView > | m_textureViews |
| std::vector< std::string > | m_ignoredTexturePaths |
This class manages resources like textures, descriptor sets, and uniform buffers.
Definition at line 23 of file Resources.hpp.
| vex::VulkanResources::VulkanResources | ( | VulkanContext & | context, |
| VirtualFileSystem * | vfs ) |
Simple constructor.
Initializes the resource manager: creates default textures, samplers, UBOs, and descriptor pools.
| VulkanContext& | context - The Vulkan context to use. |
| VirtualFileSystem* | vfs - VFS for loading texture files. |
Definition at line 27 of file Resources.cpp.
| vex::VulkanResources::~VulkanResources | ( | ) |
Simple destructor.
Destroys all textures, buffers, samplers, and descriptor pools.
Definition at line 36 of file Resources.cpp.
| void vex::VulkanResources::createColorLUT | ( | ) |
Generates and uploads a 32x32x32 3D Lookup Texture (LUT) to the GPU. Bakes PS1 5-bit color quantization, saturation, and brightness boost into a 3D texture. The data is transferred via a staging buffer to a VK_IMAGE_TYPE_3D image stored in the VulkanContext. This allows the composite shader to replace heavy color math with a single hardware-accelerated trilinear texture fetch.
Definition at line 125 of file Resources.cpp.
| void vex::VulkanResources::createDefaultTexture | ( | ) |
Creates a default texture.
Generates a 1x1 white pixel texture, transitions it to SHADER_READ_ONLY, and assigns it to the "default" key.
Definition at line 802 of file Resources.cpp.
|
private |
Internal function to create descriptor resources.
Definition at line 525 of file Resources.cpp.
|
private |
Internal function to create particle SSBOs.
Definition at line 456 of file Resources.cpp.
|
private |
Internal function to create per-mesh texture sets.
Definition at line 882 of file Resources.cpp.
| void vex::VulkanResources::createTextureFromRaw | ( | const std::vector< unsigned char > & | rgba, |
| int | w, | ||
| int | h, | ||
| const std::string & | name ) |
Creates a texture from raw data.
Creates a GPU texture from a vector of bytes (RGBA). Useful for generated content like UI fonts.
| const | std::vector<unsigned char>& rgba - Raw pixel data. |
| int | w - Width. |
| int | h - Height. |
| const | std::string& name - Identifier. |
Definition at line 271 of file Resources.cpp.
|
private |
Internal function to create texture sampler.
Definition at line 937 of file Resources.cpp.
| void vex::VulkanResources::createUniformBuffers | ( | ) |
Creates uniform buffers.
Allocates Scene and Light UBOs for each frame in flight using VMA.
Definition at line 431 of file Resources.cpp.
|
inline |
Returns the bindless descriptor set.
Definition at line 157 of file Resources.hpp.
|
inline |
Returns the bindless descriptor set layout.
Definition at line 161 of file Resources.hpp.
|
inline |
|
inline |
Returns a descriptor set layout.
Definition at line 136 of file Resources.hpp.
|
inline |
Returns the descriptor set for the given frame index.
| uint32_t | frameIndex - The index of the frame. |
Definition at line 105 of file Resources.hpp.
|
inline |
Returns a pointer to the descriptor set for the given frame index.
| uint32_t | frameIndex - The index of the frame. |
Definition at line 118 of file Resources.hpp.
|
inline |
Returns the particle descriptor set for the given frame index.
| frameIndex | - The frame index. |
Definition at line 166 of file Resources.hpp.
|
inline |
Returns the mapped data for the particle SSBO for the given frame index.
| frameIndex | - The frame index. |
Definition at line 179 of file Resources.hpp.
| VkDescriptorSet vex::VulkanResources::getTextureDescriptorSet | ( | uint32_t | frameIndex, |
| uint32_t | textureIndex ) const |
Returns a descriptor set for the given frame index and texture index.
| uint32_t | frameIndex - Frame index. |
| uint32_t | textureIndex - Texture slot index. |
Definition at line 926 of file Resources.cpp.
| uint32_t vex::VulkanResources::getTextureIndex | ( | const std::string & | name | ) |
Returns the index of a texture with the given name.
If the texture isn't loaded, attempts to load it from disk using the name as the path.
| const | std::string& name - Texture path/name. |
Definition at line 957 of file Resources.cpp.
|
inline |
Returns the texture sampler.
Definition at line 153 of file Resources.hpp.
| VkImageView vex::VulkanResources::getTextureView | ( | const std::string & | name | ) | const |
Returns the texture view for the given texture name.
| const | std::string& name - The texture identifier. |
Definition at line 1425 of file Resources.cpp.
| VkDescriptorSet vex::VulkanResources::getUBODescriptorSet | ( | uint32_t | frameIndex | ) | const |
Returns the uniform buffer descriptor set for the given frame index.
| uint32_t | frameIndex - The frame index. |
Definition at line 705 of file Resources.cpp.
| bool vex::VulkanResources::loadTexture | ( | const std::string & | path, |
| const std::string & | name ) |
Loads a texture from a file.
Uses stbi_load_from_memory via VFS. Creates Vulkan Image, View, and uploads data via staging buffer. Recycles texture indices if available.
| const | std::string& path - File path. |
| const | std::string& name - Unique identifier key. |
Definition at line 971 of file Resources.cpp.
| void vex::VulkanResources::loadTexturesBatched | ( | const std::vector< std::string > & | paths | ) |
Loads multiple textures in batches.
| const | std::vector<std::string>& paths - List of file paths to load. |
Definition at line 1204 of file Resources.cpp.
|
inline |
Returns if a texture with the given name exists.
| const | std::string& name - The name of the texture. |
Definition at line 141 of file Resources.hpp.
| void vex::VulkanResources::unloadTexture | ( | const std::string & | name | ) |
Unloads a texture.
Destroys the image/view and pushes the index to the recycled queue. Resets descriptors to the default texture.
| const | std::string& name - Identifier of the texture to unload. |
Definition at line 1359 of file Resources.cpp.
| void vex::VulkanResources::updateLightUBO | ( | uint32_t | frameIndex, |
| uint32_t | modelIndex, | ||
| const SceneLightsUBO & | data ) |
Updates the light uniform buffer for a specific model.
Updates the dynamic UBO section corresponding to a specific model index.
| uint32_t | frameIndex - Current frame. |
| uint32_t | modelIndex - Index of the model to update lights for. |
| const | SceneLightsUBO& data - Light data. |
Definition at line 773 of file Resources.cpp.
| void vex::VulkanResources::updateSceneUBO | ( | const SceneUBO & | data | ) |
Updates the scene uniform buffer.
Maps memory and copies the SceneUBO struct (camera, lighting, time data) to the GPU.
| const | SceneUBO& data - The data to update. |
Definition at line 752 of file Resources.cpp.
| void vex::VulkanResources::updateTextureDescriptor | ( | uint32_t | frameIndex, |
| VkImageView | textureView, | ||
| uint32_t | textureIndex ) |
Updates the texture descriptor.
Updates the global descriptor set (or Bindless set) to point to the new texture view.
| uint32_t | frameIndex - Frame index. |
| VkImageView | textureView - The new view. |
| uint32_t | textureIndex - The slot index to update. |
Definition at line 710 of file Resources.cpp.
|
private |
Definition at line 196 of file Resources.hpp.
|
private |
Definition at line 214 of file Resources.hpp.
|
private |
Definition at line 212 of file Resources.hpp.
|
private |
Definition at line 213 of file Resources.hpp.
|
private |
Definition at line 224 of file Resources.hpp.
|
private |
Definition at line 204 of file Resources.hpp.
|
private |
Definition at line 202 of file Resources.hpp.
|
private |
Definition at line 207 of file Resources.hpp.
|
private |
Definition at line 209 of file Resources.hpp.
|
private |
Definition at line 210 of file Resources.hpp.
|
private |
Definition at line 208 of file Resources.hpp.
|
private |
Definition at line 206 of file Resources.hpp.
|
private |
Definition at line 198 of file Resources.hpp.
|
private |
Definition at line 203 of file Resources.hpp.
|
private |
Definition at line 201 of file Resources.hpp.
|
private |
Definition at line 221 of file Resources.hpp.
|
private |
Definition at line 215 of file Resources.hpp.
|
private |
Definition at line 220 of file Resources.hpp.
|
private |
Definition at line 217 of file Resources.hpp.
|
private |
Definition at line 218 of file Resources.hpp.
|
private |
Definition at line 222 of file Resources.hpp.
|
private |
Definition at line 199 of file Resources.hpp.