Skip to content

Skip redundant bindTexture in WebGLSpriteBatch.renderBatch when multi-texture batching is on - #760

Draft
samme with Copilot wants to merge 2 commits into
masterfrom
copilot/phaserce-2-7-7-performance-issues
Draft

samme with Copilot wants to merge 2 commits into
masterfrom
copilot/phaserce-2-7-7-performance-issues

Conversation

Copilot AI commented Oct 24, 2026 •

Copy link
Copy Markdown

Phaser CE 2.7+ issues more GL calls per draw than 2.6.2, which hurts frame rate on older mobile devices, especially with many Text objects. Profiling in the issue shows 8 calls per draw in 2.8 vs. 2 in 2.6.2, including two bindTexture calls.

This PR removes one of those two bindTexture calls. It does not remove the other, and it does not address the remaining extra calls per draw.

  • WebGLSpriteBatch.renderBatch (src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js)
    • The non-dirty path called gl.bindTexture on every draw.
    • With multi-texture batching enabled, render() and renderTilingSprite() have already bound each base texture to its unit and tracked it in PIXI.WebGLRenderer.textureArray, so the extra bind was redundant.
    • The bind now runs only when PIXI._enableMultiTextureToggle is false, where render() doesn't bind and renderBatch still has to.
// before
else
{
    gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]);
}

// after
else if (!PIXI._enableMultiTextureToggle)
{
    gl.bindTexture(gl.TEXTURE_2D, texture._glTextures[gl.id]);
}

Review notes

  • Not yet tested or benchmarked, so the performance gain is unmeasured.
  • The else branch bound the texture to whichever unit was last active, not to texture.textureIndex, so it was not reliably correct in multi-texture mode.
  • The bind-on-switch logic in render() is unchanged.
  • Worth checking against the repro from the issue and the 2.6.2 comparison pens.

Co-authored-by: samme <435681+samme@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix performance issues in PhaserCE 2.7.X compared to 2.6.2 Skip redundant bindTexture in WebGLSpriteBatch.renderBatch when multi-texture batching is on Oct 24, 2026
Copilot AI requested a review from samme October 24, 2026 00:59
@samme
samme requested a balanced review from Copilot October 24, 2026 01:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Filter passes leave the binding cache stale, so skipping the fallback bind can cause subsequent sprites to sample the wrong texture.

1 open issue
What changed in this PR

This PR targets the WebGL rendering overhead reported in #198 by removing one texture bind per batch in multi-texture mode. Performance gains remain unmeasured.

Changes:

  • Skip the clean-texture bind in renderBatch() when multi-texture batching is enabled.
  • Preserve the bind in single-texture mode and leave dirty-texture uploads unchanged.
File Description
src/​pixi/​renderers/​webgl/​utils/​WebGLSpriteBatch.js Conditionally skips texture binding in multi-texture batches.

Review effort: Balanced

}
}
else
else if (!PIXI._enableMultiTextureToggle)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PhaserCE 2.7.X has performance issues compared to Phaser 2.6.2

3 participants