aframe icon indicating copy to clipboard operation
aframe copied to clipboard

Cache Source instead of Texture instances in material system

Open mrxz opened this issue 1 year ago • 2 comments

Description: Final part of #5449, resolving #5441, #5120, #1372. Instead of caching textures and trying to do reference counting, the underlying Sources are cached instead. Actual reference counting is done by Three.js internally, which allows the same texture source to be shared with multiple textures, even if they differ in offset or repeat (which before would result in uploads).

This PR also improves the disposing behaviour, which previously only disposed when the material unregistered itself from the material system, missing any textures that were no longer assigned to that material. This also means that since Texture instances aren't shared, they can be changed by users without affecting other textures, while still using the same underlying image.

Changes proposed:

  • Let systems/material cache Source instances instead of Textures
  • Let helpers in utils/material request these Source instances and create/update the material's Texture instance

mrxz avatar Feb 10 '24 15:02 mrxz

This need rebase

dmarcos avatar Feb 13 '24 22:02 dmarcos

@dmarcos Rebased

mrxz avatar Feb 14 '24 08:02 mrxz

Thanks. So much good work.

dmarcos avatar Feb 20 '24 21:02 dmarcos