The 2024 Wheel Reinvention Jam is in 16 days. September 23-29, 2024. More info

Drawing multiple textures in one draw call

I was wondering how Casey ended up drawing multiple textures in one draw call? I remember he talked about that texture atlases are just one way of doing it, but never saw what Casey did.

My only understanding of how to do it is use a texture array and have an index for each instance. Is this a reasonable solution? What's the usual approach without using texture atlases? Are bindless textures relate to this?

Thanks 🙂

He's doing array texture for that.

Alternative to that is doing texture atlas - then you need to be careful with padding & mipmaps. If you don't need mipmaps, then things are simple - do 1 extra padding if you're doing linear filtering (or do simple math in shader to clamp to item borders).

Bindless textures also help if you're ok with non-core extension, and not supporting older GPU's / driver versions. It allows to pass handle to texture inside vertex attribute or vertex buffer or any other kind of data structure you have in UBO/SSBO or otherwise. This way you can use different texture per each element you draw in the same draw call.


Edited by Mārtiņš Možeiko on

Thanks Martins, is the texture array Casey used sampler2darray?


Edited by Oliver Marsh on

Yes. You need to use sampler2DArray for array texture.


Edited by Mārtiņš Možeiko on
Replying to OliverMarsh (#25748)

Sorry to bump this again, what's the equivalent to sampler2Darray in d3d11?


Edited by Oliver Marsh on

D3D11 has separate sampler state from texture. For sample state you do your regular sampler object - that does not depend on texture type.

Then you define Texture2DArray on which you will use any sampler you want and pass float3 (u,v,index) for Sample() method: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-sample


Edited by Mārtiņš Možeiko on

thanks martins :)


Replying to mmozeiko (#25805)

Hi, just a couple more questions :)

How did Casey manage the texture2Darrays? Did he alter the texture data when the game needed to draw a new texture that hadn't been loaded yet? Would this be a map/unmap call in d3d11?

I should watch the specific videos casey did this, does anyone know which these ones are?

Thankyou :)

Last time I saw the that part code it updated slice of texture with glTexSubImage3D whenever needed.

On D3D you have different options - if you're updating often, then probably having staging texture (because you cannot write from cpu to default textures), then mapping/memcpy/unmap & copy to actual texture is probably best way. If that happens only occasionally, then UpdateSubresource is fine.


Replying to OliverMarsh (#25820)

Thanks again Martins