Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL how to bind (tens of) thousands of textures at once?

Tags:

opengl

3d

So I was playing around with opengl and ran into a bit of a problem. I want to be able to use a very large amount (upwards of 15k) of small (128x128) 2D textures at once (during a single draw call). Problem is I can't figure out how to do it efficiently. Here are the approaches and their problems I have found so far:

  1. As far as I understand the standard solution to multiple textures is a GL_TEXTURE_2D_ARRAY but that usually doesn't have a max size anywhere near big enough
  2. As an alternative I could use GL_TEXTURE_3D which, usually, has a much greater allowed depth, but, as I understand, I would have to generate mipmaps manually (or maybe even not use them at all?) and could have color bleed between the layers due to floating point errors if there are thousands of layers
  3. I could try using a GL_TEXTURE_2D_ARRAY of texture atlases, but then I would also have to think of how to solve mipmapping or wrapping problems as well as color bleed Can someone please recommend a better way if there is one, or say which is better of the ones I have outlined and if I am overlooking anything?
like image 496
DFined Avatar asked Nov 14 '25 09:11

DFined


1 Answers

A bit of a follow up in case anyone has the same problem.

I chose to try the 3-rd option I outlined in the question (using TEXTURE_2D_ARRAY with each layer being a texture atlas generated from separate textures at startup) and can indeed confirm that, while not ideal and somewhat unconventional, it does, at least, work. Moreover, while it is unusual to use a texture atlas array as if it was a single atlas, texture atlases themselves are very well practiced and easy to research.

I tested it with only a few textures in total so far, but, in theory, with a typical 8192x8192x2048 2D texture array of atlases I could have up to 8 million 128x128 textures (though in practice the actual number would, of course, be far less due to VRAM limitations)

The proof of concept - a simple 1024x1024 block world with some different textures loaded through an atlas array

like image 87
DFined Avatar answered Nov 17 '25 10:11

DFined



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!