Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

SpriteAtlas adds all images to the texture #9019

Closed

Description

@jfirebaugh

Prior to 5cdf838, SpriteAtlas added images to the texture atlas on an as-needed basis, as individual images were requested via SpriteAtlas::getIcon. Now it preemptively adds all images to the texture when buildIconMap is called.

Not sure how important the old behavior was. Though, at the very least, buildIconMap should handle the case where the BinPack overflows and getIcon returns a null optional.

cc @ChrisLoer

Activity

  1. added
    Core
    performance
    on May 17, 2017
  2. mb12 commented on May 17, 2017

    @mb12

    I've included below an explanation for why it is done this way. @ChrisLoer can you please kindly correct me if my understanding is wrong?

    Binpacking of individual spriteatlas elements determines the texel coordinates/UV mapping. Every consumer of texel coordinates for an icon must see the same value. Doing it at the very beginning/together fixes the texel coordinates for all the threads.

    Here are examples of different scenarios which would otherwise need synchronization.

    1. Symbolbucket needs texel coordinate of each icon as an attribute so that it can coalesce drawing of multiple icons in one 'drawTriangles' call.
      Geometrytile workers in separate threads (separate from renderer thread) must see the same texel coordinate for icons with same name.

    2. When rendering fill patterns need to fill the same icon for all the triangles. For these cases texel coordinates can be passed as uniform vec2. The renderer thread also needs to see the same texel coordinates as the worker threads.

    If you wish to dynamically resize SpriteAtlas, you must address the following issues.

    1. All threads (both worker and renderer) should get the same texel coordinates for an icon.
    2. Resizing the SpriteAtlas should not change the position of icons already in use. Otherwise it would invalidate the tex attributes for all vertices uses in symbol buckets.
    3. From an opengl perspective u,v coordinates are normalized to [0, 1]. So access to SpriteAtlas.width/height must also be synchronized.
  3. ChrisLoer commented on May 17, 2017

    @ChrisLoer
    Contributor

    @mb12 Yeah, those are pretty much the synchronization concerns we have to worry about here -- although GlyphAtlas has all the same concerns and handles incremental updates requested by multiple threads, so we have a pattern we can follow.

    @jfirebaugh A lot of the plumbing is actually in place for adding sprites incrementally (we pass dependencies all the way to GeometryTile::getIcons but discard them there). I suspect the extra up-front copying of PremultipliedImages is a pretty small cost, but I hadn't thought through handling overflow. If we're going to support the "more sprites provided than can fit in the SpriteAtlas" case, it seems like we should do it by keeping track of what's requested instead of just dropping sprites based on their order in the data.

  4. self-assigned this
    on May 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Coreperformance

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions