Raven Engine v0.1
Loading...
Searching...
No Matches
Raven::MaterialRegistry Class Reference

Central manager for material lifetimes and asset persistence. More...

#include <MaterialRegistry.h>

Public Member Functions

 MaterialRegistry ()=default
 ~MaterialRegistry ()=default
void Shutdown ()
 Destroys all registered materials and clears registry state.
MaterialHandle LoadMaterialAsset (const std::string &assetPath)
 Load a material asset from disk or return existing slot handle.
MaterialHandle CreateMaterialTransient (const Ref< Material > &mat)
 Register a transient runtime-only material.
MaterialHandle CreateOrLoadMaterial (const MaterialAsset &desc)
 Create a new material or load existing from disk.
Ref< MaterialGetMaterial (const MaterialHandle &handle)
 Resolve a Ref<Material> from a handle.
void RemoveMaterial (const MaterialHandle &handle)
 Remove a material and free its slot.
bool SaveMaterial (const MaterialHandle &handle)
 Persist a material asset to disk.

Detailed Description

Central manager for material lifetimes and asset persistence.

MaterialRegistry provides both runtime and asset-backed material creation. It hides the complexity of reference management, slot reuse, and serialization.

Key workflows:

  • LoadMaterialAsset(path): Deserialize a material JSON file, create a Material, and track it.
  • CreateMaterialTransient(mat): Register a runtime-only material not tied to disk.
  • CreateOrLoadMaterial(desc): Register a new material or load if it already exists on disk.
  • GetMaterial(handle): Resolve a MaterialRef from a handle.
  • SaveMaterial(handle): Serialize the associated asset back to disk.

Handles remain valid until their version mismatches with the slot version.

Constructor & Destructor Documentation

◆ MaterialRegistry()

Raven::MaterialRegistry::MaterialRegistry ( )
default

◆ ~MaterialRegistry()

Raven::MaterialRegistry::~MaterialRegistry ( )
default

Member Function Documentation

◆ CreateMaterialTransient()

MaterialHandle Raven::MaterialRegistry::CreateMaterialTransient ( const Ref< Material > & mat)

Register a transient runtime-only material.

Parameters
matRef<Material> to register.
Returns
MaterialHandle for the transient material.
Note
Material is not persisted to disk.

◆ CreateOrLoadMaterial()

MaterialHandle Raven::MaterialRegistry::CreateOrLoadMaterial ( const MaterialAsset & desc)

Create a new material or load existing from disk.

Parameters
descMaterialAsset descriptor.
Returns
MaterialHandle for the new or loaded material.
Note
Persists the material asset to disk if path is provided or generated.
Automatically assigns GPUIndex if missing.

◆ GetMaterial()

Ref< Material > Raven::MaterialRegistry::GetMaterial ( const MaterialHandle & handle)

Resolve a Ref<Material> from a handle.

Parameters
handleMaterialHandle to resolve.
Returns
Ref<Material> or nullptr if handle is invalid.
Note
Handle is invalid if slot version does not match.

◆ LoadMaterialAsset()

MaterialHandle Raven::MaterialRegistry::LoadMaterialAsset ( const std::string & assetPath)

Load a material asset from disk or return existing slot handle.

Parameters
assetPathNormalized relative path to the JSON material file.
Returns
MaterialHandle corresponding to the loaded or existing material.
Note
If deserialization fails, returns an invalid handle.

◆ RemoveMaterial()

void Raven::MaterialRegistry::RemoveMaterial ( const MaterialHandle & handle)

Remove a material and free its slot.

Parameters
handleMaterialHandle to remove.
Note
Increments slot version to invalidate previous handles.
Added slot index is pushed to free list for reuse.

◆ SaveMaterial()

bool Raven::MaterialRegistry::SaveMaterial ( const MaterialHandle & handle)

Persist a material asset to disk.

Parameters
handleMaterialHandle of material to save.
Returns
true if serialization succeeded, false if handle is invalid or pathless.

◆ Shutdown()

void Raven::MaterialRegistry::Shutdown ( )

Destroys all registered materials and clears registry state.

Calls VulkanMaterial::Destroy() on Vulkan-backed materials to ensure descriptor sets are released before GPU shutdown.


The documentation for this class was generated from the following files: