|
Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
|
#include <TransientBufferPool.hpp>
Public Member Functions | |
| TransientBufferPool (GfxDevice &device) | |
| GfxDevice & | device () |
| The device the pool's buffers live on, for a plugin that keeps geometry of its own on it. | |
| void | init (u32 initialVertexBytes=2 *1024 *1024, u32 initialIndexCount=256 *1024) |
| void | shutdown () |
| void | beginFrame () |
| void | swap (TransientBufferPool &other) noexcept |
| Trades what the two pools hold, buffers and staging both; they must share one device. | |
| u32 | allocVertices (LayoutId layout, u32 byteSize) |
| u32 | allocIndices (LayoutId layout, u32 count) |
| void | writeVertices (LayoutId layout, u32 byteOffset, const void *data, u32 byteSize) |
| void | writeIndices (LayoutId layout, u32 indexOffset, const u32 *data, u32 count) |
| u32 | appendVertices (LayoutId layout, const void *data, u32 byteSize) |
| u32 | appendIndices (LayoutId layout, const u32 *data, u32 count) |
| bool | copyIndexRange (LayoutId layout, u32 offset, u32 count, u32 &copiedAt) |
| void | upload () |
| void | bindLayout (LayoutId layout) |
| void | bindInstanceLayout (LayoutId layout, u32 instanceByteOffset) |
| void | bindInstanceBuffer (LayoutId layout, BufferHandle instances) |
| void | reserveStream (LayoutId layout) |
| VertexLayoutHandle | layoutHandle (LayoutId layout) const |
| u32 | vertexStride (LayoutId layout) const |
| u8 * | vertexData (LayoutId layout) |
| u32 | vertexBytesUsed (LayoutId layout) const |
| u32 | indicesUsed (LayoutId layout) const |
| const u32 * | indexData (LayoutId layout) const |
| BufferHandle | vertexBuffer (LayoutId layout) const |
| BufferHandle | indexBuffer (LayoutId layout) const |
| TextureHandle | instanceTexture () const |
| The frame's per-object records. Invalid until a frame writes some. | |
Per-frame vertex/index staging with one independent VBO+EBO+vertex-layout per stream.
Design note: heterogeneous vertex formats (BatchVertex 20B, ShapeVertex 48B, ...) cannot safely share a single VBO because each plugin computes baseVertex = byteOffset / sizeof(OwnVertex). Once a prior plugin writes a non-multiple of the next plugin's vertex size, the next plugin's baseVertex truncates and the GPU reads garbage vertices. Giving each layout its own stream makes every offset "vertex 0" for that layout by construction — no alignment discipline needed at call sites, no cross-plugin coupling.
Definition at line 28 of file TransientBufferPool.hpp.
|
explicit |
Definition at line 158 of file TransientBufferPool.cpp.
Referenced by appendIndices(), and copyIndexRange().
Definition at line 146 of file TransientBufferPool.cpp.
Referenced by appendVertices().
Definition at line 184 of file TransientBufferPool.cpp.
References allocIndices(), and writeIndices().
Referenced by esengine::appendQuads().
| u32 esengine::TransientBufferPool::appendVertices | ( | LayoutId | layout, |
| const void * | data, | ||
| u32 | byteSize ) |
Definition at line 178 of file TransientBufferPool.cpp.
References allocVertices(), and writeVertices().
Referenced by esengine::appendIndexedDraw(), and esengine::appendQuads().
| void esengine::TransientBufferPool::beginFrame | ( | ) |
Definition at line 56 of file TransientBufferPool.cpp.
| void esengine::TransientBufferPool::bindInstanceBuffer | ( | LayoutId | layout, |
| BufferHandle | instances ) |
The same layout with the per-instance slot taken from instances whole — records a compute kernel wrote.
Definition at line 259 of file TransientBufferPool.cpp.
Referenced by esengine::DrawList::execute().
Bind an instanced stream with its per-instance buffer rebased to instanceByteOffset. GLES3 has no baseInstance, so each emitter's instanced draw rebases the instance slot here before drawElementsInstanced. The static quad slot is untouched.
Definition at line 252 of file TransientBufferPool.cpp.
Referenced by bindLayout(), and esengine::DrawList::execute().
| void esengine::TransientBufferPool::bindLayout | ( | LayoutId | layout | ) |
Bind this stream's vertex + index buffers for the next draw.
Definition at line 242 of file TransientBufferPool.cpp.
References bindInstanceLayout(), and esengine::ParticleInstance.
Referenced by esengine::DrawList::execute().
| bool esengine::TransientBufferPool::copyIndexRange | ( | LayoutId | layout, |
| u32 | offset, | ||
| u32 | count, | ||
| u32 & | copiedAt ) |
Copy a valid written range to the stream tail; false leaves the stream unchanged.
Definition at line 286 of file TransientBufferPool.cpp.
References allocIndices().
|
inline |
The device the pool's buffers live on, for a plugin that keeps geometry of its own on it.
Definition at line 33 of file TransientBufferPool.hpp.
Referenced by TransientBufferPool().
| BufferHandle esengine::TransientBufferPool::indexBuffer | ( | LayoutId | layout | ) | const |
Definition at line 301 of file TransientBufferPool.cpp.
Definition at line 282 of file TransientBufferPool.cpp.
Definition at line 278 of file TransientBufferPool.cpp.
| void esengine::TransientBufferPool::init | ( | u32 | initialVertexBytes = 2 * 1024 * 1024, |
| u32 | initialIndexCount = 256 * 1024 ) |
Initialize layouts; stream storage is allocated on its first non-empty write.
Definition at line 16 of file TransientBufferPool.cpp.
References esengine::Batch, esengine::MeshInstance, esengine::ParticleInstance, esengine::Shape, and esengine::Sky.
|
inline |
The frame's per-object records. Invalid until a frame writes some.
Definition at line 97 of file TransientBufferPool.hpp.
References esengine::MeshInstance.
Referenced by esengine::DrawList::execute().
| VertexLayoutHandle esengine::TransientBufferPool::layoutHandle | ( | LayoutId | layout | ) | const |
The device vertex layout a pipeline drawing this stream must reference.
Definition at line 266 of file TransientBufferPool.cpp.
Referenced by esengine::DrawList::execute().
|
inline |
Creates a stream's static buffers (a particle's quad and indices) without writing to it: a draw whose records live elsewhere still needs them, and nothing else would ask.
Definition at line 77 of file TransientBufferPool.hpp.
| void esengine::TransientBufferPool::shutdown | ( | ) |
Definition at line 30 of file TransientBufferPool.cpp.
References esengine::Invalid.
|
inlinenoexcept |
Trades what the two pools hold, buffers and staging both; they must share one device.
Definition at line 43 of file TransientBufferPool.hpp.
References TransientBufferPool().
| void esengine::TransientBufferPool::upload | ( | ) |
Upload every non-empty stream's staging to its VBO/EBO.
Definition at line 190 of file TransientBufferPool.cpp.
References ES_PROFILE_COUNTER, esengine::Invalid, and esengine::MeshInstance.
| BufferHandle esengine::TransientBufferPool::vertexBuffer | ( | LayoutId | layout | ) | const |
Definition at line 297 of file TransientBufferPool.cpp.
Definition at line 274 of file TransientBufferPool.cpp.
Referenced by esengine::DrawList::contentHashOfRecords().
Direct write-through pointer into a layout's staging, for hot paths that want to format vertices in place after allocVertices.
Definition at line 270 of file TransientBufferPool.cpp.
Referenced by esengine::DrawList::contentHashOfRecords().
Byte stride of this stream's writable vertex slot (the per-instance slot for ParticleInstance) — the single source for baseVertex math, so submission code never hardcodes a sizeof that could drift from the device layout.
Definition at line 305 of file TransientBufferPool.cpp.
Referenced by esengine::appendIndexedDraw(), and esengine::appendQuads().
| void esengine::TransientBufferPool::writeIndices | ( | LayoutId | layout, |
| u32 | indexOffset, | ||
| const u32 * | data, | ||
| u32 | count ) |
Definition at line 174 of file TransientBufferPool.cpp.
Referenced by appendIndices().
| void esengine::TransientBufferPool::writeVertices | ( | LayoutId | layout, |
| u32 | byteOffset, | ||
| const void * | data, | ||
| u32 | byteSize ) |
Definition at line 170 of file TransientBufferPool.cpp.
Referenced by appendVertices().