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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
perf(render): skip geometry outside UI scissor viewports
yhha2676471f979
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 09a8143f5..815d4185b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,8 @@ published separately; it ships inside the editor.### Fixed+- **Screen-excluded UI scissor regions no longer submit draws.** Root scissor masks intersect the current view's viewport before propagating to descendants. Empty regions skip UI visual collection and batch geometry/index/command allocation, including text submissions; stencil-only entries remain drawable. Moving a masked subtree back into view restores its draws on the next frame.+- **Animation despawn subscriptions belong to their App.** Shared animation plugins withdraw the quitting App's listener while preserving other Apps' tween cancellation, sprite-event cleanup, and animator removal callbacks. Repeated preview shutdowns no longer leave stale subscriptions on older worlds.- **Sprite animation applies frames through direct component accessors.** Running animation resolves the sprite read/write path once per update, avoiding per-frame embind snapshots and full component marshalling for every animated entity. Component write journals still observe frame changes, while editor observers, speculative updates, and rebound worlds retain the full mutation path.diff --git a/src/esengine/renderer/draw/BatchBuilder.cpp b/src/esengine/renderer/draw/BatchBuilder.cppindex 3f9f8d382..e23b6762c 100644--- a/src/esengine/renderer/draw/BatchBuilder.cpp+++ b/src/esengine/renderer/draw/BatchBuilder.cpp@@ -29,7 +29,7 @@ void pushBatchCommandImpl(TransientBufferPool& pool, DrawList& drawList, const Cu32 vertexByteOffset, u32 vertexCount,const IndexT* localIndices, u32 indexCount,const BatchDrawKey& key) {- if (indexCount == 0) return;+ if (indexCount == 0 || clips.isEmptyScissor(key.entity)) return;u32 baseVertex = vertexByteOffset / pool.vertexStride(key.layoutId);g_indexScratch.resize(indexCount);@@ -46,7 +46,7 @@ void pushBatchCommandImpl(TransientBufferPool& pool, DrawList& drawList, const Cvoid pushBatchDraw(DrawList& drawList, const ClipState& clips,u32 vertexByteOffset, u32 vertexCount, u32 indexOffset, u32 indexCount,const BatchDrawKey& key) {- if (indexCount == 0) return;+ if (indexCount == 0 || clips.isEmptyScissor(key.entity)) return;// A group takes over its members' outward identity, so EVERY layer-derived decision// below asks the group's layer: the culling bit, the ordering rule, the key's top field.@@ -184,7 +184,7 @@ void appendIndexedDraw(TransientBufferPool& pool, DrawList& drawList, const Clipconst void* verts, u32 vertexCount,const u32* localIndices, u32 indexCount,const BatchDrawKey& key) {- if (vertexCount == 0 || indexCount == 0) return;+ if (vertexCount == 0 || indexCount == 0 || clips.isEmptyScissor(key.entity)) return;u32 vertexByteOffset = pool.appendVertices(key.layoutId, verts, vertexCount * pool.vertexStride(key.layoutId));pushBatchCommandImpl(pool, drawList, clips, vertexByteOffset, vertexCount, localIndices, indexCount, key);@@ -197,4 +197,4 @@ void appendIndexedBatch(TransientBufferPool& pool, DrawList& drawList, const CliappendIndexedDraw(pool, drawList, clips, verts, vertexCount, localIndices, indexCount, key);}-} // namespace esengine\ No newline at end of file+} // namespace esenginediff --git a/src/esengine/renderer/draw/ClipState.hpp b/src/esengine/renderer/draw/ClipState.hppindex 37e2e50ac..3c1c74e79 100644--- a/src/esengine/renderer/draw/ClipState.hpp+++ b/src/esengine/renderer/draw/ClipState.hpp@@ -64,6 +64,13 @@ public:return it != entries_.end() ? &it->second : nullptr;}+ bool isEmptyScissor(Entity entity) const {+ if (entries_.empty()) return false;+ const auto* entry = getEntry(entity.id());+ return entry && (entry->flags & CMD_STATE_SCISSOR)+ && (entry->scissor.w <= 0 || entry->scissor.h <= 0);+ }+void clear() { entries_.clear(); }bool empty() const { return entries_.empty(); }@@ -71,4 +78,4 @@ private:std::unordered_map<u32, Entry> entries_;};-} // namespace esengine\ No newline at end of file+} // namespace esenginediff --git a/src/esengine/renderer/frame/RenderFrameMask.cpp b/src/esengine/renderer/frame/RenderFrameMask.cppindex bccea7e23..94543e352 100644--- a/src/esengine/renderer/frame/RenderFrameMask.cpp+++ b/src/esengine/renderer/frame/RenderFrameMask.cpp@@ -237,6 +237,7 @@ void RenderFrame::processMasks(ecs::Registry& registry, const glm::mat4& projectfor (auto entity : rootScissors) {ScreenRect rect = computeMaskScreenRect(registry, entity, projection, vpX, vpY, vpW, vpH);+ rect = intersectRects(rect, {vpX, vpY, vpW, vpH});applyScissorToDescendants(registry, *this, entity, rect, maskSet, projection, vpX, vpY, vpW, vpH);}}diff --git a/src/esengine/renderer/plugins/UIElementPlugin.cpp b/src/esengine/renderer/plugins/UIElementPlugin.cppindex 1a57a1867..aa10e354b 100644--- a/src/esengine/renderer/plugins/UIElementPlugin.cpp+++ b/src/esengine/renderer/plugins/UIElementPlugin.cpp@@ -60,6 +60,7 @@ void UIElementPlugin::collect(RenderCollectContext& collect_ctx) {// Geometry from the UINode (CSS box) — always pivot-centered.const auto* node = registry.tryGet<ecs::UINode>(entity);if (!node || node->hidden_in_tree_) continue;+ if (clips.isEmptyScissor(entity)) { ++collect_ctx.culled; continue; }f32 w = node->computed_size_.x, h = node->computed_size_.y;f32 pivotX = 0.5f, pivotY = 0.5f;if (w <= 0.0f && h <= 0.0f) continue;diff --git a/tests/renderer/test_batch_builder.cpp b/tests/renderer/test_batch_builder.cppindex 2f2a1bc22..5f5ffa5f7 100644--- a/tests/renderer/test_batch_builder.cpp+++ b/tests/renderer/test_batch_builder.cpp@@ -101,6 +101,50 @@ TEST_CASE("appendQuad: Batch command with baseVertex-offset indices and one textCHECK(second.index_offset == 6);}+TEST_CASE("empty scissor regions allocate no quad geometry or draw command") {+ for (const auto size : {std::pair{0, 20}, std::pair{20, 0}, std::pair{-1, 20}}) {+ Harness h;+ BatchVertex quad[4] = {};+ auto blocked = quadKey(42); blocked.entity = Entity(91);+ h.clips.setScissor(91, 10, 20, size.first, size.second);+ h.clips.setStencilTestOutside(91, 3);+ appendQuad(h.pool, h.list, h.clips, quad, blocked);+ auto visible = quadKey(42); visible.entity = Entity(92);+ appendQuad(h.pool, h.list, h.clips, quad, visible);+ REQUIRE(h.list.commandCount() == 1);+ CHECK(h.list.command(0).entity == Entity(92));+ CHECK(h.list.command(0).vertex_byte_offset == 0);+ CHECK(h.list.command(0).index_offset == 0);+ }+}++TEST_CASE("empty scissors suppress direct and prebuilt-vertex submissions") {+ Harness h;+ auto blocked = quadKey(42); blocked.entity = Entity(91);+ h.clips.setScissor(91, 0, 0, 0, 0);+ pushBatchDraw(h.list, h.clips, 0, 4, 0, 6, blocked);+ const u32 indices[] = {0, 1, 2, 2, 3, 0};+ pushBatchCommand(h.pool, h.list, h.clips, 0, 4, indices, 6, blocked);+ CHECK(h.list.commandCount() == 0);+ BatchVertex quad[4] = {};+ auto visible = quadKey(42); visible.entity = Entity(92);+ appendQuad(h.pool, h.list, h.clips, quad, visible);+ REQUIRE(h.list.commandCount() == 1);+ CHECK(h.list.command(0).index_offset == 0);+}++TEST_CASE("stencil-only entries and nonempty scissors still draw") {+ Harness h;+ BatchVertex quad[4] = {};+ auto stencil = quadKey(42); stencil.entity = Entity(91);+ h.clips.setStencilMask(91, 1);+ appendQuad(h.pool, h.list, h.clips, quad, stencil);+ auto clipped = quadKey(42); clipped.entity = Entity(92);+ h.clips.setScissor(92, 10, 20, 1, 1);+ appendQuad(h.pool, h.list, h.clips, quad, clipped);+ CHECK(h.list.commandCount() == 2);+}+TEST_CASE("appendIndexedDraw: non-Batch stream uses its own stride for baseVertex") {Harness h;TestShapeVertex verts[4] = {};diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 7445f4556..c2af25113 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ 'perf(render): skip geometry outside UI scissor viewports':+ { note: 'Screen-excluded UI scissor regions no longer submit draws.' },'fix(animation): isolate despawn subscriptions by app':{ note: 'Animation despawn subscriptions belong to their App.' },'perf(animation): apply sprite frames through direct storage accessors':