VEX Engine
Retro looking game engine made in vulkan mostly because i wanted to understand it better.
Loading...
Searching...
No Matches
Resources.hpp
Go to the documentation of this file.
1
6
7#pragma once
8#include "uniforms.hpp"
9#include "context.hpp"
10#include "components/ErrorUtils.hpp"
12#include "components/ThreadPool.hpp"
14
15#include <components/Types.hpp>
16#include <string>
17#include <array>
18#include <vector>
19#include <fstream>
20
21namespace vex {
24 public:
30
34
38
42 void updateSceneUBO(const SceneUBO& data);
43
49 void updateLightUBO(uint32_t frameIndex, uint32_t modelIndex, const SceneLightsUBO& data);
50
54
60 void updateTextureDescriptor(uint32_t frameIndex, VkImageView textureView, uint32_t textureIndex);
61
64 const std::string& getDefaultTextureName() const {
65 return defaultTextureName;
66 }
67
71 VkDescriptorSet getUBODescriptorSet(uint32_t frameIndex) const;
72
78 bool loadTexture(const std::string& path, const std::string& name) ;
79
82 void loadTexturesBatched(const std::vector<std::string>& paths);
83
87 void unloadTexture(const std::string& name);
88
92 VkImageView getTextureView(const std::string& name) const;
93
100 void createTextureFromRaw(const std::vector<unsigned char>& rgba, int w, int h, const std::string& name);
101
105 VkDescriptorSet getDescriptorSet(uint32_t frameIndex) const {
106 if (frameIndex >= m_descriptorSets.size()) {
107 log(LogLevel::ERROR,
108 "Invalid frame index %u (Max %zu)",
109 frameIndex, m_descriptorSets.size());
110 return VK_NULL_HANDLE;
111 }
112 return m_descriptorSets[frameIndex];
113 }
114
118 VkDescriptorSet* getDescriptorSetPtr(uint32_t frameIndex) {
119 if (frameIndex >= m_descriptorSets.size()) {
120 log(LogLevel::ERROR,
121 "Invalid frame index %u (Max %zu). Returning nullptr.",
122 frameIndex, m_descriptorSets.size());
123 return nullptr;
124 }
125 return &m_descriptorSets[frameIndex];
126 }
127
132 VkDescriptorSet getTextureDescriptorSet(uint32_t frameIndex, uint32_t textureIndex) const;
133
136 VkDescriptorSetLayout getDescriptorLayout() const { return m_descriptorSetLayout; }
137
141 bool textureExists(const std::string& name) const {
142 return m_textures.find(name) != m_textures.end();
143 }
144
149 uint32_t getTextureIndex(const std::string& name);
150
153 VkSampler getTextureSampler() const { return m_textureSampler; }
154
157 VkDescriptorSet getBindlessDescriptorSet() const { return m_r_context.bindlessDescriptorSet; }
158
161 VkDescriptorSetLayout getBindlessLayout() const { return m_r_context.bindlessDescriptorSetLayout; }
162
166 VkDescriptorSet getParticleDescriptorSet(uint32_t frameIndex) const {
167 if (frameIndex >= m_particleDescriptorSets.size()) {
168 log(LogLevel::ERROR,
169 "Invalid frame index %u for particle descriptor set (Max %zu)",
170 frameIndex, m_particleDescriptorSets.size());
171 return VK_NULL_HANDLE;
172 }
173 return m_particleDescriptorSets[frameIndex];
174 }
175
179 void* getParticleMappedData(uint32_t frameIndex) const {
180 if (frameIndex >= m_particleMappedData.size()) {
181 log(LogLevel::ERROR,
182 "Invalid frame index %u for particle mapped data (Max %zu)",
183 frameIndex, m_particleMappedData.size());
184 return nullptr;
185 }
186 return m_particleMappedData[frameIndex];
187 }
188
194 void createColorLUT();
195 private:
196 const std::string defaultTextureName = "default";
197
198 VulkanContext& m_r_context;
199 VirtualFileSystem* m_vfs;
200
201 std::vector<VkBuffer> m_sceneBuffers;
202 std::vector<VkBuffer> m_lightBuffers;
203 std::vector<VmaAllocation> m_sceneAllocs;
204 std::vector<VmaAllocation> m_lightAllocs;
205
206 std::vector<VkBuffer> m_particleSSBOs;
207 std::vector<VmaAllocation> m_particleAllocs;
208 std::vector<void*> m_particleMappedData;
209 VkDescriptorPool m_particleDescriptorPool = VK_NULL_HANDLE;
210 std::vector<VkDescriptorSet> m_particleDescriptorSets;
211
212 VkDescriptorSetLayout m_descriptorSetLayout;
213 std::vector<VkDescriptorSet> m_descriptorSets;
214 VkDescriptorPool m_descriptorPool;
215 std::vector<VkDescriptorSet> m_textureDescriptorSets;
216
217 vex_map<std::string, VkImageView> m_textures;
218 VkSampler m_textureSampler;
219
220 vex_map<std::string, VkImage> m_textureImages;
221 vex_map<std::string, VmaAllocation> m_textureAllocations;
222 vex_map<std::string, VkImageView> m_textureViews;
223
224 std::vector<std::string> m_ignoredTexturePaths;
225
233 void createParticleSSBOs();
234 };
235}
Particle emitter component.
This file defines VirtualFileSystem and VPKStream classes.
This class provides abstraction of file system needed for loading packed and unpacked assets.
void * getParticleMappedData(uint32_t frameIndex) const
Returns the mapped data for the particle SSBO for the given frame index.
VkDescriptorSet getUBODescriptorSet(uint32_t frameIndex) const
Returns the uniform buffer descriptor set for the given frame index.
void createPerMeshTextureSets()
Internal function to create per-mesh texture sets.
const std::string & getDefaultTextureName() const
Returns the default texture name.
Definition Resources.hpp:64
VkDescriptorSetLayout getBindlessLayout() const
Returns the bindless descriptor set layout.
void updateSceneUBO(const SceneUBO &data)
Updates the scene uniform buffer.
bool loadTexture(const std::string &path, const std::string &name)
Loads a texture from a file.
void createTextureSampler()
Internal function to create texture sampler.
uint32_t getTextureIndex(const std::string &name)
Returns the index of a texture with the given name.
VulkanResources(VulkanContext &context, VirtualFileSystem *vfs)
Simple constructor.
Definition Resources.cpp:27
void updateTextureDescriptor(uint32_t frameIndex, VkImageView textureView, uint32_t textureIndex)
Updates the texture descriptor.
void unloadTexture(const std::string &name)
Unloads a texture.
VkDescriptorSetLayout getDescriptorLayout() const
Returns a descriptor set layout.
~VulkanResources()
Simple destructor.
Definition Resources.cpp:36
VkDescriptorSet getParticleDescriptorSet(uint32_t frameIndex) const
Returns the particle descriptor set for the given frame index.
VkDescriptorSet getBindlessDescriptorSet() const
Returns the bindless descriptor set.
void createParticleSSBOs()
Internal function to create particle SSBOs.
bool textureExists(const std::string &name) const
Returns if a texture with the given name exists.
void updateLightUBO(uint32_t frameIndex, uint32_t modelIndex, const SceneLightsUBO &data)
Updates the light uniform buffer for a specific model.
VkDescriptorSet getTextureDescriptorSet(uint32_t frameIndex, uint32_t textureIndex) const
Returns a descriptor set for the given frame index and texture index.
void createDefaultTexture()
Creates a default texture.
VkDescriptorSet getDescriptorSet(uint32_t frameIndex) const
Returns the descriptor set for the given frame index.
void loadTexturesBatched(const std::vector< std::string > &paths)
Loads multiple textures in batches.
void createTextureFromRaw(const std::vector< unsigned char > &rgba, int w, int h, const std::string &name)
Creates a texture from raw data.
VkDescriptorSet * getDescriptorSetPtr(uint32_t frameIndex)
Returns a pointer to the descriptor set for the given frame index.
VkSampler getTextureSampler() const
Returns the texture sampler.
void createDescriptorResources()
Internal function to create descriptor resources.
void createUniformBuffers()
Creates uniform buffers.
void createColorLUT()
Generates and uploads a 32x32x32 3D Lookup Texture (LUT) to the GPU. Bakes PS1 5-bit color quantizati...
VkImageView getTextureView(const std::string &name) const
Returns the texture view for the given texture name.
This file defines struct holding all vulkan data, like device, surface, swapchain,...
void VEX_EXPORT log(const char *fmt,...)
Logs a formatted message.
Scene lights uniform buffer object.
Definition uniforms.hpp:47
Scene uniform buffer object. Holds data that is bind once per scene.
Definition uniforms.hpp:13
Struct holding all vulkan data, like device, surface, swapchain, images, views, and more.
Definition context.hpp:26
Represents an RGBA color value. Used mainly for fancy rendering in editor.
This file defines uniforms and pushconstant for rendering meshes.