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): dedupe redundant program + blend binds on pipeline switch
esengine477748da1021
diff --git a/src/esengine/renderer/GLDevice.cpp b/src/esengine/renderer/GLDevice.cppindex 1d001a3d2..59ab44cac 100644--- a/src/esengine/renderer/GLDevice.cpp+++ b/src/esengine/renderer/GLDevice.cpp@@ -291,6 +291,8 @@ void GLDevice::setBlendEnabled(bool enabled) {}void GLDevice::setBlendMode(BlendMode mode) {+ if (mode == current_blend_) return;+ current_blend_ = mode;switch (mode) {case BlendMode::Normal:glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);@@ -473,7 +475,9 @@ void GLDevice::deleteProgram(ShaderHandle program) {}void GLDevice::useProgram(ShaderHandle program) {+ if (program == current_program_) return;glUseProgram(static_cast<GLuint>(program));+ current_program_ = program;}i32 GLDevice::getUniformLocation(ShaderHandle program, const char* name) {@@ -801,6 +805,8 @@ void GLDevice::setStencilReference(i32 ref) {void GLDevice::invalidatePipelineCache() {current_pipeline_ = PipelineHandle::Invalid;current_stencil_mode_ = GfxStencilMode::Off;+ current_program_ = ShaderHandle::Invalid;+ current_blend_ = static_cast<BlendMode>(0xFF);}// =============================================================================diff --git a/src/esengine/renderer/GLDevice.hpp b/src/esengine/renderer/GLDevice.hppindex f7878a7c8..ab953af45 100644--- a/src/esengine/renderer/GLDevice.hpp+++ b/src/esengine/renderer/GLDevice.hpp@@ -165,6 +165,13 @@ private:std::vector<PipelineDesc> pipelines_;PipelineHandle current_pipeline_ = PipelineHandle::Invalid;GfxStencilMode current_stencil_mode_ = GfxStencilMode::Off;+ // Redundant-state caches for setPipeline: the program and blend func are only+ // ever set through useProgram / setBlendMode, so caching the last value lets a+ // pipeline switch that shares them skip the (FFI-crossing) GL call. Reset in+ // invalidatePipelineCache. 0xFF is an out-of-range BlendMode sentinel so the+ // first real set always issues (init sets the GL blend directly, not via here).+ ShaderHandle current_program_ = ShaderHandle::Invalid;+ BlendMode current_blend_ = static_cast<BlendMode>(0xFF);// Redundant-state caches for the two per-draw hot paths. glActiveTexture is// the only site that moves the active unit, so active_texture_unit_ is