Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a deflate function to TextureAtlasTiles. #42

Open
Possseidon opened this issue Mar 30, 2021 · 0 comments
Open

Add a deflate function to TextureAtlasTiles. #42

Possseidon opened this issue Mar 30, 2021 · 0 comments
Assignees
Labels
dang-gl enhancement New feature or request optimization Improves memory usage or performance in general

Comments

@Possseidon
Copy link
Owner

If a lot of similar tiles are added to a texture atlas, multiple layers for the same tile size will be created. If a lot of random tiles are removed now, this is going to create a lot of unused space in all layers, which can only be reclaimed by actually using it for newly added tiles.

Therefore a deflate function could try and reclaim all that unused space and shrink down the layer count.

Implementation:

Go through all tiles, call layerForTile to find the smallest layer index and see if it is smaller than the current one, which means an earlier layer has space for this tile. If this is the case, remove it from the current layer and add it to that layer.

The most efficient way here, would be to start with the tiles in the last layer. Otherwise, a lot of tiles might get shifted along as new spaces keeps opening up in lower layers.

The order to process the layer itself in doesn't really matter all that much unless shrink_to_fit is called on the tiles vector. Then back to front is favorable again.

@Possseidon Possseidon added enhancement New feature or request dang-gl optimization Improves memory usage or performance in general labels Mar 30, 2021
@Possseidon Possseidon self-assigned this Mar 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dang-gl enhancement New feature or request optimization Improves memory usage or performance in general
Projects
None yet
Development

No branches or pull requests

1 participant