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 way to free all image data of a TextureAtlas. #38

Open
Possseidon opened this issue Mar 27, 2021 · 1 comment
Open

Add a way to free all image data of a TextureAtlas. #38

Possseidon opened this issue Mar 27, 2021 · 1 comment
Assignees
Labels
dang-gl enhancement New feature or request

Comments

@Possseidon
Copy link
Owner

Possseidon commented Mar 27, 2021

Currently a TextureAtlas stores all the image data forever. This is actually required, as new textures might be added later on, which might in turn require the underlying array texture to resize to fit all tiles, which then invalidates the already existing tiles.

However keeping all those textures around forever is quite expensive. Therefore a way to free all texture data should exist.

Of course, once all the textures are freed, no new textures can be added anymore, as this might require a resize again. To prevent this, upon freeing the textures the TextureAtlas should be in a frozen state, preventing any further modification.

It is very rare, that you actually want to keep all the texture data around, once everything has been loaded and the array texture been generated. Freeing everything is almost always the right choice afterwards.

Simple implementation:

  • Have an update function, that only updates the texture without freeing any image data.
  • Have an additional freeze function, that updates the texture and frees all image data.
  • Any modification attempts after a freeze should then throw an exception.

Idea without exceptions:

  • Make the freeze function a move only function and return different type FrozenTextureAtlas that is read-only.
  • Gets rid of frozen checks that throw exceptions.
  • FrozenTextureAtlas has an actual TextureAtlas member variable, which gets moved in but only exposes const functions.
    • Don't make the member const, as this prevents moves, which are still perfectly valid.
  • A bit more annoying to maintain when new functions are added, but probably worth the effort.
  • Will also be a bit more complicated with decoupling of the Texture2DArray in mind.

Additional afterthoughts:

  • Add the ability to mark tiles that should not be freed.
    • E.g. GUI elements might still need manual texture lookup for hit-tests.
    • Maybe even add special cases to only store relevant parts (only transparency information for hit-tests for example).
    • Turn image into a std::variant of various image formats or even just a bitfield for hit-tests.
    • Do I want an Image<bool> specialization for that? Sounds like a neat idea.
@Possseidon Possseidon added enhancement New feature or request dang-gl labels Mar 27, 2021
@Possseidon Possseidon self-assigned this Mar 27, 2021
@Possseidon Possseidon pinned this issue Mar 28, 2021
@Possseidon
Copy link
Owner Author

Implemented, but currently simply frees all textures.

Leaving this issue open, so I remember to keep the afterthought of not fully freeing all data in mind.

@Possseidon Possseidon unpinned this issue Mar 28, 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
Projects
None yet
Development

No branches or pull requests

1 participant