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

#include <AssetManager.h>

Collaboration diagram for Engine::Core::AssetManager:

Public Types

using AudioAssetRef = Assets::AudioAssetRef
using MaterialAssetRef = Assets::MaterialAssetRef
using MeshAssetRef = Assets::MeshAssetRef
using TextureAssetRef = Assets::TextureAssetRef

Public Member Functions

template<typename AssetClass, typename Key>
auto getAsset (const Key &asset)
 AssetManager ()
 AssetManager (ApplicationContext *context)
 ~AssetManager ()
void attachToRenderer (Rendering::Renderer *renderer)
 Sets what renderer the render process belongs to.
void setRenderingDataManager (RenderingDataManager *renderingDataManager)
 Sets the RenderingDataManager on asset pipelines for hook notifications.
Assets::CubemapTextureloadEcsCubemap (const std::filesystem::path &path)
 Loads a six-face cubemap asset from a directory.
uint32_t getTextureDescriptorIndex (const std::filesystem::path &path)
 Gets the descriptor index of a loaded texture by path.
uint32_t getImageCount () const
void cleanup ()
std::vector< VkDescriptorImageInfo > getTextureDescriptorInfos () const
Ecs::TextureAssetPipelinegetTextureAssetPipeline ()
Ecs::ModelAssetPipelinegetMeshAssetPipeline ()
Ecs::AudioAssetPipelinegetAudioAssetPipeline ()
void unloadAllData ()
void discardSceneLoadingData ()
 Drops any queued or in-flight scene asset loading work.
AudioAssetRef loadAudioAsset (const std::filesystem::path &path)
 Submit an audio file for async loading through the pipeline.
Assets::AudiogetAudioAsset (const std::filesystem::path &path)
 Get a loaded audio asset by path.
Assets::AudioAssetManagergetAudioAssetManager () const
 Gets the audio asset manager for direct access.
Assets::MaterialAssetManagergetMaterialAssetManager () const
 Gets the material asset manager for material lookups.
Assets::ModelAssetManager * getModelAssetManager () const
 Gets the model asset manager for model/GLTF file loading state lookups.
Assets::MeshAssetManagergetMeshAssetManager () const
 Gets the mesh asset manager for mesh asset lookups.
Assets::Textures::TextureHandleRegistrygetTextureHandleRegistry ()
 Gets the texture handle registry for O(1) descriptor index lookups.
NamedThreadPoolgetCalculationPool () const
NamedThreadPoolgetAssetLoaderPool () const

Private Member Functions

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, materials and textures.
void loadEcsTexture (const std::filesystem::path &path)
 Loads a texture (.png / .jpg / .exr)
Assets::MeshgetMeshAsset (const Asset::Path &asset)
 Get a mesh asset by path. If not loaded, requests its model and returns nullptr.
bool doesTextureAlreadyExist (const std::filesystem::path &path)
 Checks if a texture has already been loaded.
Assets::RuntimeTextureregisterTexture (const std::filesystem::path &path, Assets::RuntimeTexture texture)
 Registers a texture with the texture manager which prevents the same texture from being loaded twice.
Assets::RuntimeTextureregisterTextureFromPrepared (const std::filesystem::path &path, Assets::RuntimeTexture texture)
 Register a texture whose Vulkan resources are already created. Skips createResources() — only allocates a descriptor index and queues for GPU upload. Used by the async texture preparation pipeline.
Assets::RuntimeTexturereplaceTextureFromPrepared (const std::filesystem::path &path, Assets::RuntimeTexture texture)
 Replace an already registered texture while preserving its descriptor index.
void unregisterTexture (Assets::RuntimeTexture *texture)
void unloadRuntimeTextures ()

Private Attributes

friend ApplicationContext
friend RenderingDataManager
NamedThreadPoolthreadPool_ = new NamedThreadPool( 2, "Asset Loader" )
NamedThreadPoolthreadedCalculation_ = new NamedThreadPool( 2, "Bounding Sphere" )
Assets::TextureAssetManagertextureAssetManager
Ecs::TextureAssetPipeline texturePipeline
Assets::MeshAssetManagermeshAssetManager
Assets::MaterialAssetManagermaterialAssetManager
Assets::ModelAssetManager * modelAssetManager
Assets::Textures::TextureHandleRegistry textureHandleRegistry_
 Registry for type-safe texture handles.
Ecs::ModelAssetPipeline modelAssetPipeline
Assets::AudioAssetManageraudioAssetManager_
Ecs::AudioAssetPipeline audioAssetPipeline_
Assets::Loaders::GltfLoader gltfLoader = Assets::Loaders::GltfLoader( threadPool_ )
ApplicationContextcontext = nullptr
Rendering::Rendererrenderer = nullptr
std::unordered_map< std::filesystem::path, Assets::RuntimeTexture *, PathHashertextures = {}
std::unordered_map< std::filesystem::path, std::unique_ptr< Assets::CubemapTexture >, PathHashercubemapTextures = {}
BidirectionalMap< uint32_t, Assets::RuntimeTexture * > textureIndexMap
std::array< std::optional< Assets::RuntimeTexture >, MAX_TEXTURE_COUNTtextureData
DescriptorIndexAllocator textureAllocator
std::mutex textureMutex
std::vector< TextureStoragetexturesToUpload {}
std::vector< Assets::RuntimeTexture * > texturesToCopyImageData

Detailed Description

Definition at line 133 of file AssetManager.h.

Member Typedef Documentation

◆ AudioAssetRef

◆ MaterialAssetRef

◆ MeshAssetRef

◆ TextureAssetRef

Constructor & Destructor Documentation

◆ AssetManager() [1/2]

Engine::Core::AssetManager::AssetManager ( )

◆ AssetManager() [2/2]

Engine::Core::AssetManager::AssetManager ( ApplicationContext * context)

References ApplicationContext, and context.

◆ ~AssetManager()

Engine::Core::AssetManager::~AssetManager ( )

Member Function Documentation

◆ attachToRenderer()

void Engine::Core::AssetManager::attachToRenderer ( Rendering::Renderer * renderer)

Sets what renderer the render process belongs to.

Parameters
rendererWhere the render process belongs to

References renderer.

◆ cleanup()

void Engine::Core::AssetManager::cleanup ( )

◆ discardSceneLoadingData()

void Engine::Core::AssetManager::discardSceneLoadingData ( )

Drops any queued or in-flight scene asset loading work.

◆ doesTextureAlreadyExist()

bool Engine::Core::AssetManager::doesTextureAlreadyExist ( const std::filesystem::path & path)
private

Checks if a texture has already been loaded.

Parameters
paththe path of the texture on disk
Returns
if the texture has been found in the loaded data

◆ getAsset()

template<typename AssetClass, typename Key>
auto Engine::Core::AssetManager::getAsset ( const Key & asset)
inlinenodiscard

Definition at line 146 of file AssetManager.h.

References getMeshAsset(), loadAudioAsset(), loadEcsTexture(), Asset::LOADED, Asset::LOADING, materialAssetManager, meshAssetManager, Asset::REQUESTED_LOAD, and textureAssetManager.

Here is the call graph for this function:

◆ getAssetLoaderPool()

NamedThreadPool * Engine::Core::AssetManager::getAssetLoaderPool ( ) const
inline

Definition at line 357 of file AssetManager.h.

References threadPool_.

◆ getAudioAsset()

Assets::Audio * Engine::Core::AssetManager::getAudioAsset ( const std::filesystem::path & path)
nodiscard

Get a loaded audio asset by path.

Parameters
pathThe path used when loading
Returns
Pointer to the audio asset, or nullptr if not loaded

◆ getAudioAssetManager()

Assets::AudioAssetManager * Engine::Core::AssetManager::getAudioAssetManager ( ) const
inlinenodiscard

Gets the audio asset manager for direct access.

Returns
Pointer to the AudioAssetManager

Definition at line 283 of file AssetManager.h.

References audioAssetManager_.

◆ getAudioAssetPipeline()

Ecs::AudioAssetPipeline & Engine::Core::AssetManager::getAudioAssetPipeline ( )

◆ getCalculationPool()

NamedThreadPool * Engine::Core::AssetManager::getCalculationPool ( ) const
inline

Definition at line 352 of file AssetManager.h.

References threadedCalculation_.

◆ getImageCount()

uint32_t Engine::Core::AssetManager::getImageCount ( ) const

◆ getMaterialAssetManager()

Assets::MaterialAssetManager * Engine::Core::AssetManager::getMaterialAssetManager ( ) const
inlinenodiscard

Gets the material asset manager for material lookups.

Returns
Pointer to the material asset manager

Definition at line 299 of file AssetManager.h.

References materialAssetManager.

◆ getMeshAsset()

Assets::Mesh * Engine::Core::AssetManager::getMeshAsset ( const Asset::Path & asset)
nodiscardprivate

Get a mesh asset by path. If not loaded, requests its model and returns nullptr.

Parameters
assetPath to the mesh asset
Returns
Pointer to the mesh asset, or nullptr if not loaded

Referenced by getAsset().

Here is the caller graph for this function:

◆ getMeshAssetManager()

Assets::MeshAssetManager * Engine::Core::AssetManager::getMeshAssetManager ( ) const
inlinenodiscard

Gets the mesh asset manager for mesh asset lookups.

Returns
Pointer to the mesh asset manager

Definition at line 317 of file AssetManager.h.

References meshAssetManager.

◆ getMeshAssetPipeline()

Ecs::ModelAssetPipeline & Engine::Core::AssetManager::getMeshAssetPipeline ( )

◆ getModelAssetManager()

Assets::ModelAssetManager * Engine::Core::AssetManager::getModelAssetManager ( ) const
inlinenodiscard

Gets the model asset manager for model/GLTF file loading state lookups.

Returns
Pointer to the model asset manager

Definition at line 308 of file AssetManager.h.

References modelAssetManager.

◆ getTextureAssetPipeline()

Ecs::TextureAssetPipeline & Engine::Core::AssetManager::getTextureAssetPipeline ( )

◆ getTextureDescriptorIndex()

uint32_t Engine::Core::AssetManager::getTextureDescriptorIndex ( const std::filesystem::path & path)
nodiscard

Gets the descriptor index of a loaded texture by path.

Parameters
pathPath to the texture (relative or absolute)
Returns
Descriptor index if texture is loaded, 0xFFFFFFFF otherwise

◆ getTextureDescriptorInfos()

std::vector< VkDescriptorImageInfo > Engine::Core::AssetManager::getTextureDescriptorInfos ( ) const

◆ getTextureHandleRegistry()

Assets::Textures::TextureHandleRegistry * Engine::Core::AssetManager::getTextureHandleRegistry ( )
inlinenodiscard

Gets the texture handle registry for O(1) descriptor index lookups.

Returns
Pointer to the texture handle registry

Definition at line 326 of file AssetManager.h.

References textureHandleRegistry_.

◆ loadAudioAsset()

AudioAssetRef Engine::Core::AssetManager::loadAudioAsset ( const std::filesystem::path & path)

Submit an audio file for async loading through the pipeline.

Parameters
pathRelative path to the audio file (WAV, FLAC, MP3)

Referenced by getAsset().

Here is the caller graph for this function:

◆ loadEcsCubemap()

Assets::CubemapTexture * Engine::Core::AssetManager::loadEcsCubemap ( const std::filesystem::path & path)

Loads a six-face cubemap asset from a directory.

◆ loadEcsModel()

void Engine::Core::AssetManager::loadEcsModel ( const std::filesystem::path & path)
private

Submits a gltf model for loading. You provide the path of the model to load. This can include 3D data, materials and textures.

Parameters
pathWhere the gltf file is

◆ loadEcsTexture()

void Engine::Core::AssetManager::loadEcsTexture ( const std::filesystem::path & path)
private

Loads a texture (.png / .jpg / .exr)

Parameters
pathwhere the texture is

Referenced by getAsset().

Here is the caller graph for this function:

◆ registerTexture()

Assets::RuntimeTexture * Engine::Core::AssetManager::registerTexture ( const std::filesystem::path & path,
Assets::RuntimeTexture texture )
private

Registers a texture with the texture manager which prevents the same texture from being loaded twice.

Parameters
pathpath to the texture
texturethe texture to register
Returns
pointer to a usable texture object

◆ registerTextureFromPrepared()

Assets::RuntimeTexture * Engine::Core::AssetManager::registerTextureFromPrepared ( const std::filesystem::path & path,
Assets::RuntimeTexture texture )
private

Register a texture whose Vulkan resources are already created. Skips createResources() — only allocates a descriptor index and queues for GPU upload. Used by the async texture preparation pipeline.

Parameters
pathPath to the texture (used as key)
textureTexture with VkImage/VkImageView/VkSampler already created
Returns
Pointer to the registered texture, or existing texture if already registered

◆ replaceTextureFromPrepared()

Assets::RuntimeTexture * Engine::Core::AssetManager::replaceTextureFromPrepared ( const std::filesystem::path & path,
Assets::RuntimeTexture texture )
private

Replace an already registered texture while preserving its descriptor index.

◆ setRenderingDataManager()

void Engine::Core::AssetManager::setRenderingDataManager ( RenderingDataManager * renderingDataManager)

Sets the RenderingDataManager on asset pipelines for hook notifications.

Parameters
renderingDataManagerPointer to the RenderingDataManager

References RenderingDataManager.

◆ unloadAllData()

void Engine::Core::AssetManager::unloadAllData ( )

◆ unloadRuntimeTextures()

void Engine::Core::AssetManager::unloadRuntimeTextures ( )
private

◆ unregisterTexture()

void Engine::Core::AssetManager::unregisterTexture ( Assets::RuntimeTexture * texture)
private

Member Data Documentation

◆ ApplicationContext

friend Engine::Core::AssetManager::ApplicationContext
private

Definition at line 135 of file AssetManager.h.

Referenced by AssetManager().

◆ audioAssetManager_

Assets::AudioAssetManager* Engine::Core::AssetManager::audioAssetManager_
private

Definition at line 348 of file AssetManager.h.

Referenced by getAudioAssetManager().

◆ audioAssetPipeline_

Ecs::AudioAssetPipeline Engine::Core::AssetManager::audioAssetPipeline_
private

Definition at line 349 of file AssetManager.h.

◆ context

ApplicationContext* Engine::Core::AssetManager::context = nullptr
private

Definition at line 365 of file AssetManager.h.

Referenced by AssetManager().

◆ cubemapTextures

std::unordered_map<std::filesystem::path, std::unique_ptr<Assets::CubemapTexture>, PathHasher> Engine::Core::AssetManager::cubemapTextures = {}
private

Definition at line 369 of file AssetManager.h.

◆ gltfLoader

Assets::Loaders::GltfLoader Engine::Core::AssetManager::gltfLoader = Assets::Loaders::GltfLoader( threadPool_ )
private

Definition at line 363 of file AssetManager.h.

◆ materialAssetManager

Assets::MaterialAssetManager* Engine::Core::AssetManager::materialAssetManager
private

Definition at line 338 of file AssetManager.h.

Referenced by getAsset(), and getMaterialAssetManager().

◆ meshAssetManager

Assets::MeshAssetManager* Engine::Core::AssetManager::meshAssetManager
private

Definition at line 337 of file AssetManager.h.

Referenced by getAsset(), and getMeshAssetManager().

◆ modelAssetManager

Assets::ModelAssetManager* Engine::Core::AssetManager::modelAssetManager
private

Definition at line 339 of file AssetManager.h.

Referenced by getModelAssetManager().

◆ modelAssetPipeline

Ecs::ModelAssetPipeline Engine::Core::AssetManager::modelAssetPipeline
private

Definition at line 346 of file AssetManager.h.

◆ renderer

Rendering::Renderer* Engine::Core::AssetManager::renderer = nullptr
private

Definition at line 366 of file AssetManager.h.

Referenced by attachToRenderer().

◆ RenderingDataManager

friend Engine::Core::AssetManager::RenderingDataManager
private

Definition at line 136 of file AssetManager.h.

Referenced by setRenderingDataManager().

◆ textureAllocator

DescriptorIndexAllocator Engine::Core::AssetManager::textureAllocator
private

Definition at line 373 of file AssetManager.h.

◆ textureAssetManager

Assets::TextureAssetManager* Engine::Core::AssetManager::textureAssetManager
private

Definition at line 335 of file AssetManager.h.

Referenced by getAsset().

◆ textureData

std::array<std::optional<Assets::RuntimeTexture>, MAX_TEXTURE_COUNT> Engine::Core::AssetManager::textureData
private

Definition at line 372 of file AssetManager.h.

◆ textureHandleRegistry_

Assets::Textures::TextureHandleRegistry Engine::Core::AssetManager::textureHandleRegistry_
private

Registry for type-safe texture handles.

Definition at line 344 of file AssetManager.h.

Referenced by getTextureHandleRegistry().

◆ textureIndexMap

BidirectionalMap<uint32_t, Assets::RuntimeTexture *> Engine::Core::AssetManager::textureIndexMap
private

Definition at line 370 of file AssetManager.h.

◆ textureMutex

std::mutex Engine::Core::AssetManager::textureMutex
private

Definition at line 414 of file AssetManager.h.

◆ texturePipeline

Ecs::TextureAssetPipeline Engine::Core::AssetManager::texturePipeline
private

Definition at line 336 of file AssetManager.h.

◆ textures

std::unordered_map<std::filesystem::path, Assets::RuntimeTexture *, PathHasher> Engine::Core::AssetManager::textures = {}
private

Definition at line 368 of file AssetManager.h.

◆ texturesToCopyImageData

std::vector<Assets::RuntimeTexture *> Engine::Core::AssetManager::texturesToCopyImageData
private

Definition at line 417 of file AssetManager.h.

◆ texturesToUpload

std::vector<TextureStorage> Engine::Core::AssetManager::texturesToUpload {}
private

Definition at line 416 of file AssetManager.h.

◆ threadedCalculation_

NamedThreadPool* Engine::Core::AssetManager::threadedCalculation_ = new NamedThreadPool( 2, "Bounding Sphere" )
private

Definition at line 333 of file AssetManager.h.

Referenced by getCalculationPool().

◆ threadPool_

NamedThreadPool* Engine::Core::AssetManager::threadPool_ = new NamedThreadPool( 2, "Asset Loader" )
private

Definition at line 332 of file AssetManager.h.

Referenced by getAssetLoaderPool().


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