-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
Implement growing logic for TextAtlas
#34
Conversation
I decided for my own Texture Storage to use Texture Layers With a Garbage Collector via 2 hash_maps. But after discussion this with Hecj I relies that the LRU + HashSet can be more efficient in the long run versus a Garbage like collector behind a Pressure threshhold. Edited this so others wont be confused... |
@genusistimelord I don't understand.
|
Ok yeah After discussing this with you I agree but I do think we need Texture Atlas Layering to avoid any pitfalls as resizing a Texture Atlas to a new size really doesn't solves the issue and requires us to re-upload all the glyphs currently being used individually. So I would think it be more Efficient in the long run to have the ability to use Layers and make it so a new layer is only created when there is no room in the Atlas and no room can be made by de-allocating unused Glyphs. |
Thank you for the PR! Is there a way we could perform the growing automatically internally and copy the old atlas into the new one after resizing? If it's possible, I'd prefer that callers didn't need to re- I'd also like |
@grovesNL I couldn't find a way to resize an existing We could reallocate the glyphs, but they may have different positions and the UVs of the vertices computed before the resize will be invalid. |
Good point, opened nical/etagere#22 We also might be able to work around it in the meantime by internally remapping all of the old UVs to the new UVs, but that could be complicated (especially for clipped glyphs) without storing extra info during |
52d54e3
to
c5540bf
Compare
The `TextAtlas` will have an initial size of `256` (we could make this configurable) and `try_allocate` will keep track of the glyphs in use in the current frame, returning `None` when the LRU glyph is in use. In that case, `TextRenderer::prepare` will return `PrepareError::AtlasFull` with the `ContentType` of the atlas that is full. The user of the library can then call `TextAtlas::grow` with the provided `ContentType` to obtain a bigger atlas (by `256`). A `TextAtlas::grow` call clears the whole atlas and, as a result, all of the `prepare` calls need to be repeated in a frame until they all succeed. Overall, the atlas will rarely need to grow and so the calls will not need to be repated often. Finally, the user needs to call `TextAtlas::trim` at the end of the frame. This allows us to clear the glyphs in use collection in the atlas. Maybe there is a better way to model this in an API that forces the user to trim the atlas (e.g. make `trim` return a new type and changing `prepare` and `render` to take that type instead).
I have rebased on top of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
nical/etagere#24 was finally merged, which should unblock this! I have updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thank you!
The
TextAtlas
will have an initial size of256
(we could make this configurable) andtry_allocate
will keep track of the glyphs in use in the current frame, returningNone
when the LRU glyph is in use.In that case,
TextRenderer::prepare
will returnPrepareError::AtlasFull
with theContentType
of the atlas that is full. The user of the library can then callTextAtlas::grow
with the providedContentType
to obtain a bigger atlas (by256
).A
TextAtlas::grow
call clears the whole atlas and, as a result, all of theprepare
calls need to be repeated in a frame until they all succeed. Overall, the atlas will rarely need to grow and so the calls will not need to be repated often.Finally, the user needs to call
TextAtlas::trim
at the end of the frame. This allows us to clear the glyphs in use collection in the atlas. Maybe there is a better way to model this in an API that forces the user to trim the atlas (e.g. maketrim
return a new type and changingprepare
andrender
to take that type instead).