lordmauve / wasabi2d

Cutting-edge 2D game framework for Python
https://wasabi2d.readthedocs.io/
GNU Lesser General Public License v3.0
154 stars 24 forks source link

Texture repack #31

Open lordmauve opened 4 years ago

lordmauve commented 4 years ago

When building texture atlases, sprite data is uploaded from system memory.

Sprites that are unused after a long time are not currently deleted. It would be possible to "garbage collect" sprites - perhaps periodically or as a function that users can call. To release texture memory this could rebuild the atlas with sprites to keep.

However, at this point, the sprite data is on the GPU already. A new texture can be built by drawing the old sprites into their new locations - essentially by drawing them as sprites into a new texture.

lordmauve commented 4 years ago

From #2, large NPOT textures are never deallocated. If we can track which textures have not been recently referenced (eg. a generational approach) then we can simply remove these textures from cache.

lordmauve commented 4 years ago

NB since #24 this issue becomes a lot easier:

To actually repack we would need to visit users of each texture region and update them with the new region. An alternative would be to maintain a texture containing the "table of contents" for an atlas, and users of a texture region simply have indexes into this. Repacking textures can thus be done by rewriting the TOC. We could then track users of a texture region by refcounting alone.

lordmauve commented 4 years ago

Rather than a texture, we can pass the allocations to the vertex shader in a UBO.