-
-
Notifications
You must be signed in to change notification settings - Fork 657
WebGL: flush and rebatch when texture units are exhausted instead of throwing #1280
Description
Description
When all GPU texture units are occupied and a new texture needs to be bound, the texture cache currently throws an exception:
Texture cache overflow: N texture units available for this GPU.
This is overly restrictive. Instead, the renderer should transparently handle texture unit exhaustion by flushing the current batch (issuing a draw call for everything buffered so far), resetting the texture unit assignments, and continuing with the new texture bound to unit 0.
Proposed solution
In TextureCache.allocateTextureUnit(), instead of throwing when no units are available:
- Flush the current compositor (
compositor.flush()) - Reset/clear all texture unit assignments in the cache
- Allocate unit 0 for the new texture and return it
This results in an additional draw call, which is the expected trade-off when a scene uses more unique textures than the GPU has units. The behavior is transparent to the user — no errors, no texture merging complexity.
Impact
- Games with many unique textures will work without errors (at the cost of additional draw calls)
- Games within the texture unit limit see no change in behavior
- No API changes required
Location: src/video/texture/cache.js — allocateTextureUnit()