Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
esengine::resource::Handle< T > Class Template Reference

Type-safe resource handle. More...

#include <Handle.hpp>

Public Types

using IdType = u32
using Layout = PackedId<20, 12>

Public Member Functions

 Handle ()=default
 Creates an invalid handle.
 Handle (IdType id)
 Creates a handle from a packed ID (index + generation).
bool isValid () const
 Checks if the handle references a valid resource.
IdType id () const
 Gets the packed identifier (index + generation).
u32 index () const
 Extracts the slot index from the packed handle.
u32 generation () const
 Extracts the generation from the packed handle.
bool operator== (const Handle &other) const
 Equality comparison.
bool operator!= (const Handle &other) const
 Inequality comparison.
 operator bool () const
 Explicit bool conversion (true if valid).

Static Public Member Functions

static Handle fromParts (u32 index, u32 generation)
 Creates a handle from separate index and generation.
static u32 extractIndex (IdType packed)
 Extracts index from a raw packed ID.
static u32 extractGeneration (IdType packed)
 Extracts generation from a raw packed ID.

Static Public Attributes

static constexpr u32 INDEX_BITS = Layout::INDEX_BITS
static constexpr u32 GEN_BITS = Layout::GEN_BITS
static constexpr u32 INDEX_MASK = Layout::INDEX_MASK
static constexpr u32 GEN_MASK = Layout::GEN_MASK
static constexpr IdType INVALID = 0

Detailed Description

template<typename T>
class esengine::resource::Handle< T >

Type-safe resource handle.

Lightweight identifier for resources stored in ResourcePool. Handles are copyable and comparable, but do not manage resource lifetime - use ResourceManager for acquire/release.

Template Parameters
TThe resource type this handle references
ShaderHandle shader = resourceManager.loadShader("vert.glsl", "frag.glsl");
if (shader.isValid()) {
Shader* ptr = resourceManager.getShader(shader);
}
GPU shader program for rendering.
Definition Shader.hpp:86
bool isValid() const
Checks if the handle references a valid resource.
Definition Handle.hpp:82
Handle< esengine::Shader > ShaderHandle
Handle to a shader resource.
Definition Handle.hpp:214

Definition at line 50 of file Handle.hpp.

Member Typedef Documentation

◆ IdType

template<typename T>
using esengine::resource::Handle< T >::IdType = u32

Definition at line 52 of file Handle.hpp.

◆ Layout

template<typename T>
using esengine::resource::Handle< T >::Layout = PackedId<20, 12>

Definition at line 56 of file Handle.hpp.

Constructor & Destructor Documentation

◆ Handle() [1/2]

template<typename T>
esengine::resource::Handle< T >::Handle ( )
default

Creates an invalid handle.

Referenced by esengine::resource::Handle< esengine::Shader >::fromParts().

◆ Handle() [2/2]

template<typename T>
esengine::resource::Handle< T >::Handle ( IdType id)
inlineexplicit

Creates a handle from a packed ID (index + generation).

Parameters
idThe packed resource identifier

Definition at line 70 of file Handle.hpp.

Member Function Documentation

◆ extractGeneration()

template<typename T>
u32 esengine::resource::Handle< T >::extractGeneration ( IdType packed)
inlinestatic

Extracts generation from a raw packed ID.

Definition at line 97 of file Handle.hpp.

Referenced by esengine::resource::ResourcePool< T >::invalidatePath(), and esengine::resource::ResourcePool< T >::release().

◆ extractIndex()

template<typename T>
u32 esengine::resource::Handle< T >::extractIndex ( IdType packed)
inlinestatic

Extracts index from a raw packed ID.

Definition at line 94 of file Handle.hpp.

Referenced by esengine::resource::ResourcePool< T >::invalidatePath(), and esengine::resource::ResourcePool< T >::release().

◆ fromParts()

template<typename T>
Handle esengine::resource::Handle< T >::fromParts ( u32 index,
u32 generation )
inlinestatic

Creates a handle from separate index and generation.

Parameters
indexSlot index in the resource pool (max ~1M)
generationReuse counter for the slot (max 4095)

Definition at line 77 of file Handle.hpp.

Referenced by esengine::resource::ResourcePool< T >::add(), esengine::resource::ResourcePool< T >::forEachAlive(), and esengine::resource::ResourcePool< T >::forEachAlive().

◆ generation()

◆ id()

template<typename T>
IdType esengine::resource::Handle< T >::id ( ) const
inline

Gets the packed identifier (index + generation).

Definition at line 85 of file Handle.hpp.

Referenced by esengine::MaterialStore::bindForDraw(), esengine::MaterialStore::bindThrough(), bitmaptextToJS(), esengine::TilemapRenderPlugin::collect(), convexcollider3dToJS(), esengine::MaterialStore::forgetShader(), esengine::resource::ResourceManager::getTextureMetadata(), esengine::resource::ResourceManager::hasTextureMetadata(), esengine::MaterialStore::layoutFor(), lightprobevolumeToJS(), lightToJS(), lodgroupToJS(), esengine::material_compileEsshader(), esengine::mesh_createFromChannels(), meshcollider3dToJS(), meshinstancesToJS(), meshlightmapToJS(), esengine::MaterialStore::meshProgram(), esengine::resource::ResourceManager::meshRealizations(), meshrendererToJS(), particleemitterToJS(), esengine::MaterialStore::prepassCoverageProgram(), reflectionprobeToJS(), esengine::MaterialStore::registerLayout(), esengine::resource::ResourceManager::releaseBitmapFont(), esengine::resource::ResourceManager::releaseEnvironment(), esengine::resource::ResourceManager::releaseIndexBuffer(), esengine::resource::ResourceManager::releaseMesh(), esengine::resource::ResourceManager::releaseProbeVolume(), esengine::resource::ResourceManager::releaseShader(), esengine::resource::ResourceManager::releaseTexture(), esengine::resource::ResourceManager::releaseVertexBuffer(), esengine::resource::ResourceManager::rematerializeMesh(), esengine::MaterialStore::rememberSource(), esengine::resource::ResourceManager::removeTextureMetadata(), esengine::rm_acquireTextureByPath(), esengine::rm_createCompressedTexture(), esengine::rm_createShader(), esengine::rm_createTexture(), esengine::rm_createTextureArray(), esengine::rm_registerExternalTexture(), esengine::rm_registerExternalTextureSized(), esengine::resource::ResourceManager::setMeshClusters(), esengine::resource::ResourceManager::setMeshSkinChunks(), esengine::resource::ResourcePool< T >::setPath(), esengine::resource::ResourceManager::setTextureMetadata(), esengine::MaterialStore::setUniform(), esengine::MaterialStore::setWorldUnitsPerMeter(), esengine::MaterialStore::shadowProgram(), spriteToJS(), tilemaplayerToJS(), trailrendererToJS(), and uivisualToJS().

◆ index()

◆ isValid()

template<typename T>
bool esengine::resource::Handle< T >::isValid ( ) const
inline

Checks if the handle references a valid resource.

Definition at line 82 of file Handle.hpp.

Referenced by esengine::resource::ResourcePool< T >::addRef(), esengine::PostProcessPipeline::canDrawMaterialOver(), esengine::TilemapRenderPlugin::collect(), esengine::PostProcessPipeline::drawMaterialOver(), esengine::gatherLodLevels(), esengine::resource::ResourcePool< T >::get(), esengine::resource::ResourcePool< T >::get(), esengine::resource::ResourcePool< T >::getPath(), esengine::resource::ResourcePool< T >::getRefCount(), esengine::resource::ResourceManager::getTextureMetadata(), esengine::PostProcessPipeline::grabScene(), esengine::resource::ResourceManager::hasTextureMetadata(), esengine::resource::ResourcePool< T >::isEvictable(), esengine::resource::ResourceManager::loadTextureByGUID(), esengine::resource::SharedHandle< esengine::Shader >::make(), esengine::material_compileEsshader(), esengine::MaterialStore::meshProgram(), esengine::resource::Handle< esengine::Shader >::operator bool(), esengine::placementCoarseMesh(), esengine::MaterialStore::prepassCoverageProgram(), esengine::MaterialStore::registerLayout(), esengine::resource::ResourceManager::registerTextureWithPath(), esengine::resource::ResourceManager::releaseBitmapFont(), esengine::resource::ResourceManager::releaseIndexBuffer(), esengine::resource::ResourceManager::releaseShader(), esengine::resource::ResourceManager::releaseTexture(), esengine::resource::ResourceManager::releaseVertexBuffer(), esengine::MaterialStore::rememberSource(), esengine::resource::ResourceManager::removeTextureMetadata(), esengine::resource::ResourcePool< T >::setPath(), esengine::RenderFrame::setProbeVolumeOverride(), esengine::resource::ResourceManager::setTextureMetadata(), and esengine::MaterialStore::shadowProgram().

◆ operator bool()

template<typename T>
esengine::resource::Handle< T >::operator bool ( ) const
inlineexplicit

Explicit bool conversion (true if valid).

Definition at line 106 of file Handle.hpp.

◆ operator!=()

template<typename T>
bool esengine::resource::Handle< T >::operator!= ( const Handle< T > & other) const
inline

Inequality comparison.

Definition at line 103 of file Handle.hpp.

◆ operator==()

template<typename T>
bool esengine::resource::Handle< T >::operator== ( const Handle< T > & other) const
inline

Equality comparison.

Definition at line 100 of file Handle.hpp.

Member Data Documentation

◆ GEN_BITS

template<typename T>
u32 esengine::resource::Handle< T >::GEN_BITS = Layout::GEN_BITS
staticconstexpr

Definition at line 58 of file Handle.hpp.

◆ GEN_MASK

template<typename T>
u32 esengine::resource::Handle< T >::GEN_MASK = Layout::GEN_MASK
staticconstexpr

Definition at line 60 of file Handle.hpp.

◆ INDEX_BITS

template<typename T>
u32 esengine::resource::Handle< T >::INDEX_BITS = Layout::INDEX_BITS
staticconstexpr

Definition at line 57 of file Handle.hpp.

◆ INDEX_MASK

template<typename T>
u32 esengine::resource::Handle< T >::INDEX_MASK = Layout::INDEX_MASK
staticconstexpr

Definition at line 59 of file Handle.hpp.

◆ INVALID

template<typename T>
IdType esengine::resource::Handle< T >::INVALID = 0
staticconstexpr

Definition at line 61 of file Handle.hpp.


The documentation for this class was generated from the following file:
  • /home/runner/work/estella/estella/src/esengine/resource/Handle.hpp