当前位置: 动力学知识库 > 问答 > 编程问答 >

libgdx - Correct usage of TextureAtlas to limit bind time

问题描述:

I've been reading Beginning Android Games and it says there that SpriteBatcher.begin() binds the texture to be used and and clears the buffers. My question concerns the correct usage of Texture Atlases to limit the amount of time it takes to bind those textures . In the case that one ABSOLUTELY needs to use different SpriteBatchers for different sprites should one use the smallest possible number of texture atlases for the whole series of batch.begin, batch.end series?

batch1.begin()

spriteA_from_atlas_general.draw(batch1);

spriteB_from_atlas_general.draw(batch1);

....

batch1.end()

batch2.begin()

spriteX_from_atlas_general.draw(batch2);

spriteY_from_atlas_general(batch2);

....

batch2.end()

...

Or is it faster to use more TextureAtlases that will be smaller in size, one for each batch.begin, batch.end session? Because smaller texture atlases means less time to bind them.

batch1.begin()

spriteA_from_atlas1.draw(batch1);

spriteB_from_atlas1.draw(batch1);

....

batch1.end()

batch2.begin()

spriteX_from_atlas2.draw(batch2);

spriteY_from_atlas2.draw(batch2);

....

batch2.end()

...

网友答案:

In general there shouldn't be a real reason to have more than a single SpriteBatch. And you should also keep your begin() and end() calls to a minimum.

The more batches you use, and the more often you interrupt the batching via begin/end, the more performance you will lose.

If you have only single textures for your sprites and you fire your draw calls in this order A, B, A, B, A, B, then you'll have up to 6 texture bindings.

If you put both of those textures into a TextureAtlas, they will have the same texture, and there will be just a single texture binding.

The size of your atlas pages usually shouldn't make a difference. All that happens in the background is another ID to be set, the actual texture won't be moved anywhere, or processed anyhow, when you just bind another texture.

Thus you should use texture atlas pages that are as big as possible. However there is a tradeoff. The bigger the page size, the more likely some devices won't support those sizes anymore. Plus, the bigger your page size, the more memory you are likely to waste, because the pages aren't filled completely, or because you will only use a very small part of the page, but it still needs to be loaded completely.

分享给朋友:
您可能感兴趣的文章:
随机阅读: