DrawAtlas Method Signature is Unclear To Me

108 views
Skip to first unread message

James Houx

unread,
May 11, 2022, 2:16:02 PM5/11/22
to skia-discuss
The drawAtlas comment says "Draws a set of sprites from atlas..."

The comment leads me to believe I could provide 1 or more sprites as well as an array of destination positions with optional destination RSXform matrices so that each sprite can be drawn in a specific position with a specific transform.

However, the commenting on the signature doesn't connect the dots for me.

From what I understand about "drawImage", to draw an image many times with different destination position/rotation/scale for each draw command. If I invoke drawImage 1000 times without changing the basic GL state, then the 1000 commands should happen quickly in one draw call.

If drawAtlas worked the same way as drawImage, that would mean I have to invoke drawAtlas 1000 times to draw sprites in 1000 destination positions.  Even though that makes sense conceptually, it leaves me confused as to why the drawAtlas parameters take an array of xforms and an array of SKRect tex[] for source atlas sprite positions.  It makes me think one invocation of drawAtlas will draw all of tex array sprites in into the same destination (effectively overlapping them).  Is this what is supposed to happen?

Maybe this is an area where the API documentation could use a bit of improvement?

Thank you in advanced for any help!!!!  Skia is wonderful!

Brian Osman

unread,
May 11, 2022, 2:40:32 PM5/11/22
to skia-d...@googlegroups.com
The idea is that you have all of your individual sprite images combined into a single, larger image (the "atlas" or "sprite sheet"). So there is only a single image used to do all of the drawing. For each sprite that you want to draw:

- tex[i] defines where the data for that sprite is, within the image. So (for example), if you had 4 32x32 sprites for different types of characters in a single 64x64 image, each entry of tex would be one of: { 0, 0, 32, 32 }, { 32, 0, 64, 32 }, { 0, 32, 32, 64 }, { 32, 32, 64, 64 }.
- xform[i] defines how that sprite is transformed (rotated, scaled, and translated) when placed in the destination

It's a very poor example (because the image being used is a single large picture, rather than a sprite sheet), but this example might help? https://fiddle.skia.org/c/ecc5a1ac9de0bc262c299a2bb9ae1915

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/982fc3e0-9ded-4d3e-a5e3-15760adc15f0n%40googlegroups.com.

Jim Van Verth

unread,
May 11, 2022, 5:07:11 PM5/11/22
to skia-d...@googlegroups.com
SampleAtlas.cpp is another place to look. It generates a sprite atlas by rendering glyphs to a texture, and then uses that to draw animated text with drawAtlas.



--

Jim Van Verth | Software Engineer | jvan...@google.com | 919-210-7664

Reply all
Reply to author
Forward
0 new messages