1
\$\begingroup\$

In an attempt to batch render as many quads (sprites) as possible, I'm instance rendering a single unit-sized quad and passing in a buffer of per-instance data that includes width/height, texture coordinates, color, texture Id, etc.

Offline, I have a tool that constructs texture atlases based on any particular sprite animation, so the output is flexible in terms of texture atlas width/height, which sprites reference which texture atlas, and so on.

The end result is that I may have many texture atlases, and sprites which reference any one of those atlases for their current frame.

I need a robust solution that'll allow me to draw these sprites in any order while reducing texture binding as much as possible. After some research there are two options:

  • combine multiple 2D textures into a 2D array texture (up to GL_MAX_ARRAY_TEXTURE_LAYERS_EXT)
  • bind multiple textures in array of samplers (up to MAX_TEXTURE_IMAGE_UNITS)

The first solution I believe requires all textures to be the same height/width. The second solution seems to have a limitation that requires a constant index to access the array of samplers in the fragment shader.

I think I want to go with the second solution, but I'm worried I won't be able to properly write a fragment shader if I have to use a constant index, as I'd be getting the index via per-instance data input.

Are my above suspicions correct? Is there a known work-a-round for the second solution? Or is there a better way to do this than what I presented.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

I settled on forcing my offline tool to specify a texture atlas width and height for all the textures of that group. I now can simply use a 2D texture array and can batch an entire scene in one draw call.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .