From what I understand, SpriteBatch's purpose is to batch as many draw operations to send to the GPU. Each batch can handle one texture at a time, and changing SpriteBatch context/texture is expensive, so when you need to draw many different textures in one frame you use a texture atlas, putting sprites that are most likely to be drawn by the same component in the same page.
So my questions are:
- Assuming there are numerous components using the same texture page, how am I supposed to group them together and issue their drawing method?
- What is an efficient way to deal with a component that uses sprites from two different texture pages? Should I handle two different drawing methods for each texture page? or perhaps take the context texture page as parameter and draw only what's relevant for it?
- What about dynamically generated textures?
- What if you don't know which texture pages a component needs? (For example, a custom visual equipment where you can't possible put all the equips in the same texture page since there might be thousands of em, and it's determined only at runtime)
I've seen many articles on how SpriteBatches work technically but nothing meaningfull on how to actually make the best use out of them. Would a good solution be to somehow queue my draw operations sorted by texture? If so, what would be a good generic way to implement it?