74 if (!data.has_value())
89 std::vector<const Mesh *> allMeshes(
meshAllocator.getUsedIndices().size());
91 for (
const std::optional<Mesh> &mesh:
meshData) {
92 if (!mesh.has_value())
continue;
93 allMeshes[i] = &mesh.value();
100 uint32_t primCount = 0u;
102 primCount += mesh->getPrimitives().size();
112 PLOGI <<
"Loaded Mesh count: " <<
meshes.size();
113 PLOGI <<
"Loaded Texture count: " <<
textures.size();
120 for (std::optional<Mesh> &mesh:
meshData) {
121 if (!mesh.has_value())
continue;
123 sum += mesh.value().getMeshletCount();
133 if (mesh.has_value()) {
139 if (texture.has_value()) {
152 std::vector<VkDescriptorImageInfo> descriptorTextures;
154 if (!texture.has_value())
continue;
155 VkDescriptorImageInfo descriptorImageInfo;
156 descriptorImageInfo.sampler = texture.value().getVkImageSampler();
157 descriptorImageInfo.imageView = texture.value().getVkImageView();
158 descriptorImageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
159 descriptorTextures.push_back(descriptorImageInfo);
161 return descriptorTextures;
213 if (
const auto it = std::ranges::find(
shaders, shader); it !=
shaders.end()) {
225 const std::vector<const Mesh *> &
meshes)
const {
226 std::vector<const MeshPrimitive *> allPrimitives;
230 for (
const MeshPrimitive &primitive: mesh->getPrimitivesByReference()) {
232 allPrimitives.push_back(&primitive);
235 return allPrimitives;
239 std::vector<MeshPrimitive *> allPrimitives;
243 for (
MeshPrimitive &primitive: mesh->getPrimitivesByReference()) {
245 allPrimitives.push_back(&primitive);
248 return allPrimitives;
252 uint32_t meshletCount = 0;
253 uint32_t primitiveCount = 0;
255 for (
const MeshPrimitive &primitive: mesh->getPrimitivesByReference()) {
256 uint32_t primMeshletCount = primitive.getMeshletsCount();
257 meshletCount += primMeshletCount;
259 if (primMeshletCount == 0) {
260 PLOGW <<
"Primitive " << primitiveCount <<
" has 0 meshlets!";
264 PLOGI <<
"Total meshlet count: " << meshletCount <<
" from " << primitiveCount <<
" primitives";
297 const auto it =
textures.find(path.generic_string());
298 if (it !=
textures.end() && it->second && it->second->isDescriptorIndexInitialized()) {
299 return it->second->getDescriptorIndex();
306 if (
textures.contains(path.generic_string())) {
307 return textures.find(path.generic_string())->second;
314 textureData[freeTextureIndex] = std::move(texture);
317 textures[path.generic_string()] = texturePtr;
322 renderer->getRenderingDataManager()->queueTextureForUpload(texturePtr);
325 PLOGI <<
"Texture " << path.generic_string() <<
" created.";
326 return textures[path.generic_string()];
330 uint32_t textureIndex = std::numeric_limits<uint32_t>::max();
332 for (
const auto &[path, texturePtr]:
textures) {
333 if (texturePtr == texture) {
334 textureIndex = texturePtr->descriptorIndex;
346 uint32_t meshIndex = std::numeric_limits<uint32_t>::max();
350 const auto it =
meshes.find(meshName);
358 meshData[freeMeshIndex].value().descriptorIndex = freeMeshIndex;
360 meshes[meshName] = meshPtr;
362 meshIndex = freeMeshIndex;
365 meshData[meshIndex]->createResources();
372 uint32_t meshIndex = std::numeric_limits<uint32_t>::max();
375 for (
const auto &entry:
meshes) {
376 if (entry.second == mesh) {
377 meshIndex = entry.second->descriptorIndex;
constexpr uint32_t MAX_MESH_COUNT
constexpr uint32_t MAX_TEXTURE_COUNT
#define TRACY_LOCK_GUARD(type, varname, var)
#define TRACY_ZONE_SCOPED_NAMED(name)
The model asset pipeline loads a gltf scene and loads and loads the mesh and material data....
Infrastructure to load images into the ecs.
NamedThreadPool * threadedCalculation
uint32_t getMeshletCount(const std::vector< const Mesh * > &meshes) const
uint32_t getMeshOffset(Mesh *mesh) const
std::unordered_map< MaterialShader *, uint32_t > shaderOffsets
MaterialShader * registerShader(MaterialShader shader, const PipelineNames &materialName)
BidirectionalMap< uint32_t, Mesh * > meshIndexMap
Ecs::ModelAssetPipeline & getMeshAssetPipeline()
uint32_t getTextureDescriptorIndex(const std::filesystem::path &path)
Gets the descriptor index of a loaded texture by path.
DescriptorIndexAllocator textureAllocator
std::vector< MaterialShader * > shaders
std::unordered_map< PipelineNames, VulkanBuffer > materialStorageBuffers
void unregisterMesh(Mesh *mesh)
BidirectionalMap< uint32_t, Texture * > textureIndexMap
MeshAsset * getMeshAsset(const Asset::Path &asset)
Get a mesh from the asset manager. If it does not exist it requests the asset from the asset loader.
DescriptorIndexAllocator shaderAllocator
DescriptorIndexAllocator meshAllocator
void unregisterTexture(Texture *texture)
friend RenderingDataManager
std::unordered_map< PipelineNames, MaterialShader * > shadersByName
ApplicationContext * context
std::unordered_map< std::filesystem::path, Texture *, PathHasher > textures
void unregisterShader(MaterialShader *shader)
MeshAssetManager * meshAssetManager
MaterialShader * getShaderByName(const std::string &shaderName)
Ecs::TextureAssetPipeline texturePipeline
VulkanBuffer & getMaterialStorageBufferByName(PipelineNames name)
std::unordered_map< Mesh *, uint32_t > meshOffsets
bool doesTextureAlreadyExist(const std::filesystem::path &path)
Checks if a texture has already been loaded.
TextureAssetManager * textureAssetManager
NamedThreadPool * threadPool
std::vector< const Mesh * > getAllMeshes() const
Gets a copy of all meshes which are currently loaded in the asset manager.
std::vector< Texture * > texturesToCopyImageData
std::array< std::optional< Mesh >, MAX_MESH_COUNT > meshData
uint32_t getTotalPrimitiveCount() const
Mesh * registerMesh(const std::filesystem::path &path, GltfLoader::GltfMeshData &gltfMeshData)
void setRenderingDataManager(RenderingDataManager *renderingDataManager)
Sets the RenderingDataManager on asset pipelines for hook notifications.
void attachToRenderer(Renderer *renderer)
Sets what renderer the render process belongs to.
std::vector< const MeshPrimitive * > getMeshPrimitivesFromMeshes(const std::vector< const Mesh * > &meshes) const
PipelineNames materialNameFromString(const std::string &string)
uint32_t getImageCount() const
Ecs::ModelAssetPipeline modelAssetPipeline
MaterialAssetManager * materialAssetManager
std::unordered_map< std::filesystem::path, Mesh *, PathHasher > meshes
friend ApplicationContext
ModelAssetManager * modelAssetManager
std::array< std::optional< MaterialShader >, 100 > shaderData
Ecs::TextureAssetPipeline & getTextureAssetPipeline()
void loadEcsModel(const std::filesystem::path &path)
Submits a gltf model for loading. You provide the path of the model to load. This can include 3D data...
void unloadAllData() const
std::vector< VkDescriptorImageInfo > getTextureDescriptorInfos() const
void logAllLoadedAssets() const
void loadEcsTexture(const std::filesystem::path &path)
Loads a texture (.png / .jpg / .exr)
uint32_t getShaderCount() const
std::vector< MaterialShader * > getShaders() const
std::vector< Texture * > getTexturesToUpload()
Texture * registerTexture(const std::filesystem::path &path, Texture texture)
Registers a texture with the texture manager which prevents the same texture from being loaded twice.
std::array< std::optional< Texture >, MAX_TEXTURE_COUNT > textureData
bool doesMeshAlreadyExist(const std::filesystem::path &meshPath) const
Checks if a mesh is already present in the loaded meshes in RAM.
Stores mesh data with their primitives.
The mesh asset stores geometry data and.
static std::string createMeshName(const std::filesystem::path &path, const std::string &meshName)
The model asset is used to bind together all files of one gtlf model. The idea is that textures,...
RAII wrapper for Vulkan buffer and device memory.
Log category system implementation.
T UnpackOptional(std::optional< T > var)
std::filesystem::path getFilePath() const
std::string getName() const