Question

I am trying to implement sprites in DX11, but I don't know how to proceed with texturing them.

First off, there might be multiple sprites, each using a different texture(atlas). But since I don't know how many sprites are on-screen, I can't use Texture2D[x] in my shader code.

So I looked at using Texture2DArray, but then I have to initialize the D3D11Texture2D object itself as an array of textures. That seems to me to be a problem, because in one moment, sprites A, B, C might be on screen, and the next moment sprites B, C, D are on screen. So then I would have to create two D3D11Texture2D objects, both containing the B and C textures. And in any case, it looks like textures in arrays must be of the same size..

And that's an absolute disaster. So - is there something I am missing about arrays? And what are my options for doing this in the most efficient way? Do I have to set a single texture, draw all sprites that use that texture, and repeat? Because that also seems quite bad.

Thanks in advance!

PS. I know this might be premature optimization, but I am new to DX and learning to code well/use the library well is interesting to me. So I would rather spend some time than write a bad solution.

Was it helpful?

Solution

One very common optimisation when we are drawing sprites, is to merge textures of sprites that usually appear on screen at the same time. So you can draw them all in a single Draw Call (you just have to change your texcoords).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top