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

Central manager for GPU resources. More...

#include <ResourceManager.hpp>

Classes

struct  OwedTexture
 Textures the device is waiting for content for, with who refills them. More...
struct  MeshRealization
 One live mesh and whether its geometry is on the device. More...

Public Types

using ShaderRetiredCallback = void (*)(void*, ShaderHandle)
 One renderer owns shader-derived metadata. Notify after final pool retirement.

Public Member Functions

 ResourceManager ()=default
 ~ResourceManager ()=default
 ResourceManager (const ResourceManager &)=delete
ResourceManager & operator= (const ResourceManager &)=delete
 ResourceManager (ResourceManager &&)=default
ResourceManager & operator= (ResourceManager &&)=default
void init (GfxDevice &device)
 Initializes the resource manager.
GfxDevice * device () const
void shutdown ()
 Shuts down and releases all resources.
bool isInitialized () const
 Checks if the manager is initialized.
void update ()
 Updates resource manager (processes hot reload, call once per frame).
GfxShaderLanguage preferredShaderLanguage () const
 The language embedded pipelines must author their sources in.
ShaderTargetLanguage preferredShaderTarget () const
 preferredShaderLanguage() as a ShaderParser assembly target.
bool deferLinks () const
 Creates a shader from source strings.
ShaderHandle createShader (const std::string &vertSrc, const std::string &fragSrc, bool rewriteLoose=true, GfxShaderLanguage language=GfxShaderLanguage::GLSL_ES300, bool deferLink=false)
ShaderHandle createShaderWithBindings (const std::string &vertSrc, const std::string &fragSrc, std::initializer_list< AttribBinding > bindings, GfxShaderLanguage language=GfxShaderLanguage::GLSL_ES300, bool deferLink=false)
ShaderHandle loadShader (const std::string &vertPath, const std::string &fragPath)
 Loads a shader from file paths (with caching).
Shader * getShader (ShaderHandle handle)
 Gets a shader by handle.
const Shader * getShader (ShaderHandle handle) const
 Gets a shader by handle (const).
void releaseShader (ShaderHandle handle)
 Releases a shader (decrements ref count).
void setShaderRetiredCallback (void *owner, ShaderRetiredCallback callback)
void clearShaderRetiredCallback (void *owner)
u32 getShaderRefCount (ShaderHandle handle) const
 Gets the current reference count for a shader.
TextureHandle createTexture (ResourceContent content, const TextureSpecification &spec)
 Creates a texture from specification.
TextureHandle createTexture (ResourceContent content, u32 width, u32 height, ConstSpan< u8 > pixels, TextureFormat format, bool flipY=false)
 Creates a texture from pixel data.
TextureHandle createTextureArray (ResourceContent content, const TextureSpecification &spec, ConstSpan< u8 > pixels)
 Creates a 2D texture array from spec.layers same-size RGBA8 (or SRGB8A8) layers.
TextureHandle createCompressedTexture (ResourceContent content, u32 width, u32 height, GfxCompressedFormat format, ConstSpan< u8 > data, u32 mipLevels=1)
 Creates a block-compressed texture (KTX2 → ETC2/ASTC/BC), uploading the pre-compressed blocks for mip level 0. Tracked like any texture; its residency cost is the real (compressed) byte size.
TextureHandle loadTexture (const std::string &path)
 Loads a texture from file (with caching).
Texture * getTexture (TextureHandle handle)
 Gets a texture by handle.
const Texture * getTexture (TextureHandle handle) const
 Gets a texture by handle (const).
void releaseTexture (TextureHandle handle)
 Releases a texture (decrements ref count).
u32 getTextureRefCount (TextureHandle handle) const
 Gets the current reference count for a texture.
TextureHandle registerExternalTexture (ResourceContent content, u32 glTextureId, u32 width, u32 height, usize bytes=0)
 Registers an externally-created GL texture.
TextureHandle wrapDeviceTexture (::esengine::TextureHandle texture, u32 width, u32 height)
 Names a texture the device holds for another owner (a render target's colour plane) by a resource handle, without taking it over.
void registerTextureWithPath (TextureHandle handle, const std::string &path)
 Registers a texture with a path for cache lookup.
bool adoptTextureContent (TextureHandle target, TextureHandle source)
 Moves a freshly loaded texture's pixels behind an owed handle.
std::vector< OwedTexture > texturesAwaitingReupload () const
void forgoTextureContent (TextureHandle handle)
 Gives up on an owed texture's content: it keeps blank storage.
void restoreTextureContent (TextureHandle handle)
 Settles an owed texture whose provider wrote the pixels itself.
u32 textureNativeId (TextureHandle handle) const
 The backend's own name for a texture's object, for a host that writes its pixels itself; 0 when there is none. See GfxDevice::nativeTextureName.
const std::string & getTexturePath (TextureHandle handle) const
 Gets the cached path for a texture.
TextureHandle loadTextureByGUID (const std::string &guid, const std::string &path)
 Loads a texture by GUID (with caching).
TextureHandle getTextureByGUID (const std::string &guid) const
 Gets a texture handle by GUID if already loaded.
void releaseTextureByGUID (const std::string &guid)
 Releases a texture by GUID.
void setTextureBudget (usize bytes)
 Sets the texture pool's resident-byte budget (0 = no eviction). Over budget, refCount==0 textures are evicted oldest-first.
void setRetainedBudget (usize bytes)
 See GfxDevice::setRetainedBudget.
TextureHandle acquireTextureByPath (const std::string &path)
 Reuses a cached texture by its build path: returns its handle with an added reference (reviving an evictable one), or an invalid handle if none is cached. Lets the runtime dedupe + reuse textures across loads.
bool invalidateTexturePath (const std::string &path)
 Severs a path's texture-cache identity (hot reload). The next acquireTextureByPath for it misses, so stale bytes are never revived; an evictable entry under that path is freed immediately.
usize trimTextureCache ()
 Frees every evictable cached texture now (memory pressure). Held textures and the budget are untouched.
void setTextureMetadata (TextureHandle handle, const TextureMetadata &metadata)
 Sets metadata for a texture.
const TextureMetadata * getTextureMetadata (TextureHandle handle) const
 Gets metadata for a texture.
bool hasTextureMetadata (TextureHandle handle) const
 Checks if a texture has metadata.
void removeTextureMetadata (TextureHandle handle)
 Removes metadata for a texture.
template<typename T>
VertexBufferHandle createVertexBuffer (GfxContent content, ConstSpan< T > data)
 Creates a vertex buffer from typed data.
VertexBufferHandle createVertexBuffer (GfxContent content, u32 sizeBytes)
 Creates a dynamic vertex buffer.
bool setMeshClusters (MeshHandle target, lod::ClusterHierarchy hierarchy)
 Uploads geometry that stays on the GPU, drawn from its own buffers.
bool setMeshSkinChunks (MeshHandle target, std::vector< MeshSkinChunk > chunks, std::vector< u16 > bones)
 Gives a realized skinned mesh the chunks it is drawn in (Mesh::skinChunks).
MeshHandle createMesh (ConstSpan< u8 > vertexBytes, ConstSpan< u32 > indices, ConstSpan< GfxVertexAttribute > channels, u32 vertexStride, const glm::vec3 &localMin, const glm::vec3 &localMax, MeshRecovery recovery, ConstSpan< f32 > inverseBind={}, const MeshMorphSource &morph={})
bool rematerializeMesh (MeshHandle target, ConstSpan< u8 > vertexBytes, ConstSpan< u32 > indices, ConstSpan< GfxVertexAttribute > channels, u32 vertexStride, const glm::vec3 &localMin, const glm::vec3 &localMax, ConstSpan< f32 > inverseBind={}, const MeshMorphSource &morph={})
 Puts new geometry behind an EXISTING mesh handle.
void setMeshEdgeBuffers (bool enabled)
 Whether meshes realized FROM NOW ON also get an edge buffer.
bool meshEdgeBuffers () const
Mesh * getMesh (MeshHandle handle)
 The mesh a handle names, or null.
const Mesh * getMesh (MeshHandle handle) const
void releaseMesh (MeshHandle handle)
 Releases a mesh and the buffers it owns.
u64 meshesRevision () const
 Changes whenever any mesh is realized (each takes a new Mesh::revision) or released: while it holds, every mesh a reader looked at is the one it was.
u64 textureMetadataRevision () const
 Moves whenever a texture's metadata (its nine-slice borders and the rest) is set or dropped.
std::vector< MeshHandle > meshesAwaitingRematerialization () const
 Replayable meshes whose geometry the device is still waiting for.
std::vector< MeshRealization > meshRealizations ()
 Every live mesh, for a recovery criterion to read.
EnvironmentHandle createEnvironment (ConstSpan< f32 > irradiance, TextureHandle specular, f32 faceSize, u32 mipCount, f32 maxRange, u32 columns=1)
 Registers a baked environment.
Environment * getEnvironment (EnvironmentHandle handle)
 The environment a handle names, or null.
const Environment * getEnvironment (EnvironmentHandle handle) const
void releaseEnvironment (EnvironmentHandle handle)
 Releases an environment. The atlas is an ordinary texture asset with its own lifetime, so it is NOT released here.
ProbeVolumeHandle createProbeVolume (const glm::ivec3 &resolution, ConstSpan< f32 > irradiance)
 Registers a grid of baked irradiance.
ProbeVolumeHandle createProbeVolumeBricks (const glm::ivec3 &resolution, ConstSpan< i32 > bricks, ConstSpan< f32 > irradiance)
 Registers a SPARSE grid: bricks at their own spacing (see ProbeVolume).
ProbeVolume * getProbeVolume (ProbeVolumeHandle handle)
 The probe volume a handle names, or null.
const ProbeVolume * getProbeVolume (ProbeVolumeHandle handle) const
void releaseProbeVolume (ProbeVolumeHandle handle)
 Releases a probe volume.
VertexBuffer * getVertexBuffer (VertexBufferHandle handle)
 Gets a vertex buffer by handle.
const VertexBuffer * getVertexBuffer (VertexBufferHandle handle) const
 Gets a vertex buffer by handle (const).
void releaseVertexBuffer (VertexBufferHandle handle)
 Releases a vertex buffer (decrements ref count).
IndexBufferHandle createIndexBuffer (GfxContent content, ConstSpan< u32 > indices)
 Creates an index buffer from 32-bit indices.
IndexBufferHandle createIndexBuffer (GfxContent content, ConstSpan< u16 > indices)
 Creates an index buffer from 16-bit indices.
IndexBuffer * getIndexBuffer (IndexBufferHandle handle)
 Gets an index buffer by handle.
const IndexBuffer * getIndexBuffer (IndexBufferHandle handle) const
 Gets an index buffer by handle (const).
void releaseIndexBuffer (IndexBufferHandle handle)
 Releases an index buffer (decrements ref count).
BitmapFontHandle loadBitmapFont (const std::string &fntPath)
BitmapFontHandle createBitmapFont (const std::string &fntContent, TextureHandle texture, u32 texWidth, u32 texHeight)
BitmapFontHandle createLabelAtlasFont (TextureHandle texture, u32 texWidth, u32 texHeight, const std::string &chars, u32 charWidth, u32 charHeight)
text::BitmapFont * getBitmapFont (BitmapFontHandle handle)
const text::BitmapFont * getBitmapFont (BitmapFontHandle handle) const
void releaseBitmapFont (BitmapFontHandle handle)
u32 getBitmapFontRefCount (BitmapFontHandle handle) const
 Gets the current reference count for a bitmap font.
ResourceStats getStats () const
 Gets current resource statistics.
void resetCacheStats ()
 Resets cache hit/miss counters.
u32 meshPageCount () const
u64 meshPageBytes () const

Detailed Description

Central manager for GPU resources.

Manages the lifecycle of shaders, textures, and buffers. Provides handle-based access with reference counting and path-based caching for deduplication.

rm.init();
auto shader = rm.createShader(vertSrc, fragSrc);
auto texture = rm.loadTexture("assets/player.png");
Shader* shaderPtr = rm.getShader(shader);
Texture* texturePtr = rm.getTexture(texture);
rm.releaseShader(shader);
rm.releaseTexture(texture);
rm.shutdown();
GPU shader program for rendering.
Definition Shader.hpp:86
2D texture for GPU rendering
Definition Texture.hpp:116
Texture * getTexture(TextureHandle handle)
Gets a texture by handle.
TextureHandle loadTexture(const std::string &path)
Loads a texture from file (with caching).
void releaseShader(ShaderHandle handle)
Releases a shader (decrements ref count).
Shader * getShader(ShaderHandle handle)
Gets a shader by handle.
void shutdown()
Shuts down and releases all resources.
ShaderHandle createShader(const std::string &vertSrc, const std::string &fragSrc, bool rewriteLoose=true, GfxShaderLanguage language=GfxShaderLanguage::GLSL_ES300, bool deferLink=false)
void init(GfxDevice &device)
Initializes the resource manager.
void releaseTexture(TextureHandle handle)
Releases a texture (decrements ref count).

Definition at line 112 of file ResourceManager.hpp.

Member Typedef Documentation

◆ ShaderRetiredCallback

One renderer owns shader-derived metadata. Notify after final pool retirement.

Definition at line 228 of file ResourceManager.hpp.

Constructor & Destructor Documentation

◆ ResourceManager() [1/3]

esengine::resource::ResourceManager::ResourceManager ( )
default

◆ ~ResourceManager()

esengine::resource::ResourceManager::~ResourceManager ( )
default

◆ ResourceManager() [2/3]

esengine::resource::ResourceManager::ResourceManager ( const ResourceManager & )
delete

References ResourceManager().

◆ ResourceManager() [3/3]

esengine::resource::ResourceManager::ResourceManager ( ResourceManager && )
default

References ResourceManager().

Member Function Documentation

◆ acquireTextureByPath()

TextureHandle esengine::resource::ResourceManager::acquireTextureByPath ( const std::string & path)

Reuses a cached texture by its build path: returns its handle with an added reference (reviving an evictable one), or an invalid handle if none is cached. Lets the runtime dedupe + reuse textures across loads.

Definition at line 417 of file ResourceManager.cpp.

References esengine::Texture::getId(), and esengine::GfxOwedContent::Texture.

Referenced by esengine::rm_acquireTextureByPath().

◆ adoptTextureContent()

bool esengine::resource::ResourceManager::adoptTextureContent ( TextureHandle target,
TextureHandle source )

Moves a freshly loaded texture's pixels behind an owed handle.

How the asset layer pays: it loads the texture the ordinary way and hands the result over, which leaves source empty for its release.

Returns
False if either handle names no live texture.

Definition at line 350 of file ResourceManager.cpp.

References esengine::Texture::adoptContent().

Referenced by esengine::rm_adoptTextureContent().

◆ clearShaderRetiredCallback()

void esengine::resource::ResourceManager::clearShaderRetiredCallback ( void * owner)
inline

Definition at line 232 of file ResourceManager.hpp.

◆ createBitmapFont()

BitmapFontHandle esengine::resource::ResourceManager::createBitmapFont ( const std::string & fntContent,
TextureHandle texture,
u32 texWidth,
u32 texHeight )

Definition at line 1133 of file ResourceManager.cpp.

References esengine::makeUnique().

◆ createCompressedTexture()

TextureHandle esengine::resource::ResourceManager::createCompressedTexture ( ResourceContent content,
u32 width,
u32 height,
GfxCompressedFormat format,
ConstSpan< u8 > data,
u32 mipLevels = 1 )

Creates a block-compressed texture (KTX2 → ETC2/ASTC/BC), uploading the pre-compressed blocks for mip level 0. Tracked like any texture; its residency cost is the real (compressed) byte size.

Parameters
dataAll mipLevels concatenated (level 0 first, block-aligned).
mipLevelsMip levels present (1 = base only).
Returns
Handle to the texture, or invalid handle on failure.

Definition at line 266 of file ResourceManager.cpp.

References esengine::Texture::createCompressed(), ES_LOG_ERROR, and esengine::resource::toGfxContent().

Referenced by esengine::rm_createCompressedTexture().

◆ createEnvironment()

EnvironmentHandle esengine::resource::ResourceManager::createEnvironment ( ConstSpan< f32 > irradiance,
TextureHandle specular,
f32 faceSize,
u32 mipCount,
f32 maxRange,
u32 columns = 1 )

Registers a baked environment.

Parameters
irradianceNine RGB spherical-harmonic coefficients.
specularThe prefiltered octahedral atlas; may be invalid, leaving the environment diffuse-only.
Returns
Handle to the environment, or invalid when the coefficients are not nine.

Definition at line 987 of file ResourceManager.cpp.

References ES_LOG_ERROR.

◆ createIndexBuffer() [1/2]

IndexBufferHandle esengine::resource::ResourceManager::createIndexBuffer ( GfxContent content,
ConstSpan< u16 > indices )

Creates an index buffer from 16-bit indices.

Parameters
indicesSpan of index data
Returns
Handle to the buffer, or invalid handle on failure

Definition at line 1090 of file ResourceManager.cpp.

References esengine::IndexBuffer::create(), and ES_LOG_ERROR.

◆ createIndexBuffer() [2/2]

IndexBufferHandle esengine::resource::ResourceManager::createIndexBuffer ( GfxContent content,
ConstSpan< u32 > indices )

Creates an index buffer from 32-bit indices.

Parameters
indicesSpan of index data
Returns
Handle to the buffer, or invalid handle on failure

Definition at line 1080 of file ResourceManager.cpp.

References esengine::IndexBuffer::create(), and ES_LOG_ERROR.

◆ createLabelAtlasFont()

BitmapFontHandle esengine::resource::ResourceManager::createLabelAtlasFont ( TextureHandle texture,
u32 texWidth,
u32 texHeight,
const std::string & chars,
u32 charWidth,
u32 charHeight )

Definition at line 1143 of file ResourceManager.cpp.

References esengine::makeUnique().

◆ createMesh()

MeshHandle esengine::resource::ResourceManager::createMesh ( ConstSpan< u8 > vertexBytes,
ConstSpan< u32 > indices,
ConstSpan< GfxVertexAttribute > channels,
u32 vertexStride,
const glm::vec3 & localMin,
const glm::vec3 & localMax,
MeshRecovery recovery,
ConstSpan< f32 > inverseBind = {},
const MeshMorphSource & morph = {} )

◆ createProbeVolume()

ProbeVolumeHandle esengine::resource::ResourceManager::createProbeVolume ( const glm::ivec3 & resolution,
ConstSpan< f32 > irradiance )

Registers a grid of baked irradiance.

Parameters
resolutionProbes along x, y and z.
irradianceNine RGB coefficients per probe, x fastest then y then z.

Definition at line 1019 of file ResourceManager.cpp.

References ES_LOG_ERROR, and esengine::ProbeVolume::nextRevision().

◆ createProbeVolumeBricks()

ProbeVolumeHandle esengine::resource::ResourceManager::createProbeVolumeBricks ( const glm::ivec3 & resolution,
ConstSpan< i32 > bricks,
ConstSpan< f32 > irradiance )

Registers a SPARSE grid: bricks at their own spacing (see ProbeVolume).

Parameters
resolutionThe finest grid's probes along x, y and z.
bricksFour ints a brick: its first finest-brick cell x, y, z and its span in those cells.
irradianceNine RGB coefficients per probe, ProbeVolume::kBrickProbes probes a brick, brick after brick.

Definition at line 1037 of file ResourceManager.cpp.

References ES_LOG_ERROR, and esengine::ProbeVolume::nextRevision().

◆ createShader()

ShaderHandle esengine::resource::ResourceManager::createShader ( const std::string & vertSrc,
const std::string & fragSrc,
bool rewriteLoose = true,
GfxShaderLanguage language = GfxShaderLanguage::GLSL_ES300,
bool deferLink = false )

◆ createShaderWithBindings()

ShaderHandle esengine::resource::ResourceManager::createShaderWithBindings ( const std::string & vertSrc,
const std::string & fragSrc,
std::initializer_list< AttribBinding > bindings,
GfxShaderLanguage language = GfxShaderLanguage::GLSL_ES300,
bool deferLink = false )

◆ createTexture() [1/2]

TextureHandle esengine::resource::ResourceManager::createTexture ( ResourceContent content,
const TextureSpecification & spec )

Creates a texture from specification.

Parameters
specTexture creation parameters
Returns
Handle to the texture, or invalid handle on failure

Definition at line 223 of file ResourceManager.cpp.

References esengine::Texture::create(), ES_LOG_ERROR, and esengine::resource::toGfxContent().

Referenced by esengine::rm_createTexture(), and esengine::rm_createTextureEx().

◆ createTexture() [2/2]

TextureHandle esengine::resource::ResourceManager::createTexture ( ResourceContent content,
u32 width,
u32 height,
ConstSpan< u8 > pixels,
TextureFormat format,
bool flipY = false )

Creates a texture from pixel data.

Parameters
widthTexture width in pixels
heightTexture height in pixels
pixelsPixel data
formatPixel format (default RGBA8)
Returns
Handle to the texture, or invalid handle on failure

Definition at line 234 of file ResourceManager.cpp.

References esengine::Texture::create(), ES_LOG_ERROR, and esengine::resource::toGfxContent().

◆ createTextureArray()

TextureHandle esengine::resource::ResourceManager::createTextureArray ( ResourceContent content,
const TextureSpecification & spec,
ConstSpan< u8 > pixels )

Creates a 2D texture array from spec.layers same-size RGBA8 (or SRGB8A8) layers.

Parameters
pixelsThe layers back to back, layer 0 first; exactly spec.width * spec.height * 4 * spec.layers bytes, or nothing is made.
Returns
Handle to the texture, or invalid handle on failure

Definition at line 247 of file ResourceManager.cpp.

References esengine::Texture::createArray(), ES_LOG_ERROR, esengine::TextureSpecification::format, esengine::TextureSpecification::height, esengine::TextureSpecification::layers, esengine::RGBA8, esengine::SRGB8A8, esengine::resource::toGfxContent(), and esengine::TextureSpecification::width.

Referenced by esengine::rm_createTextureArray().

◆ createVertexBuffer() [1/2]

template<typename T>
VertexBufferHandle esengine::resource::ResourceManager::createVertexBuffer ( GfxContent content,
ConstSpan< T > data )

Creates a vertex buffer from typed data.

Template Parameters
TVertex type
Parameters
dataSpan of vertex data
Returns
Handle to the buffer, or invalid handle on failure

Definition at line 778 of file ResourceManager.hpp.

References esengine::VertexBuffer::create().

◆ createVertexBuffer() [2/2]

VertexBufferHandle esengine::resource::ResourceManager::createVertexBuffer ( GfxContent content,
u32 sizeBytes )

Creates a dynamic vertex buffer.

Parameters
sizeBytesBuffer size in bytes
Returns
Handle to the buffer, or invalid handle on failure

Definition at line 515 of file ResourceManager.cpp.

References esengine::VertexBuffer::create(), and ES_LOG_ERROR.

◆ deferLinks()

bool esengine::resource::ResourceManager::deferLinks ( ) const

Creates a shader from source strings.

Parameters
vertSrcVertex shader GLSL source
fragSrcFragment shader GLSL source
rewriteLooseLift loose non-sampler uniforms into a std140 DrawParams block (see renderer/DrawParams.hpp). Pass false for sources whose uniform blocks are already assembled (ShaderParser material output).
Returns
Handle to the shader, or invalid handle on failure

Whether a shader that is known to compile is made without waiting for it (the device's skip-what-is-not-ready policy is on).

Definition at line 115 of file ResourceManager.cpp.

◆ device()

GfxDevice * esengine::resource::ResourceManager::device ( ) const
inline

The device resources are created on, or null before init. Read by callers that must ASK the backend what it supports.

Definition at line 138 of file ResourceManager.hpp.

Referenced by init(), operator=(), and esengine::rm_supportsCompressedFormat().

◆ forgoTextureContent()

void esengine::resource::ResourceManager::forgoTextureContent ( TextureHandle handle)

Gives up on an owed texture's content: it keeps blank storage.

For content nothing can bring back; the caller says so in the log.

Definition at line 372 of file ResourceManager.cpp.

References esengine::Texture::getId(), and esengine::GfxOwedContent::Texture.

Referenced by esengine::rm_forgoTextureContent().

◆ getBitmapFont() [1/2]

text::BitmapFont * esengine::resource::ResourceManager::getBitmapFont ( BitmapFontHandle handle)

Definition at line 1152 of file ResourceManager.cpp.

◆ getBitmapFont() [2/2]

const text::BitmapFont * esengine::resource::ResourceManager::getBitmapFont ( BitmapFontHandle handle) const

Definition at line 1156 of file ResourceManager.cpp.

◆ getBitmapFontRefCount()

u32 esengine::resource::ResourceManager::getBitmapFontRefCount ( BitmapFontHandle handle) const

Gets the current reference count for a bitmap font.

Parameters
handleThe font handle
Returns
Reference count, or 0 if invalid

Definition at line 1166 of file ResourceManager.cpp.

◆ getEnvironment() [1/2]

Environment * esengine::resource::ResourceManager::getEnvironment ( EnvironmentHandle handle)

The environment a handle names, or null.

Definition at line 1007 of file ResourceManager.cpp.

◆ getEnvironment() [2/2]

const Environment * esengine::resource::ResourceManager::getEnvironment ( EnvironmentHandle handle) const

Definition at line 1011 of file ResourceManager.cpp.

◆ getIndexBuffer() [1/2]

IndexBuffer * esengine::resource::ResourceManager::getIndexBuffer ( IndexBufferHandle handle)

Gets an index buffer by handle.

Parameters
handleThe buffer handle
Returns
Pointer to the buffer, or nullptr if invalid

Definition at line 1100 of file ResourceManager.cpp.

◆ getIndexBuffer() [2/2]

const IndexBuffer * esengine::resource::ResourceManager::getIndexBuffer ( IndexBufferHandle handle) const

Gets an index buffer by handle (const).

Parameters
handleThe buffer handle
Returns
Const pointer to the buffer, or nullptr if invalid

Definition at line 1104 of file ResourceManager.cpp.

◆ getMesh() [1/2]

Mesh * esengine::resource::ResourceManager::getMesh ( MeshHandle handle)

The mesh a handle names, or null.

Definition at line 927 of file ResourceManager.cpp.

Referenced by esengine::gatherLodLevels(), and esengine::placementCoarseMesh().

◆ getMesh() [2/2]

const Mesh * esengine::resource::ResourceManager::getMesh ( MeshHandle handle) const

Definition at line 931 of file ResourceManager.cpp.

◆ getProbeVolume() [1/2]

ProbeVolume * esengine::resource::ResourceManager::getProbeVolume ( ProbeVolumeHandle handle)

The probe volume a handle names, or null.

Definition at line 1064 of file ResourceManager.cpp.

◆ getProbeVolume() [2/2]

const ProbeVolume * esengine::resource::ResourceManager::getProbeVolume ( ProbeVolumeHandle handle) const

Definition at line 1068 of file ResourceManager.cpp.

◆ getShader() [1/2]

Shader * esengine::resource::ResourceManager::getShader ( ShaderHandle handle)

Gets a shader by handle.

Parameters
handleThe shader handle
Returns
Pointer to the shader, or nullptr if invalid

Definition at line 191 of file ResourceManager.cpp.

Referenced by esengine::MaterialStore::meshProgram(), esengine::MaterialStore::prepassCoverageProgram(), and esengine::MaterialStore::shadowProgram().

◆ getShader() [2/2]

const Shader * esengine::resource::ResourceManager::getShader ( ShaderHandle handle) const

Gets a shader by handle (const).

Parameters
handleThe shader handle
Returns
Const pointer to the shader, or nullptr if invalid

Definition at line 195 of file ResourceManager.cpp.

◆ getShaderRefCount()

u32 esengine::resource::ResourceManager::getShaderRefCount ( ShaderHandle handle) const

Gets the current reference count for a shader.

Parameters
handleThe shader handle
Returns
Reference count, or 0 if invalid

Definition at line 207 of file ResourceManager.cpp.

Referenced by esengine::rm_getShaderRefCount().

◆ getStats()

ResourceStats esengine::resource::ResourceManager::getStats ( ) const

Gets current resource statistics.

Returns
Resource counts and cache statistics

Definition at line 1174 of file ResourceManager.cpp.

References esengine::resource::ResourceStats::shaderCount.

◆ getTexture() [1/2]

Texture * esengine::resource::ResourceManager::getTexture ( TextureHandle handle)

Gets a texture by handle.

Parameters
handleThe texture handle
Returns
Pointer to the texture, or nullptr if invalid

Definition at line 295 of file ResourceManager.cpp.

Referenced by esengine::text::BitmapFont::loadFromFntText(), esengine::rm_createTextureEx(), esengine::rm_getTextureGLId(), and esengine::rm_updateTextureSubregion().

◆ getTexture() [2/2]

const Texture * esengine::resource::ResourceManager::getTexture ( TextureHandle handle) const

Gets a texture by handle (const).

Parameters
handleThe texture handle
Returns
Const pointer to the texture, or nullptr if invalid

Definition at line 299 of file ResourceManager.cpp.

◆ getTextureByGUID()

TextureHandle esengine::resource::ResourceManager::getTextureByGUID ( const std::string & guid) const

Gets a texture handle by GUID if already loaded.

Parameters
guidAsset GUID
Returns
Handle to the texture, or invalid handle if not loaded

Definition at line 464 of file ResourceManager.cpp.

◆ getTextureMetadata()

const TextureMetadata * esengine::resource::ResourceManager::getTextureMetadata ( TextureHandle handle) const

Gets metadata for a texture.

Parameters
handleThe texture handle
Returns
Pointer to metadata, or nullptr if not set

Definition at line 491 of file ResourceManager.cpp.

References esengine::resource::Handle< T >::id(), and esengine::resource::Handle< T >::isValid().

◆ getTexturePath()

const std::string & esengine::resource::ResourceManager::getTexturePath ( TextureHandle handle) const

Gets the cached path for a texture.

Parameters
handleThe texture handle
Returns
The path used to load the texture, or empty if not found

Definition at line 405 of file ResourceManager.cpp.

Referenced by esengine::rm_texturesAwaitingReupload().

◆ getTextureRefCount()

u32 esengine::resource::ResourceManager::getTextureRefCount ( TextureHandle handle) const

Gets the current reference count for a texture.

Parameters
handleThe texture handle
Returns
Reference count, or 0 if invalid

Definition at line 323 of file ResourceManager.cpp.

Referenced by esengine::rm_getTextureRefCount().

◆ getVertexBuffer() [1/2]

VertexBuffer * esengine::resource::ResourceManager::getVertexBuffer ( VertexBufferHandle handle)

Gets a vertex buffer by handle.

Parameters
handleThe buffer handle
Returns
Pointer to the buffer, or nullptr if invalid

Definition at line 525 of file ResourceManager.cpp.

◆ getVertexBuffer() [2/2]

const VertexBuffer * esengine::resource::ResourceManager::getVertexBuffer ( VertexBufferHandle handle) const

Gets a vertex buffer by handle (const).

Parameters
handleThe buffer handle
Returns
Const pointer to the buffer, or nullptr if invalid

Definition at line 529 of file ResourceManager.cpp.

◆ hasTextureMetadata()

bool esengine::resource::ResourceManager::hasTextureMetadata ( TextureHandle handle) const

Checks if a texture has metadata.

Parameters
handleThe texture handle
Returns
True if metadata is set

Definition at line 500 of file ResourceManager.cpp.

References esengine::resource::Handle< T >::id(), and esengine::resource::Handle< T >::isValid().

◆ init()

void esengine::resource::ResourceManager::init ( GfxDevice & device)

Initializes the resource manager.

Parameters
deviceThe graphics device used to create all GPU resources (shaders, textures, buffers). ResourceManager is the GPU-resource factory, so it owns the single device reference the resource classes route through.

Definition at line 51 of file ResourceManager.cpp.

References device(), and ES_LOG_WARN.

◆ invalidateTexturePath()

bool esengine::resource::ResourceManager::invalidateTexturePath ( const std::string & path)

Severs a path's texture-cache identity (hot reload). The next acquireTextureByPath for it misses, so stale bytes are never revived; an evictable entry under that path is freed immediately.

Parameters
pathThe path to invalidate
Returns
True if the path was registered

Definition at line 441 of file ResourceManager.cpp.

Referenced by esengine::rm_invalidateTexturePath().

◆ isInitialized()

bool esengine::resource::ResourceManager::isInitialized ( ) const
inline

Checks if the manager is initialized.

Returns
True if init() has been called

Definition at line 149 of file ResourceManager.hpp.

◆ loadBitmapFont()

BitmapFontHandle esengine::resource::ResourceManager::loadBitmapFont ( const std::string & fntPath)

Definition at line 1118 of file ResourceManager.cpp.

References ES_LOG_ERROR.

◆ loadShader()

ShaderHandle esengine::resource::ResourceManager::loadShader ( const std::string & vertPath,
const std::string & fragPath )

Loads a shader from file paths (with caching).

Parameters
vertPathPath to vertex shader file
fragPathPath to fragment shader file
Returns
Handle to the shader, or invalid handle on failure

Definition at line 167 of file ResourceManager.cpp.

References esengine::Shader::createFromFile().

◆ loadTexture()

TextureHandle esengine::resource::ResourceManager::loadTexture ( const std::string & path)

Loads a texture from file (with caching).

Parameters
pathPath to the image file
Returns
Handle to the texture, or invalid handle on failure

Definition at line 280 of file ResourceManager.cpp.

References ES_LOG_ERROR.

Referenced by esengine::text::BitmapFont::loadFromFntText(), and loadTextureByGUID().

◆ loadTextureByGUID()

TextureHandle esengine::resource::ResourceManager::loadTextureByGUID ( const std::string & guid,
const std::string & path )

Loads a texture by GUID (with caching).

Parameters
guidAsset GUID from AssetDatabase
pathFile path to load if not cached
Returns
Handle to the texture, or invalid handle on failure

Definition at line 449 of file ResourceManager.cpp.

References esengine::resource::Handle< T >::isValid(), and loadTexture().

◆ meshEdgeBuffers()

bool esengine::resource::ResourceManager::meshEdgeBuffers ( ) const
inline

Definition at line 549 of file ResourceManager.hpp.

◆ meshesAwaitingRematerialization()

std::vector< MeshHandle > esengine::resource::ResourceManager::meshesAwaitingRematerialization ( ) const

Replayable meshes whose geometry the device is still waiting for.

Read off the device's ledger, so the list empties exactly when a rematerialization has put the geometry back.

Definition at line 944 of file ResourceManager.cpp.

Referenced by esengine::rm_meshesAwaitingRemat().

◆ meshesRevision()

u64 esengine::resource::ResourceManager::meshesRevision ( ) const
inline

Changes whenever any mesh is realized (each takes a new Mesh::revision) or released: while it holds, every mesh a reader looked at is the one it was.

Definition at line 562 of file ResourceManager.hpp.

Referenced by esengine::ecs::UISystem::hitInputsChanged().

◆ meshPageBytes()

u64 esengine::resource::ResourceManager::meshPageBytes ( ) const
inline

Definition at line 748 of file ResourceManager.hpp.

◆ meshPageCount()

u32 esengine::resource::ResourceManager::meshPageCount ( ) const
inline

The shared mesh pages standing and the bytes they hold, for a profiler.

Definition at line 747 of file ResourceManager.hpp.

◆ meshRealizations()

std::vector< ResourceManager::MeshRealization > esengine::resource::ResourceManager::meshRealizations ( )

Every live mesh, for a recovery criterion to read.

Definition at line 935 of file ResourceManager.cpp.

References esengine::Mesh::hasRealization(), and esengine::resource::Handle< T >::id().

Referenced by esengine::rm_meshRealizations().

◆ operator=() [1/2]

ResourceManager & esengine::resource::ResourceManager::operator= ( const ResourceManager & )
delete

References ResourceManager().

◆ operator=() [2/2]

ResourceManager & esengine::resource::ResourceManager::operator= ( ResourceManager && )
default

References ResourceManager(), and device().

◆ preferredShaderLanguage()

GfxShaderLanguage esengine::resource::ResourceManager::preferredShaderLanguage ( ) const

The language embedded pipelines must author their sources in.

GLSL when the backend compiles it (the GL device); otherwise the backend's own language (WGSL). Embedded shader creation sites branch on this to pick the .esshader assembly or its WGSL twin — the one seam that keeps plugins backend-agnostic.

Definition at line 103 of file ResourceManager.cpp.

References esengine::GLSL_ES300, and esengine::WGSL.

Referenced by preferredShaderTarget(), esengine::MaterialStore::prepassCoverageProgram(), and esengine::MaterialStore::shadowProgram().

◆ preferredShaderTarget()

ShaderTargetLanguage esengine::resource::ResourceManager::preferredShaderTarget ( ) const

preferredShaderLanguage() as a ShaderParser assembly target.

The other half of the seam: creation sites parse one .esshader (whose WGSL twin rides the same file) and assemble both stages for this target — no per-backend branches.

Definition at line 109 of file ResourceManager.cpp.

References esengine::resource::GLSL_ES300, preferredShaderLanguage(), esengine::WGSL, and esengine::resource::WGSL.

Referenced by esengine::MaterialStore::prepassCoverageProgram(), and esengine::MaterialStore::shadowProgram().

◆ registerExternalTexture()

TextureHandle esengine::resource::ResourceManager::registerExternalTexture ( ResourceContent content,
u32 glTextureId,
u32 width,
u32 height,
usize bytes = 0 )

Registers an externally-created GL texture.

Parameters
glTextureIdThe OpenGL texture ID
widthTexture width in pixels
heightTexture height in pixels
bytesActual GPU size for the eviction budget; 0 = estimate as RGBA8 (width × height × 4). Compressed uploads (KTX2 → ASTC/ETC2/S3TC) pass their real block size, 4–8× smaller — billing them as RGBA8 would waste most of the budget.
Returns
Handle to the registered texture

Definition at line 327 of file ResourceManager.cpp.

References esengine::Texture::createFromExternalId(), ES_LOG_ERROR, esengine::Invalid, esengine::RGBA8, and esengine::resource::toGfxContent().

Referenced by esengine::rm_registerExternalTexture(), and esengine::rm_registerExternalTextureSized().

◆ registerTextureWithPath()

void esengine::resource::ResourceManager::registerTextureWithPath ( TextureHandle handle,
const std::string & path )

Registers a texture with a path for cache lookup.

Parameters
handleThe texture handle
pathThe path to associate (used by loadTexture cache)

Definition at line 399 of file ResourceManager.cpp.

References esengine::resource::Handle< T >::isValid().

Referenced by esengine::rm_registerTextureWithPath().

◆ releaseBitmapFont()

void esengine::resource::ResourceManager::releaseBitmapFont ( BitmapFontHandle handle)

◆ releaseEnvironment()

void esengine::resource::ResourceManager::releaseEnvironment ( EnvironmentHandle handle)

Releases an environment. The atlas is an ordinary texture asset with its own lifetime, so it is NOT released here.

Definition at line 1015 of file ResourceManager.cpp.

References esengine::resource::Handle< T >::id().

◆ releaseIndexBuffer()

void esengine::resource::ResourceManager::releaseIndexBuffer ( IndexBufferHandle handle)

Releases an index buffer (decrements ref count).

Parameters
handleThe buffer handle

Definition at line 1108 of file ResourceManager.cpp.

References esengine::resource::Handle< T >::id(), and esengine::resource::Handle< T >::isValid().

Referenced by releaseMesh().

◆ releaseMesh()

◆ releaseProbeVolume()

void esengine::resource::ResourceManager::releaseProbeVolume ( ProbeVolumeHandle handle)

Releases a probe volume.

Definition at line 1072 of file ResourceManager.cpp.

References esengine::resource::Handle< T >::id().

◆ releaseShader()

void esengine::resource::ResourceManager::releaseShader ( ShaderHandle handle)

Releases a shader (decrements ref count).

Parameters
handleThe shader handle

Definition at line 199 of file ResourceManager.cpp.

References esengine::resource::Handle< T >::id(), and esengine::resource::Handle< T >::isValid().

Referenced by esengine::MaterialStore::prepassCoverageProgram(), esengine::rm_releaseShader(), and esengine::MaterialStore::shadowProgram().

◆ releaseTexture()

void esengine::resource::ResourceManager::releaseTexture ( TextureHandle handle)

Releases a texture (decrements ref count).

Parameters
handleThe texture handle

Definition at line 303 of file ResourceManager.cpp.

References esengine::resource::Handle< T >::id(), and esengine::resource::Handle< T >::isValid().

Referenced by releaseTextureByGUID(), and esengine::rm_releaseTexture().

◆ releaseTextureByGUID()

void esengine::resource::ResourceManager::releaseTextureByGUID ( const std::string & guid)

Releases a texture by GUID.

Parameters
guidAsset GUID

Definition at line 472 of file ResourceManager.cpp.

References releaseTexture().

◆ releaseVertexBuffer()

void esengine::resource::ResourceManager::releaseVertexBuffer ( VertexBufferHandle handle)

Releases a vertex buffer (decrements ref count).

Parameters
handleThe buffer handle

Definition at line 533 of file ResourceManager.cpp.

References esengine::resource::Handle< T >::id(), and esengine::resource::Handle< T >::isValid().

◆ rematerializeMesh()

bool esengine::resource::ResourceManager::rematerializeMesh ( MeshHandle target,
ConstSpan< u8 > vertexBytes,
ConstSpan< u32 > indices,
ConstSpan< GfxVertexAttribute > channels,
u32 vertexStride,
const glm::vec3 & localMin,
const glm::vec3 & localMax,
ConstSpan< f32 > inverseBind = {},
const MeshMorphSource & morph = {} )

Puts new geometry behind an EXISTING mesh handle.

Same identity, a fresh realization. Re-uploading through createMesh would mint a SECOND handle and leave every component on the dead one. Refuses a host-only mesh; clears the debt only on success.

Returns
False if the handle names no live mesh, is not replayable, or the geometry could not be rebuilt.

Definition at line 848 of file ResourceManager.cpp.

References ES_LOG_ERROR, esengine::resource::Handle< T >::id(), esengine::Mesh::recovery, and esengine::SourceReplayable.

Referenced by esengine::mesh_rematerializeFromChannels().

◆ removeTextureMetadata()

void esengine::resource::ResourceManager::removeTextureMetadata ( TextureHandle handle)

Removes metadata for a texture.

Parameters
handleThe texture handle

Definition at line 505 of file ResourceManager.cpp.

References esengine::resource::Handle< T >::id(), and esengine::resource::Handle< T >::isValid().

◆ resetCacheStats()

void esengine::resource::ResourceManager::resetCacheStats ( )

Resets cache hit/miss counters.

Definition at line 1186 of file ResourceManager.cpp.

◆ restoreTextureContent()

void esengine::resource::ResourceManager::restoreTextureContent ( TextureHandle handle)

Settles an owed texture whose provider wrote the pixels itself.

See GfxDevice::restoreContent — for a JS-side upload straight into the native texture, which the device cannot see.

Definition at line 383 of file ResourceManager.cpp.

References esengine::Texture::getId(), and esengine::GfxOwedContent::Texture.

Referenced by esengine::rm_restoreTextureContent().

◆ setMeshClusters()

bool esengine::resource::ResourceManager::setMeshClusters ( MeshHandle target,
lod::ClusterHierarchy hierarchy )

Uploads geometry that stays on the GPU, drawn from its own buffers.

The frame's transient pool, which every renderable uses today, is rewritten by the CPU each frame — a per-frame re-upload of anything that does not change. The layout travels with the buffers: one whose attribute description lives elsewhere is a rename from garbage. Every caller is a mesh PRODUCER and owes a row in tools/meshProducers.mjs saying how the handles it mints come back after a device generation ends; check-mesh-provenance keeps that census closed in both directions.

Parameters
vertexBytesRaw vertex data, laid out as layout describes.
indicesTriangle-list indices into it.
Returns
Handle to the mesh, or invalid on failure.

Gives a realized mesh its cluster hierarchy, which a view then draws it through.

Returns
False, and the mesh stays one drawn whole, when the handle names no mesh or the hierarchy names an index run or a vertex the mesh does not have.

Definition at line 910 of file ResourceManager.cpp.

References esengine::lod::clusterHierarchyValid(), esengine::Mesh::clusters, ES_LOG_ERROR, esengine::resource::Handle< T >::id(), esengine::nextRevision(), esengine::Mesh::revision, and esengine::Mesh::vertexCount.

◆ setMeshEdgeBuffers()

void esengine::resource::ResourceManager::setMeshEdgeBuffers ( bool enabled)
inline

Whether meshes realized FROM NOW ON also get an edge buffer.

Diagnostic geometry for a wireframe view, off by default because it is a second index buffer per mesh. Set before the assets load: a mesh realized earlier has no edges, and a view that wants them draws it filled.

Definition at line 548 of file ResourceManager.hpp.

◆ setMeshSkinChunks()

bool esengine::resource::ResourceManager::setMeshSkinChunks ( MeshHandle target,
std::vector< MeshSkinChunk > chunks,
std::vector< u16 > bones )

Gives a realized skinned mesh the chunks it is drawn in (Mesh::skinChunks).

Returns
False, and the mesh is drawn as before, when the handle names no skinned mesh or the chunks do not tile its indices in order, name more bones than one draw carries, or name a joint it has no bind matrix for.

Definition at line 874 of file ResourceManager.cpp.

References ES_LOG_ERROR, esengine::resource::Handle< T >::id(), esengine::Mesh::indexCount, esengine::Mesh::inverseBind, esengine::Mesh::isSkinned(), esengine::MESH_MAX_BONES, esengine::nextRevision(), esengine::Mesh::revision, esengine::Mesh::skinChunkBones, and esengine::Mesh::skinChunks.

◆ setRetainedBudget()

void esengine::resource::ResourceManager::setRetainedBudget ( usize bytes)

◆ setShaderRetiredCallback()

void esengine::resource::ResourceManager::setShaderRetiredCallback ( void * owner,
ShaderRetiredCallback callback )
inline

Definition at line 229 of file ResourceManager.hpp.

Referenced by esengine::MaterialStore::setResourceManager().

◆ setTextureBudget()

void esengine::resource::ResourceManager::setTextureBudget ( usize bytes)

Sets the texture pool's resident-byte budget (0 = no eviction). Over budget, refCount==0 textures are evicted oldest-first.

Definition at line 409 of file ResourceManager.cpp.

Referenced by esengine::rm_setTextureBudget().

◆ setTextureMetadata()

void esengine::resource::ResourceManager::setTextureMetadata ( TextureHandle handle,
const TextureMetadata & metadata )

Sets metadata for a texture.

Parameters
handleThe texture handle
metadataThe metadata to associate

Definition at line 484 of file ResourceManager.cpp.

References esengine::resource::Handle< T >::id(), and esengine::resource::Handle< T >::isValid().

Referenced by esengine::rm_setTextureMetadata().

◆ shutdown()

void esengine::resource::ResourceManager::shutdown ( )

Shuts down and releases all resources.

Definition at line 64 of file ResourceManager.cpp.

References ES_LOG_INFO, and releaseMesh().

◆ textureMetadataRevision()

u64 esengine::resource::ResourceManager::textureMetadataRevision ( ) const
inline

Moves whenever a texture's metadata (its nine-slice borders and the rest) is set or dropped.

Definition at line 564 of file ResourceManager.hpp.

◆ textureNativeId()

u32 esengine::resource::ResourceManager::textureNativeId ( TextureHandle handle) const

The backend's own name for a texture's object, for a host that writes its pixels itself; 0 when there is none. See GfxDevice::nativeTextureName.

Definition at line 394 of file ResourceManager.cpp.

References esengine::Texture::handle().

Referenced by esengine::rm_getTextureNativeId().

◆ texturesAwaitingReupload()

std::vector< ResourceManager::OwedTexture > esengine::resource::ResourceManager::texturesAwaitingReupload ( ) const

◆ trimTextureCache()

usize esengine::resource::ResourceManager::trimTextureCache ( )

Frees every evictable cached texture now (memory pressure). Held textures and the budget are untouched.

Returns
Number of textures freed

Definition at line 445 of file ResourceManager.cpp.

Referenced by esengine::rm_trimTextureCache().

◆ update()

void esengine::resource::ResourceManager::update ( )

Updates resource manager (processes hot reload, call once per frame).

Definition at line 95 of file ResourceManager.cpp.

◆ wrapDeviceTexture()

TextureHandle esengine::resource::ResourceManager::wrapDeviceTexture ( ::esengine::TextureHandle texture,
u32 width,
u32 height )

Names a texture the device holds for another owner (a render target's colour plane) by a resource handle, without taking it over.

Definition at line 342 of file ResourceManager.cpp.

References esengine::Texture::borrow().

Referenced by esengine::rm_wrapDeviceTexture().


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