Spritebatch and texture arrays

Nov 20, 2014 at 12:55 AM
Does spritebatch support texture arrays?
Coordinator
Nov 20, 2014 at 2:46 AM
The shader currently is compiled for profile 9.1 which doesn't support them. It wouldn't be difficult to add a variant shader for FL 10.0+. Perhaps you can spell out the scenario you have here?
Nov 20, 2014 at 9:20 PM
Well originally I was simply trying to get a tiled sprite. I thought this would be a simple case of adding in a sampler state with wrap addressing. However, it seems the when you specify a different size source rectangle in the sprite sheet from the destination rectangle spritebatch does some scaling to make it fit 1:1. So I did some hunting and figured since the dxtk spritebatch is nearly identical in functionality to the XNA spritebatch this trick should work: TEXT and it did. The problem with this strategy is I can no longer use a spritesheet, I have to have an individual shader resource view for each texture I want to tile. It's not a big deal, it would just make the code a lot less messy if texture arrays could be used.
Nov 21, 2014 at 6:27 PM
Perhaps there is a way to prevent the scaling when specifying a source and dest RECT that I am missing?
Coordinator
Nov 22, 2014 at 4:34 AM
Afraid I don't really understand this question.

When you draw a sprite, the source rectangle specifies what texture coordinates are read from, while the dest rectangle specifies where on the screen geometry is drawn. The source region is always scaled to fit the destination - that's just the nature of how all graphics rendering works.

If your source region goes outside the bounds of the texture (<0 or >1) then you will get either wrap or clamp behavior depending on how your sampler state address mode is configured. Wrap addressing can be used to implement texture tiling, but this is not compatible with sprite sheets - D3D does not provide any way (at least not easily or efficiently) to tile just a subregion of a larger texture.

If you need to tile a texture, I suggest not putting it in a sprite sheet.
Marked as answer by walbourn on 11/21/2014 at 9:39 PM