37#include <unordered_map>
191 bool rewriteLoose =
true,
193 bool deferLink =
false);
195 std::initializer_list<AttribBinding> bindings,
197 bool deferLink =
false);
230 shaderRetiredOwner_ = owner; shaderRetiredCallback_ = callback;
233 if (shaderRetiredOwner_ == owner) { shaderRetiredOwner_ =
nullptr; shaderRetiredCallback_ =
nullptr; }
524 const glm::vec3& localMin,
const glm::vec3& localMax,
539 const glm::vec3& localMin,
const glm::vec3& localMax,
540 ConstSpan<f32> inverseBind = {},
const MeshMorphSource& morph = {});
594 f32 faceSize,
u32 mipCount,
f32 maxRange,
694 u32 texWidth,
u32 texHeight);
697 u32 texWidth,
u32 texHeight,
698 const std::string& chars,
699 u32 charWidth,
u32 charHeight);
728 void* shaderRetiredOwner_ =
nullptr;
734 bool meshEdges_ =
false;
739 u64 meshes_revision_ = 0;
740 u64 texture_metadata_revision_ = 0;
743 u32 arenaPage,
u32 arenaFirstVertex,
u32 vertexCount,
u32 firstIndex,
u32 indexCount);
759 const glm::vec3& localMin,
const glm::vec3& localMax,
766 std::unordered_map<std::string, TextureHandle> guidToTexture_;
767 std::unordered_map<TextureHandle::IdType, TextureMetadata> textureMetadata_;
770 bool initialized_ =
false;
781 return vertexBuffers_.add(std::move(buffer));
GPU buffer abstractions for vertex and index data.
A baked environment: what a surface sees when no light faces it.
Type-safe resource handle system.
Meshes of one vertex shape sharing a vertex buffer, an index buffer and a layout.
Geometry that lives on the GPU rather than in a frame.
A baked environment sampled on a grid, rather than held at one value.
Type-erased resource pool with reference counting.
GPU shader program abstraction.
Texture metadata structures for nine-slice and other settings.
GPU texture abstraction for 2D images.
Core type definitions and utilities for ESEngine.
The two halves of an image-based light, as the importer baked them.
A content policy. provider names who refills a Sourced object and key what it refills; both are the p...
Abstract graphics device interface.
GPU buffer for index data.
Buffers, the layout that describes them, and the bounds culling reads.
Irradiance at a grid of points — an Environment sampled, not held.
GPU shader program for rendering.
2D texture for GPU rendering
GPU buffer for vertex data, static or dynamic; all GPU work goes through the device.
static Unique< VertexBuffer > create(GfxDevice &device, GfxContent content, std::span< const T > data)
Creates a static buffer from a span.
u64 textureMetadataRevision() const
Moves whenever a texture's metadata (its nine-slice borders and the rest) is set or dropped.
void update()
Updates resource manager (processes hot reload, call once per frame).
u32 meshPageCount() const
void(*)(void *, ShaderHandle) ShaderRetiredCallback
One renderer owns shader-derived metadata. Notify after final pool retirement.
ShaderHandle loadShader(const std::string &vertPath, const std::string &fragPath)
Loads a shader from file paths (with caching).
Texture * getTexture(TextureHandle handle)
Gets a texture by handle.
ShaderTargetLanguage preferredShaderTarget() const
preferredShaderLanguage() as a ShaderParser assembly target.
u32 getTextureRefCount(TextureHandle handle) const
Gets the current reference count for a texture.
ProbeVolumeHandle createProbeVolumeBricks(const glm::ivec3 &resolution, ConstSpan< i32 > bricks, ConstSpan< f32 > irradiance)
Registers a SPARSE grid: bricks at their own spacing (see ProbeVolume).
ShaderHandle createShaderWithBindings(const std::string &vertSrc, const std::string &fragSrc, std::initializer_list< AttribBinding > bindings, GfxShaderLanguage language=GfxShaderLanguage::GLSL_ES300, bool deferLink=false)
bool deferLinks() const
Creates a shader from source strings.
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...
void forgoTextureContent(TextureHandle handle)
Gives up on an owed texture's content: it keeps blank storage.
void releaseVertexBuffer(VertexBufferHandle handle)
Releases a vertex buffer (decrements ref count).
void releaseIndexBuffer(IndexBufferHandle handle)
Releases an index buffer (decrements ref count).
BitmapFontHandle createLabelAtlasFont(TextureHandle texture, u32 texWidth, u32 texHeight, const std::string &chars, u32 charWidth, u32 charHeight)
BitmapFontHandle loadBitmapFont(const std::string &fntPath)
u32 getBitmapFontRefCount(BitmapFontHandle handle) const
Gets the current reference count for a bitmap font.
const std::string & getTexturePath(TextureHandle handle) const
Gets the cached path for a texture.
ResourceManager & operator=(ResourceManager &&)=default
EnvironmentHandle createEnvironment(ConstSpan< f32 > irradiance, TextureHandle specular, f32 faceSize, u32 mipCount, f32 maxRange, u32 columns=1)
Registers a baked environment.
BitmapFontHandle createBitmapFont(const std::string &fntContent, TextureHandle texture, u32 texWidth, u32 texHeight)
IndexBufferHandle createIndexBuffer(GfxContent content, ConstSpan< u32 > indices)
Creates an index buffer from 32-bit indices.
void registerTextureWithPath(TextureHandle handle, const std::string &path)
Registers a texture with a path for cache lookup.
std::vector< OwedTexture > texturesAwaitingReupload() const
~ResourceManager()=default
void resetCacheStats()
Resets cache hit/miss counters.
u64 meshPageBytes() const
bool isInitialized() const
Checks if the manager is initialized.
std::vector< MeshHandle > meshesAwaitingRematerialization() const
Replayable meshes whose geometry the device is still waiting for.
void releaseMesh(MeshHandle handle)
Releases a mesh and the buffers it owns.
const TextureMetadata * getTextureMetadata(TextureHandle handle) const
Gets metadata for a texture.
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 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 han...
bool meshEdgeBuffers() const
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={})
GfxShaderLanguage preferredShaderLanguage() const
The language embedded pipelines must author their sources in.
GfxDevice * device() const
void releaseTextureByGUID(const std::string &guid)
Releases a texture by GUID.
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).
TextureHandle loadTexture(const std::string &path)
Loads a texture from file (with caching).
bool setMeshClusters(MeshHandle target, lod::ClusterHierarchy hierarchy)
Uploads geometry that stays on the GPU, drawn from its own buffers.
void releaseShader(ShaderHandle handle)
Releases a shader (decrements ref count).
VertexBuffer * getVertexBuffer(VertexBufferHandle handle)
Gets a vertex buffer by handle.
ProbeVolumeHandle createProbeVolume(const glm::ivec3 &resolution, ConstSpan< f32 > irradiance)
Registers a grid of baked irradiance.
Shader * getShader(ShaderHandle handle)
Gets a shader by handle.
void shutdown()
Shuts down and releases all resources.
void clearShaderRetiredCallback(void *owner)
ProbeVolume * getProbeVolume(ProbeVolumeHandle handle)
The probe volume a handle names, or null.
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...
text::BitmapFont * getBitmapFont(BitmapFontHandle handle)
ShaderHandle createShader(const std::string &vertSrc, const std::string &fragSrc, bool rewriteLoose=true, GfxShaderLanguage language=GfxShaderLanguage::GLSL_ES300, bool deferLink=false)
u32 getShaderRefCount(ShaderHandle handle) const
Gets the current reference count for a shader.
ResourceManager(ResourceManager &&)=default
void removeTextureMetadata(TextureHandle handle)
Removes metadata for a texture.
Mesh * getMesh(MeshHandle handle)
The mesh a handle names, or null.
std::vector< MeshRealization > meshRealizations()
Every live mesh, for a recovery criterion to read.
u64 meshesRevision() const
Changes whenever any mesh is realized (each takes a new Mesh::revision) or released: while it holds,...
ResourceManager(const ResourceManager &)=delete
void releaseProbeVolume(ProbeVolumeHandle handle)
Releases a probe volume.
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 restoreTextureContent(TextureHandle handle)
Settles an owed texture whose provider wrote the pixels itself.
ResourceStats getStats() const
Gets current resource statistics.
void releaseEnvironment(EnvironmentHandle handle)
Releases an environment. The atlas is an ordinary texture asset with its own lifetime,...
bool adoptTextureContent(TextureHandle target, TextureHandle source)
Moves a freshly loaded texture's pixels behind an owed handle.
bool invalidateTexturePath(const std::string &path)
Severs a path's texture-cache identity (hot reload). The next acquireTextureByPath for it misses,...
void setMeshEdgeBuffers(bool enabled)
Whether meshes realized FROM NOW ON also get an edge buffer.
Environment * getEnvironment(EnvironmentHandle handle)
The environment a handle names, or null.
TextureHandle createTexture(ResourceContent content, const TextureSpecification &spec)
Creates a texture from specification.
ResourceManager()=default
void setTextureMetadata(TextureHandle handle, const TextureMetadata &metadata)
Sets metadata for a texture.
IndexBuffer * getIndexBuffer(IndexBufferHandle handle)
Gets an index buffer by handle.
void init(GfxDevice &device)
Initializes the resource manager.
void releaseBitmapFont(BitmapFontHandle handle)
ResourceManager & operator=(const ResourceManager &)=delete
VertexBufferHandle createVertexBuffer(GfxContent content, ConstSpan< T > data)
Creates a vertex buffer from typed data.
void setRetainedBudget(usize bytes)
See GfxDevice::setRetainedBudget.
TextureHandle getTextureByGUID(const std::string &guid) const
Gets a texture handle by GUID if already loaded.
void releaseTexture(TextureHandle handle)
Releases a texture (decrements ref count).
TextureHandle registerExternalTexture(ResourceContent content, u32 glTextureId, u32 width, u32 height, usize bytes=0)
Registers an externally-created GL texture.
usize trimTextureCache()
Frees every evictable cached texture now (memory pressure). Held textures and the budget are untouche...
void setTextureBudget(usize bytes)
Sets the texture pool's resident-byte budget (0 = no eviction). Over budget, refCount==0 textures are...
TextureHandle acquireTextureByPath(const std::string &path)
Reuses a cached texture by its build path: returns its handle with an added reference (reviving an ev...
void setShaderRetiredCallback(void *owner, ShaderRetiredCallback callback)
TextureHandle loadTextureByGUID(const std::string &guid, const std::string &path)
Loads a texture by GUID (with caching).
bool hasTextureMetadata(TextureHandle handle) const
Checks if a texture has metadata.
Typed resource pool with reference counting.
ShaderTargetLanguage
Target language for stage assembly (REARCH_WGSL dual emission).
ResourceContent
Who refills a resource's GPU content after a device loss.
@ Asset
The asset layer loads it again from its path.
@ Retained
The device keeps the bytes (a tile collection composed at load).
@ Video
Refilled by the next decoded frame.
@ GlyphPage
Repainted from the glyphs placed on it.
@ Canvas
Redrawn from the canvas it mirrors.
@ AtlasPage
A skeleton's atlas page, decoded again from its image.
@ Composed
Composed again by its creator from its sources (a terrain's layer arrays).
@ Transient
Rewritten by its owner before every use (a video frame).
GfxContent toGfxContent(ResourceContent content)
The device's policy for a content code; unknown codes are Asset, the one that asks.
Handle< esengine::Shader > ShaderHandle
Handle to a shader resource.
Handle< esengine::text::BitmapFont > BitmapFontHandle
Handle to a bitmap font resource.
Handle< esengine::Environment > EnvironmentHandle
Handle to a baked environment (irradiance + prefiltered reflection).
Handle< esengine::IndexBuffer > IndexBufferHandle
Handle to an index buffer resource.
Handle< esengine::VertexBuffer > VertexBufferHandle
Handle to a vertex buffer resource.
Handle< esengine::Texture > TextureHandle
Handle to a texture resource.
Handle< esengine::ProbeVolume > ProbeVolumeHandle
Handle to a grid of baked irradiance.
Handle< esengine::Mesh > MeshHandle
Handle to GPU-resident geometry.
std::uint64_t u64
Unsigned 64-bit integer.
std::size_t usize
Size type for indexing and sizes.
MeshRecovery
How a mesh's geometry comes back after a device generation ends.
GfxShaderLanguage
Shader source language a backend consumes.
TextureFormat
Texture pixel format.
GfxCompressedFormat
GPU-compressed texture internal formats for createCompressedTexture.
std::span< const T > ConstSpan
std::uint32_t u32
Unsigned 32-bit integer.
std::uint8_t u8
Unsigned 8-bit integer.
float f32
32-bit floating point
The shapes handed to a realization: the deltas, and how to read them.
Texture creation parameters.
A mesh's clusters and the indices they name, every level together.
One live mesh and whether its geometry is on the device.
Textures the device is waiting for content for, with who refills them.
Statistics about resource usage.
usize indexBufferCount
Number of active index buffers.
usize shaderCount
Number of active shaders.
usize vertexBufferCount
Number of active vertex buffers.
usize retainedBytes
CPU copies the device keeps to restore content after a loss.
usize textureCount
Number of active textures.
usize cacheMisses
Number of cache misses since reset.
usize cacheHits
Number of cache hits since reset.
usize textureBytes
Resident texture bytes (RGBA8 estimate) — VRAM usage.
usize textureEvictableCount
Cached refCount==0 textures awaiting revive/evict.
usize textureBudget
Texture pool resident-byte budget (0 = eviction off).
Metadata associated with a texture resource.