Skip to content

Fix multi-texture batching binding the wrong texture to the active unit - #761

Draft
samme with Copilot wants to merge 4 commits into
masterfrom
copilot/fix-multi-texture-sprites
Draft

samme with Copilot wants to merge 4 commits into
masterfrom
copilot/fix-multi-texture-sprites

Conversation

Copilot AI commented Oct 24, 2026 •

Copy link
Copy Markdown

With multi-texture batching enabled, a sprite could be drawn with the wrong texture. In the reported case, the full-canvas game.debug.sprite appeared with another sprite's texture after setTexturePriority() was called. I haven't reproduced the stretching in a browser. The link to the debug sprite is inferred from the code and the comments on the issue.

Cause

  • WebGLSpriteBatch#renderBatch always ended with gl.bindTexture(TEXTURE_2D, texture._glTextures[gl.id]).
  • In multi-texture mode, render() has already bound each base texture to its own unit (textureIndex).
  • The extra bind therefore went to whichever unit was last made active, not the texture's own. It could overwrite another texture's binding, and PIXI.WebGLRenderer.textureArray would not reflect the change.

Change

  • WebGLSpriteBatch.js: skip that bind when PIXI._enableMultiTextureToggle is set.
  • The dirty-texture path (updateTexture) is unchanged. It already activates the correct unit.
  • Single-texture rendering is unchanged.
  • CHANGELOG.md: added a bug-fix entry.

The issue comments say this "appears fixed by #641". The redundant bind is still present in this branch, so I treated the bug as still open.

Co-authored-by: samme <435681+samme@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix multi-texture sprites stretching to fill entire canvas Fix multi-texture batching binding the wrong texture to the active unit Oct 24, 2026
Copilot AI requested a review from samme October 24, 2026 01:02
@samme
samme requested a balanced review from Copilot October 24, 2026 01:17

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

Skipping the bind can leave sprites sampling filter output because filter passes overwrite texture bindings without updating the binding cache.

1 open issue
What changed in this PR

This PR aims to prevent multi-texture sprite batching from overwriting the wrong texture unit while preserving single-texture rendering behavior.

Changes:

  • Skip the clean-texture bind in renderBatch() when multi-texture batching is enabled.
  • Add a changelog entry describing the texture-binding fix.
File Description
src/​pixi/​renderers/​webgl/​utils/​WebGLSpriteBatch.js Guard the texture bind in multi-texture mode.
CHANGELOG.md Document the fix and its connection to issue #231.

Review effort: Balanced

}
}
else
else if (!PIXI._enableMultiTextureToggle)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Invalidated unit 0's cached texture binding after popFilter() binds the filter output. Commit: c05a0ad4e.

Co-authored-by: samme <435681+samme@users.noreply.github.com>

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

Stale texture bindings on filter entry and after Rope or Creature rendering still cause incorrect sprite rendering.

3 open issues

Review effort: Balanced

}
}
else
else if (!PIXI._enableMultiTextureToggle)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Invalidated unit 0 and the texture’s assigned unit after Rope and Creature render their direct bindings. Commit: d9301bcd1.

Co-authored-by: samme <435681+samme@users.noreply.github.com>

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

TileSprite uploads, RenderTexture allocation, and lazy shader initialization still leave incorrect texture bindings when the draw-time bind is skipped.

5 open issues
1 resolved since last review

Review effort: Balanced

}
}
else
else if (!PIXI._enableMultiTextureToggle)
}
}
else
else if (!PIXI._enableMultiTextureToggle)
}
}
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.

Multi-texture sprites stretch to fill entire canvas

3 participants