Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(render): per-layout vertex streams eliminate baseVertex alignment bug

esengineaf94b876fda3
diff --git a/src/esengine/renderer/RenderFrameSubmit.cpp b/src/esengine/renderer/RenderFrameSubmit.cpp
index 3d084d527..eb683b1b6 100644
--- a/src/esengine/renderer/RenderFrameSubmit.cpp
+++ b/src/esengine/renderer/RenderFrameSubmit.cpp
@@ -28,14 +28,14 @@ void RenderFrame::submitTileQuad(
verts[2] = { {position.x + hw, position.y + hh}, pc, {uvOffset.x + uvScale.x, uvOffset.y + uvScale.y} };
verts[3] = { {position.x - hw, position.y + hh}, pc, {uvOffset.x, uvOffset.y + uvScale.y} };
- u32 vOff = pool_.appendVertices(verts, sizeof(verts));
+ u32 vOff = pool_.appendVertices(LayoutId::Batch, verts, sizeof(verts));
u32 baseVertex = vOff / sizeof(BatchVertex);
u16 indices[6];
for (u32 i = 0; i < 6; ++i) {
indices[i] = static_cast<u16>(baseVertex + TILE_QUAD_IDX[i]);
}
- u32 iOff = pool_.appendIndices(indices, 6);
+ u32 iOff = pool_.appendIndices(LayoutId::Batch, indices, 6);
DrawCommand cmd{};
cmd.sort_key = DrawCommand::buildSortKey(
@@ -72,8 +72,8 @@ void RenderFrame::submitSpineBatch(
BlendMode blend = static_cast<BlendMode>(std::clamp(blendMode, 0, 5));
u32 vBytes = static_cast<u32>(vertexCount) * sizeof(BatchVertex);
- u32 vOff = pool_.allocVertices(vBytes);
- auto* dst = reinterpret_cast<BatchVertex*>(pool_.vertexData() + vOff);
+ u32 vOff = pool_.allocVertices(LayoutId::Batch, vBytes);
+ auto* dst = reinterpret_cast<BatchVertex*>(pool_.vertexData(LayoutId::Batch) + vOff);
for (i32 i = 0; i < vertexCount; ++i) {
const f32* v = vertices + i * FLOATS_PER_VERTEX;
@@ -87,7 +87,7 @@ void RenderFrame::submitSpineBatch(
for (i32 i = 0; i < indexCount; ++i) {
offsetIndices[i] = static_cast<u16>(baseVertex + indices[i]);
}
- u32 iOff = pool_.appendIndices(offsetIndices.data(), static_cast<u32>(indexCount));
+ u32 iOff = pool_.appendIndices(LayoutId::Batch, offsetIndices.data(), static_cast<u32>(indexCount));
DrawCommand cmd{};
cmd.sort_key = DrawCommand::buildSortKey(
diff --git a/src/esengine/renderer/TransientBufferPool.cpp b/src/esengine/renderer/TransientBufferPool.cpp
index a70003ed6..ad8b6f488 100644
--- a/src/esengine/renderer/TransientBufferPool.cpp
+++ b/src/esengine/renderer/TransientBufferPool.cpp
@@ -12,131 +12,164 @@ TransientBufferPool::TransientBufferPool(GfxDevice& device)
void TransientBufferPool::init(u32 initialVertexBytes, u32 initialIndexCount) {
if (initialized_) return;
-
- vertex_staging_.resize(initialVertexBytes);
- index_staging_.resize(initialIndexCount);
- vbo_capacity_ = initialVertexBytes;
- ebo_capacity_ = initialIndexCount;
-
- vbo_ = device_.createBuffer();
- ebo_ = device_.createBuffer();
-
- device_.bindVertexBuffer(vbo_);
- device_.bufferData(GfxBufferTarget::Vertex, nullptr, vbo_capacity_, true);
- device_.bindVertexBuffer(0);
-
- device_.bindIndexBuffer(ebo_);
- device_.bufferData(GfxBufferTarget::Index, nullptr, ebo_capacity_ * sizeof(u16), true);
- device_.bindIndexBuffer(0);
+ initial_vertex_bytes_ = initialVertexBytes;
+ initial_index_count_ = initialIndexCount;
for (auto layout : {LayoutId::Batch, LayoutId::Shape, LayoutId::MatSprite}) {
- setupLayoutVAO(layout);
+ setupStream(layout);
}
- vertex_write_pos_ = 0;
- index_write_pos_ = 0;
initialized_ = true;
}
void TransientBufferPool::shutdown() {
if (!initialized_) return;
- for (u32 i = 0; i < LAYOUT_COUNT; ++i) {
- if (vaos_[i]) {
- device_.deleteVertexArray(vaos_[i]);
- vaos_[i] = 0;
- }
+ for (auto& s : streams_) {
+ if (s.vao) { device_.deleteVertexArray(s.vao); s.vao = 0; }
+ if (s.vbo) { device_.deleteBuffer(s.vbo); s.vbo = 0; }
+ if (s.ebo) { device_.deleteBuffer(s.ebo); s.ebo = 0; }
+ s.vertex_staging.clear();
+ s.index_staging.clear();
+ s.vertex_write_pos = 0;
+ s.index_write_pos = 0;
+ s.vbo_capacity = 0;
+ s.ebo_capacity = 0;
}
- if (vbo_) { device_.deleteBuffer(vbo_); vbo_ = 0; }
- if (ebo_) { device_.deleteBuffer(ebo_); ebo_ = 0; }
-
- vertex_staging_.clear();
- index_staging_.clear();
initialized_ = false;
}
void TransientBufferPool::beginFrame() {
- vertex_write_pos_ = 0;
- index_write_pos_ = 0;
+ for (auto& s : streams_) {
+ s.vertex_write_pos = 0;
+ s.index_write_pos = 0;
+ }
}
-u32 TransientBufferPool::allocVertices(u32 byteSize) {
- u32 offset = vertex_write_pos_;
- u32 newPos = vertex_write_pos_ + byteSize;
- if (newPos > static_cast<u32>(vertex_staging_.size())) {
- growVertexBuffer(newPos);
+TransientBufferPool::Stream& TransientBufferPool::stream(LayoutId layout) {
+ return streams_[static_cast<u32>(layout)];
+}
+
+const TransientBufferPool::Stream& TransientBufferPool::stream(LayoutId layout) const {
+ return streams_[static_cast<u32>(layout)];
+}
+
+u32 TransientBufferPool::allocVertices(LayoutId layout, u32 byteSize) {
+ Stream& s = stream(layout);
+ u32 offset = s.vertex_write_pos;
+ u32 newPos = s.vertex_write_pos + byteSize;
+ if (newPos > static_cast<u32>(s.vertex_staging.size())) {
+ growVertexStaging(s, newPos);
}
- vertex_write_pos_ = newPos;
+ s.vertex_write_pos = newPos;
return offset;
}
-u32 TransientBufferPool::allocIndices(u32 count) {
- u32 offset = index_write_pos_;
- u32 newPos = index_write_pos_ + count;
- if (newPos > static_cast<u32>(index_staging_.size())) {
- growIndexBuffer(newPos);
+u32 TransientBufferPool::allocIndices(LayoutId layout, u32 count) {
+ Stream& s = stream(layout);
+ u32 offset = s.index_write_pos;
+ u32 newPos = s.index_write_pos + count;
+ if (newPos > static_cast<u32>(s.index_staging.size())) {
+ growIndexStaging(s, newPos);
}
- index_write_pos_ = newPos;
+ s.index_write_pos = newPos;
return offset;
}
-void TransientBufferPool::writeVertices(u32 byteOffset, const void* data, u32 byteSize) {
- std::memcpy(vertex_staging_.data() + byteOffset, data, byteSize);
+void TransientBufferPool::writeVertices(LayoutId layout, u32 byteOffset, const void* data, u32 byteSize) {
+ std::memcpy(stream(layout).vertex_staging.data() + byteOffset, data, byteSize);
}
-void TransientBufferPool::writeIndices(u32 indexOffset, const u16* data, u32 count) {
- std::memcpy(index_staging_.data() + indexOffset, data, count * sizeof(u16));
+void TransientBufferPool::writeIndices(LayoutId layout, u32 indexOffset, const u16* data, u32 count) {
+ std::memcpy(stream(layout).index_staging.data() + indexOffset, data, count * sizeof(u16));
}
-u32 TransientBufferPool::appendVertices(const void* data, u32 byteSize) {
- u32 offset = allocVertices(byteSize);
- writeVertices(offset, data, byteSize);
+u32 TransientBufferPool::appendVertices(LayoutId layout, const void* data, u32 byteSize) {
+ u32 offset = allocVertices(layout, byteSize);
+ writeVertices(layout, offset, data, byteSize);
return offset;
}
-u32 TransientBufferPool::appendIndices(const u16* data, u32 count) {
- u32 offset = allocIndices(count);
- writeIndices(offset, data, count);
+u32 TransientBufferPool::appendIndices(LayoutId layout, const u16* data, u32 count) {
+ u32 offset = allocIndices(layout, count);
+ writeIndices(layout, offset, data, count);
return offset;
}
void TransientBufferPool::upload() {
- if (vertex_write_pos_ == 0 && index_write_pos_ == 0) return;
-
- device_.bindVertexBuffer(vbo_);
- if (vertex_write_pos_ > vbo_capacity_) {
- vbo_capacity_ = vertex_write_pos_;
- device_.bufferData(GfxBufferTarget::Vertex, vertex_staging_.data(), vbo_capacity_, true);
- } else {
- device_.bufferSubData(GfxBufferTarget::Vertex, 0, vertex_staging_.data(), vertex_write_pos_);
- }
+ for (auto& s : streams_) {
+ if (!s.vbo) continue;
+ if (s.vertex_write_pos == 0 && s.index_write_pos == 0) continue;
+
+ device_.bindVertexBuffer(s.vbo);
+ if (s.vertex_write_pos > s.vbo_capacity) {
+ s.vbo_capacity = s.vertex_write_pos;
+ device_.bufferData(GfxBufferTarget::Vertex, s.vertex_staging.data(), s.vbo_capacity, true);
+ } else if (s.vertex_write_pos > 0) {
+ device_.bufferSubData(GfxBufferTarget::Vertex, 0, s.vertex_staging.data(), s.vertex_write_pos);
+ }
- device_.bindIndexBuffer(ebo_);
- u32 eboBytes = index_write_pos_ * sizeof(u16);
- u32 eboCapBytes = ebo_capacity_ * sizeof(u16);
- if (eboBytes > eboCapBytes) {
- ebo_capacity_ = index_write_pos_;
- device_.bufferData(GfxBufferTarget::Index, index_staging_.data(),
- ebo_capacity_ * sizeof(u16), true);
- } else {
- device_.bufferSubData(GfxBufferTarget::Index, 0, index_staging_.data(), eboBytes);
+ device_.bindIndexBuffer(s.ebo);
+ u32 eboBytes = s.index_write_pos * sizeof(u16);
+ u32 eboCapBytes = s.ebo_capacity * sizeof(u16);
+ if (eboBytes > eboCapBytes) {
+ s.ebo_capacity = s.index_write_pos;
+ device_.bufferData(GfxBufferTarget::Index, s.index_staging.data(),
+ s.ebo_capacity * sizeof(u16), true);
+ } else if (eboBytes > 0) {
+ device_.bufferSubData(GfxBufferTarget::Index, 0, s.index_staging.data(), eboBytes);
+ }
}
}
void TransientBufferPool::bindLayout(LayoutId layout) {
- u32 idx = static_cast<u32>(layout);
- if (idx < LAYOUT_COUNT && vaos_[idx]) {
- device_.bindVertexArray(vaos_[idx]);
- }
+ const Stream& s = stream(layout);
+ if (s.vao) device_.bindVertexArray(s.vao);
}
-void TransientBufferPool::setupLayoutVAO(LayoutId layout) {
- u32 idx = static_cast<u32>(layout);
- vaos_[idx] = device_.createVertexArray();
- device_.bindVertexArray(vaos_[idx]);
+u8* TransientBufferPool::vertexData(LayoutId layout) {
+ return stream(layout).vertex_staging.data();
+}
+
+u32 TransientBufferPool::vertexBytesUsed(LayoutId layout) const {
+ return stream(layout).vertex_write_pos;
+}
+
+u32 TransientBufferPool::indicesUsed(LayoutId layout) const {
+ return stream(layout).index_write_pos;
+}
+
+u32 TransientBufferPool::vboId(LayoutId layout) const {
+ return stream(layout).vbo;
+}
+
+u32 TransientBufferPool::eboId(LayoutId layout) const {
+ return stream(layout).ebo;
+}
+
+void TransientBufferPool::setupStream(LayoutId layout) {
+ Stream& s = stream(layout);
+
+ s.vertex_staging.resize(initial_vertex_bytes_);
+ s.index_staging.resize(initial_index_count_);
+ s.vbo_capacity = initial_vertex_bytes_;
+ s.ebo_capacity = initial_index_count_;
+
+ s.vbo = device_.createBuffer();
+ s.ebo = device_.createBuffer();
- device_.bindVertexBuffer(vbo_);
- device_.bindIndexBuffer(ebo_);
+ device_.bindVertexBuffer(s.vbo);
+ device_.bufferData(GfxBufferTarget::Vertex, nullptr, s.vbo_capacity, true);
+
+ device_.bindIndexBuffer(s.ebo);
+ device_.bufferData(GfxBufferTarget::Index, nullptr, s.ebo_capacity * sizeof(u16), true);
+
+ s.vao = device_.createVertexArray();
+ device_.bindVertexArray(s.vao);
+ // VAO captures the ELEMENT_ARRAY_BUFFER binding at this point, and every
+ // subsequent vertexAttribPointer captures the currently-bound ARRAY_BUFFER.
+ device_.bindVertexBuffer(s.vbo);
+ device_.bindIndexBuffer(s.ebo);
switch (layout) {
case LayoutId::Batch: {
@@ -174,23 +207,27 @@ void TransientBufferPool::setupLayoutVAO(LayoutId layout) {
}
device_.bindVertexArray(0);
+ device_.bindVertexBuffer(0);
+ device_.bindIndexBuffer(0);
}
-void TransientBufferPool::growVertexBuffer(u32 requiredBytes) {
- u32 newSize = static_cast<u32>(vertex_staging_.size());
+void TransientBufferPool::growVertexStaging(Stream& s, u32 requiredBytes) {
+ u32 newSize = static_cast<u32>(s.vertex_staging.size());
+ if (newSize == 0) newSize = 1024;
while (newSize < requiredBytes) {
newSize = newSize * 2;
}
- vertex_staging_.resize(newSize);
+ s.vertex_staging.resize(newSize);
ES_LOG_WARN("TransientBufferPool: vertex staging grown to {}KB", newSize / 1024);
}
-void TransientBufferPool::growIndexBuffer(u32 requiredCount) {
- u32 newSize = static_cast<u32>(index_staging_.size());
+void TransientBufferPool::growIndexStaging(Stream& s, u32 requiredCount) {
+ u32 newSize = static_cast<u32>(s.index_staging.size());
+ if (newSize == 0) newSize = 1024;
while (newSize < requiredCount) {
newSize = newSize * 2;
}
- index_staging_.resize(newSize);
+ s.index_staging.resize(newSize);
ES_LOG_WARN("TransientBufferPool: index staging grown to {} indices", newSize);
}
diff --git a/src/esengine/renderer/TransientBufferPool.hpp b/src/esengine/renderer/TransientBufferPool.hpp
index 06b07a357..742cc00a3 100644
--- a/src/esengine/renderer/TransientBufferPool.hpp
+++ b/src/esengine/renderer/TransientBufferPool.hpp
@@ -16,6 +16,17 @@ enum class LayoutId : u8 {
static constexpr u32 LAYOUT_COUNT = 4;
+/**
+ * Per-frame vertex/index staging with one independent VBO+EBO+VAO per layout.
+ *
+ * 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.
+ */
class TransientBufferPool {
public:
explicit TransientBufferPool(GfxDevice& device);
@@ -26,45 +37,53 @@ public:
void beginFrame();
- u32 allocVertices(u32 byteSize);
- u32 allocIndices(u32 count);
+ u32 allocVertices(LayoutId layout, u32 byteSize);
+ u32 allocIndices(LayoutId layout, u32 count);
- void writeVertices(u32 byteOffset, const void* data, u32 byteSize);
- void writeIndices(u32 indexOffset, const u16* data, u32 count);
+ void writeVertices(LayoutId layout, u32 byteOffset, const void* data, u32 byteSize);
+ void writeIndices(LayoutId layout, u32 indexOffset, const u16* data, u32 count);
- u32 appendVertices(const void* data, u32 byteSize);
- u32 appendIndices(const u16* data, u32 count);
+ u32 appendVertices(LayoutId layout, const void* data, u32 byteSize);
+ u32 appendIndices(LayoutId layout, const u16* data, u32 count);
+ /** Upload every non-empty stream's staging to its VBO/EBO. */
void upload();
+ /** Bind the VAO for this layout (which also binds its EBO — VAO state). */
void bindLayout(LayoutId layout);
- u8* vertexData() { return vertex_staging_.data(); }
- u32 vertexBytesUsed() const { return vertex_write_pos_; }
- u32 indicesUsed() const { return index_write_pos_; }
- u32 vboId() const { return vbo_; }
- u32 eboId() const { return ebo_; }
+ /** Direct write-through pointer into a layout's staging, for hot paths
+ * that want to format vertices in place after `allocVertices`. */
+ u8* vertexData(LayoutId layout);
+ u32 vertexBytesUsed(LayoutId layout) const;
+ u32 indicesUsed(LayoutId layout) const;
+ u32 vboId(LayoutId layout) const;
+ u32 eboId(LayoutId layout) const;
private:
- void setupLayoutVAO(LayoutId layout);
- void growVertexBuffer(u32 requiredBytes);
- void growIndexBuffer(u32 requiredCount);
+ struct Stream {
+ u32 vbo = 0;
+ u32 ebo = 0;
+ u32 vao = 0;
+ std::vector<u8> vertex_staging;
+ std::vector<u16> index_staging;
+ u32 vertex_write_pos = 0;
+ u32 index_write_pos = 0;
+ u32 vbo_capacity = 0;
+ u32 ebo_capacity = 0;
+ };
+
+ void setupStream(LayoutId layout);
+ void growVertexStaging(Stream& s, u32 requiredBytes);
+ void growIndexStaging(Stream& s, u32 requiredCount);
+
+ Stream& stream(LayoutId layout);
+ const Stream& stream(LayoutId layout) const;
GfxDevice& device_;
-
- std::array<u32, LAYOUT_COUNT> vaos_{};
- u32 vbo_ = 0;
- u32 ebo_ = 0;
-
- std::vector<u8> vertex_staging_;
- std::vector<u16> index_staging_;
-
- u32 vertex_write_pos_ = 0;
- u32 index_write_pos_ = 0;
-
- u32 vbo_capacity_ = 0;
- u32 ebo_capacity_ = 0;
-
+ std::array<Stream, LAYOUT_COUNT> streams_{};
+ u32 initial_vertex_bytes_ = 0;
+ u32 initial_index_count_ = 0;
bool initialized_ = false;
};
diff --git a/src/esengine/renderer/plugins/ParticlePlugin.cpp b/src/esengine/renderer/plugins/ParticlePlugin.cpp
index 170621673..c948b0b22 100644
--- a/src/esengine/renderer/plugins/ParticlePlugin.cpp
+++ b/src/esengine/renderer/plugins/ParticlePlugin.cpp
@@ -72,10 +72,10 @@ void ParticlePlugin::collect(RenderCollectContext& collect_ctx) {
u32 idxCount = particleCount * 6;
u32 vertByteSize = vertCount * sizeof(BatchVertex);
- u32 vertByteOffset = buffers.allocVertices(vertByteSize);
- u32 idxOffset = buffers.allocIndices(idxCount);
+ u32 vertByteOffset = buffers.allocVertices(LayoutId::Batch, vertByteSize);
+ u32 idxOffset = buffers.allocIndices(LayoutId::Batch, idxCount);
- auto* verts = reinterpret_cast<BatchVertex*>(buffers.vertexData() + vertByteOffset);
+ auto* verts = reinterpret_cast<BatchVertex*>(buffers.vertexData(LayoutId::Batch) + vertByteOffset);
u16 baseVertex = static_cast<u16>(vertByteOffset / sizeof(BatchVertex));
u32 pi = 0;
@@ -138,15 +138,12 @@ void ParticlePlugin::collect(RenderCollectContext& collect_ctx) {
u32 ii = pi * 6;
u16 bv = baseVertex + static_cast<u16>(vi);
- for (u32 q = 0; q < 6; ++q) {
- buffers.writeIndices(idxOffset + ii + q, &QUAD_INDICES[q], 1);
- }
// Patch base vertex into indices
u16 patched[6];
for (u32 q = 0; q < 6; ++q) {
patched[q] = bv + QUAD_INDICES[q];
}
- buffers.writeIndices(idxOffset + ii, patched, 6);
+ buffers.writeIndices(LayoutId::Batch, idxOffset + ii, patched, 6);
++pi;
});
diff --git a/src/esengine/renderer/plugins/ShapePlugin.cpp b/src/esengine/renderer/plugins/ShapePlugin.cpp
index 4b8137d62..1b8e46dc2 100644
--- a/src/esengine/renderer/plugins/ShapePlugin.cpp
+++ b/src/esengine/renderer/plugins/ShapePlugin.cpp
@@ -90,14 +90,14 @@ void ShapePlugin::collect(RenderCollectContext& collect_ctx) {
verts[v].cornerRadius = shape.cornerRadius;
}
- u32 vOff = buffers.appendVertices(verts, sizeof(verts));
+ u32 vOff = buffers.appendVertices(LayoutId::Shape, verts, sizeof(verts));
u32 baseVertex = vOff / sizeof(ShapeVertex);
u16 indices[6];
for (u32 i = 0; i < 6; ++i) {
indices[i] = static_cast<u16>(baseVertex + QUAD_INDICES[i]);
}
- u32 iOff = buffers.appendIndices(indices, 6);
+ u32 iOff = buffers.appendIndices(LayoutId::Shape, indices, 6);
DrawCommand cmd{};
cmd.sort_key = DrawCommand::buildSortKey(ctx.current_stage, shape.layer, shape_shader_id_, BlendMode::Normal, 0, 0, position.z);
diff --git a/src/esengine/renderer/plugins/SpinePlugin.cpp b/src/esengine/renderer/plugins/SpinePlugin.cpp
index 93845fd0b..3eb977c39 100644
--- a/src/esengine/renderer/plugins/SpinePlugin.cpp
+++ b/src/esengine/renderer/plugins/SpinePlugin.cpp
@@ -57,13 +57,13 @@ void SpinePlugin::emitBatch(
if (vertices_.empty() || indices_.empty()) return;
u32 vBytes = static_cast<u32>(vertices_.size()) * sizeof(BatchVertex);
- u32 vOff = buffers.appendVertices(vertices_.data(), vBytes);
+ u32 vOff = buffers.appendVertices(LayoutId::Batch, vertices_.data(), vBytes);
u32 baseVertex = vOff / sizeof(BatchVertex);
for (auto& idx : indices_) {
idx = static_cast<u16>(idx + baseVertex);
}
- u32 iOff = buffers.appendIndices(indices_.data(), static_cast<u32>(indices_.size()));
+ u32 iOff = buffers.appendIndices(LayoutId::Batch, indices_.data(), static_cast<u32>(indices_.size()));
DrawCommand cmd{};
cmd.sort_key = DrawCommand::buildSortKey(
diff --git a/src/esengine/renderer/plugins/SpritePlugin.cpp b/src/esengine/renderer/plugins/SpritePlugin.cpp
index e13c60552..66dab99a6 100644
--- a/src/esengine/renderer/plugins/SpritePlugin.cpp
+++ b/src/esengine/renderer/plugins/SpritePlugin.cpp
@@ -149,14 +149,14 @@ void SpritePlugin::emitQuad(
}
}
- u32 vOff = buffers.appendVertices(verts, sizeof(verts));
+ u32 vOff = buffers.appendVertices(LayoutId::Batch, verts, sizeof(verts));
u32 baseVertex = vOff / sizeof(BatchVertex);
u16 indices[6];
for (u32 i = 0; i < 6; ++i) {
indices[i] = static_cast<u16>(baseVertex + QUAD_INDICES[i]);
}
- u32 iOff = buffers.appendIndices(indices, 6);
+ u32 iOff = buffers.appendIndices(LayoutId::Batch, indices, 6);
DrawCommand cmd{};
cmd.sort_key = DrawCommand::buildSortKey(stage, layer, shaderId, blend, 0, textureId, depth);
@@ -243,14 +243,14 @@ void SpritePlugin::emitNineSlice(
verts[2] = { p2, pc, {u[col + 1], v[row + 1]} };
verts[3] = { p3, pc, {u[col], v[row + 1]} };
- u32 vOff = buffers.appendVertices(verts, sizeof(verts));
+ u32 vOff = buffers.appendVertices(LayoutId::Batch, verts, sizeof(verts));
u32 baseVert = vOff / sizeof(BatchVertex);
u16 indices[6];
for (u32 i = 0; i < 6; ++i) {
indices[i] = static_cast<u16>(baseVert + QUAD_INDICES[i]);
}
- u32 iOff = buffers.appendIndices(indices, 6);
+ u32 iOff = buffers.appendIndices(LayoutId::Batch, indices, 6);
DrawCommand cmd{};
cmd.sort_key = DrawCommand::buildSortKey(stage, layer, shaderId, blend, 0, textureId, depth);
@@ -359,14 +359,14 @@ void SpritePlugin::emitTiledQuads(
verts[3] = { { x0, y1 }, pc, { uvOffset.x, uvOffset.y + tileUvScale.y } };
}
- u32 vOff = buffers.appendVertices(verts, sizeof(verts));
+ u32 vOff = buffers.appendVertices(LayoutId::Batch, verts, sizeof(verts));
u32 baseVert = vOff / sizeof(BatchVertex);
u16 indices[6];
for (u32 i = 0; i < 6; ++i) {
indices[i] = static_cast<u16>(baseVert + QUAD_INDICES[i]);
}
- u32 iOff = buffers.appendIndices(indices, 6);
+ u32 iOff = buffers.appendIndices(LayoutId::Batch, indices, 6);
DrawCommand cmd = tmpl;
cmd.index_offset = iOff;
diff --git a/src/esengine/renderer/plugins/TextPlugin.cpp b/src/esengine/renderer/plugins/TextPlugin.cpp
index 9d0811508..c70b9a298 100644
--- a/src/esengine/renderer/plugins/TextPlugin.cpp
+++ b/src/esengine/renderer/plugins/TextPlugin.cpp
@@ -183,14 +183,14 @@ void TextPlugin::emitGlyphQuad(
verts[3].color = pc;
verts[3].texCoord = glm::vec2(0.0f, 1.0f) * uvScale + uvOffset;
- u32 vOff = buffers.appendVertices(verts, sizeof(verts));
+ u32 vOff = buffers.appendVertices(LayoutId::Batch, verts, sizeof(verts));
u32 baseVertex = vOff / sizeof(BatchVertex);
u16 indices[6];
for (u32 i = 0; i < 6; ++i) {
indices[i] = static_cast<u16>(baseVertex + QUAD_INDICES[i]);
}
- u32 iOff = buffers.appendIndices(indices, 6);
+ u32 iOff = buffers.appendIndices(LayoutId::Batch, indices, 6);
DrawCommand cmd{};
cmd.sort_key = DrawCommand::buildSortKey(stage, layer, shaderId, BlendMode::Normal, 0, textureId, depth);
diff --git a/src/esengine/renderer/plugins/TilemapRenderPlugin.cpp b/src/esengine/renderer/plugins/TilemapRenderPlugin.cpp
index a3ac2d90b..e00dc3ce3 100644
--- a/src/esengine/renderer/plugins/TilemapRenderPlugin.cpp
+++ b/src/esengine/renderer/plugins/TilemapRenderPlugin.cpp
@@ -190,13 +190,13 @@ void TilemapRenderPlugin::collect(RenderCollectContext& collect_ctx) {
if (indices_.empty()) continue;
u32 vBytes = static_cast<u32>(vertices_.size()) * sizeof(BatchVertex);
- u32 vOff = buffers.appendVertices(vertices_.data(), vBytes);
+ u32 vOff = buffers.appendVertices(LayoutId::Batch, vertices_.data(), vBytes);
u32 baseVertex = vOff / sizeof(BatchVertex);
for (auto& idx : indices_) {
idx = static_cast<u16>(idx + baseVertex);
}
- u32 iOff = buffers.appendIndices(indices_.data(), static_cast<u32>(indices_.size()));
+ u32 iOff = buffers.appendIndices(LayoutId::Batch, indices_.data(), static_cast<u32>(indices_.size()));
DrawCommand cmd{};
cmd.sort_key = DrawCommand::buildSortKey(
diff --git a/src/esengine/renderer/plugins/UIElementPlugin.cpp b/src/esengine/renderer/plugins/UIElementPlugin.cpp
index 573a9f61e..30bf39d61 100644
--- a/src/esengine/renderer/plugins/UIElementPlugin.cpp
+++ b/src/esengine/renderer/plugins/UIElementPlugin.cpp
@@ -151,14 +151,14 @@ void UIElementPlugin::emitQuad(
}
}
- u32 vOff = buffers.appendVertices(verts, sizeof(verts));
+ u32 vOff = buffers.appendVertices(LayoutId::Batch, verts, sizeof(verts));
u32 baseVertex = vOff / sizeof(BatchVertex);
u16 indices[6];
for (u32 i = 0; i < 6; ++i) {
indices[i] = static_cast<u16>(baseVertex + QUAD_INDICES[i]);
}
- u32 iOff = buffers.appendIndices(indices, 6);
+ u32 iOff = buffers.appendIndices(LayoutId::Batch, indices, 6);
DrawCommand cmd{};
cmd.sort_key = DrawCommand::buildSortKey(stage, layer, shaderId, blend, 0, textureId, depth);
@@ -252,14 +252,14 @@ void UIElementPlugin::emitNineSlice(
verts[2] = { p2, pc, {u[col + 1], v[row + 1]} };
verts[3] = { p3, pc, {u[col], v[row + 1]} };
- u32 vOff = buffers.appendVertices(verts, sizeof(verts));
+ u32 vOff = buffers.appendVertices(LayoutId::Batch, verts, sizeof(verts));
u32 baseVert = vOff / sizeof(BatchVertex);
u16 indices[6];
for (u32 i = 0; i < 6; ++i) {
indices[i] = static_cast<u16>(baseVert + QUAD_INDICES[i]);
}
- u32 iOff = buffers.appendIndices(indices, 6);
+ u32 iOff = buffers.appendIndices(LayoutId::Batch, indices, 6);
DrawCommand cmd{};
cmd.sort_key = DrawCommand::buildSortKey(stage, layer, shaderId, blend, 0, textureId, depth);