Raven Engine v0.1
A modern 3D Game Engine
Loading...
Searching...
No Matches
Raven::MaterialRegistry Class Reference

Central manager for material lifetimes. More...

#include <MaterialRegistry.h>

Inherits Raven::RefCounted.

Public Member Functions

 MaterialRegistry ()=default
 ~MaterialRegistry ()=default
ILLUMINE_API void Shutdown ()
 Destroys all registered materials and clears registry state.
ILLUMINE_API MaterialHandle LoadMaterialAsset (const std::filesystem::path &materialPath)
 Load a material asset from disk or return existing slot handle.
ILLUMINE_API MaterialHandle CreateOrLoadMaterial (const MaterialAsset &desc)
 Create a new material or load existing from disk.
ILLUMINE_API Ref< MaterialGetMaterial (const MaterialHandle &handle)
 Resolve a Ref<Material> from a handle.
ILLUMINE_API void RemoveMaterial (const MaterialHandle &handle)
 Remove a material and free its slot.
ILLUMINE_API bool SaveMaterial (const MaterialHandle &handle)
 Persist a material asset to disk.
glz::ordered_map< MaterialHandle, Slot > & GetAllSlots ()
 Get all registered material Slots.
Public Member Functions inherited from Raven::RefCounted
 RefCounted ()
virtual ~RefCounted ()
void IncRefCount ()
void DecRefCount ()
u32 GetRefCount () const

Detailed Description

Central manager for material lifetimes.

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.

Constructor & Destructor Documentation

◆ MaterialRegistry()

Raven::MaterialRegistry::MaterialRegistry ( )
default

◆ ~MaterialRegistry()

Raven::MaterialRegistry::~MaterialRegistry ( )
default

Member Function Documentation

◆ 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.

◆ GetAllSlots()

glz::ordered_map< MaterialHandle, Slot > & Raven::MaterialRegistry::GetAllSlots ( )
inline

Get all registered material Slots.

Returns
Reference to vector of Slots.

◆ 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::filesystem::path & materialPath)

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: