Skip to content

Select multi-texture vs single-texture strategy once in WebGLSpriteBatch - #771

Draft
samme with Copilot wants to merge 1 commit into
masterfrom
copilot/split-webgl-and-webgl-multi
Draft

samme with Copilot wants to merge 1 commit into
masterfrom
copilot/split-webgl-and-webgl-multi

Conversation

Copilot AI commented Nov 17, 2026

Copy link
Copy Markdown

WebGLSpriteBatch checked the global PIXI._enableMultiTextureToggle in its per-sprite hot paths, so the multi-texture and single-texture invariants were interleaved in render, renderTilingSprite and flush. This PR splits the two modes. It is a refactor with no intended behavior change.

  • Strategy chosen once in setContext

    • It sets this.multiTexture and assigns defaultShader, bindTexture and uploadTexture for the active mode.
    • New per-mode methods: createMultiTextureShader / createSingleTextureShader, bindTextureMulti / bindTextureSingle (single is a no-op), uploadTextureMulti / uploadTextureSingle.
    • The strategy methods are assigned per instance at context setup, so there are no per-frame allocations and no per-sprite flag lookups.
  • Hot paths

    • render and renderTilingSprite call this.bindTexture(baseTexture, textureIndex). This removes the duplicated bind-and-flush block between them.
    • flush reads this.multiTexture instead of the global.
  • TileSprite

    • _renderWebGL now calls spriteBatch.uploadTexture(...).
    • It no longer checks the mode or flushes the batch itself. The multi-texture variant flushes before uploading, because the upload rebinds a texture unit that queued sprites may sample.
// TileSprite._renderWebGL
renderSession.spriteBatch.uploadTexture(this.tilingTexture.baseTexture);

Not changed

  • PixiShader, StripShader, PixiFastShader, Creature, DisplayObject and WebGLRenderer#setTexturePriority still read PIXI._enableMultiTextureToggle directly.
  • PIXI._enableMultiTextureToggle and the Game config are unchanged.
  • renderBatch still calls a plain gl.bindTexture with no activeTexture. I suspect this is fine in multi-texture mode because the batch shader samples by index, but it is unverified.

Review focus

  • No browser run yet. Needs a check with multiTexture: false and true covering sprites, tiling sprites (including texture regeneration), filters, strips, Creature and setTexturePriority.
  • bindTexture and uploadTexture are undefined until setContext runs. All current callers run after context setup.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

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.

2 participants