Jump to content
  • Advertisement
Sign in to follow this  
maxgpgpu

OpenGL help: OpenGL textures units and texture arrays

This topic is 2479 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

[font=georgia, serif]My 3D engine supports textures and bumpmaps in a simple way. Now I need to revamp textures to support information I have in object vertices and also other infrastructure that's already in the engine. But I'm at a loss to find the most efficient way to organize this, partly because I can't quite grasp the limitations of GPUs and OpenGL.[/font]

[font=georgia, serif]To begin with, my approach has been to write as general a system as possible, not have many different vertex layouts and many different shaders for different situations. So, for example, I have 2 (and potentially 4) 4-bit fields reserved in each vertex to specify "which texture", "which bumpmap", "which heightmap", "which conemap", etc. My original intent was to always access "texture patterns" from texture unit #0, "bumpmap information" from texture unit #1, and so-forth (to make the code straightforward as possible), then access the appropriate texture, bumpmap and so-forth on the basis of those 4-bit fields via OpenGL "texture arrays".[/font]

[font=georgia, serif]Without getting into details, that seems like a winner approach. However, if I understand what I've read correctly, every texture in a given "texture array" must be the same size. This could get extremely inefficient from a GPU memory-consumption standpoint if I start expanding modest 64x64 or 256x256 textures for simple things like "floor tiles" to 2048x2048 or 4096x4096 size so I can put them into a single texture array with other highly detailed textures or bumpmaps. Yikes! Am I correct that every texture in a single "texture array" must be the same size and format?[/font]

[font=georgia, serif]This led me to consider an alternative. Assign texture units by "size" --- one for 64x64 textures, another for 256x256 textures, another for 1024x1024 textures, and another for 4096x4096 textures. Then, of course, any given texture unit will contain a mix of "textures", "bumpmaps", "heightmaps", "conemaps" and so forth, and I'll need to concoct some technique to distinguish "textures" from "bumpmaps" from "heightmaps" from "conemaps" from "others". Perhaps they can be assigned such that the texture-array index is 0,4,8,12 for "textures", 1,5,9,13 for "bumpmaps", and so forth. One limitation this brings is "no repeating textures", because the textures we want to repeat are almost always small textures that would be applied to a subregion of a large texture atlas texture. I don't suppose OpenGL can support a "repeating" mode on subsections of a larger texture, right? Nah, that would be too convenient.[/font]

[font=georgia, serif]Another possibility is to always (and automatically) create only 4096x4096 textures, and when the engine receives textures smaller than 4096x4096, just glue them into a section of a 4096x4096 "texture atlas texture" and adjust vertex tcoord values accordingly. That would let me adopt the first approach, where each texture unit is exclusively assigned to a specific kind of texture (texture, bumpmap, heightmap, conemap, etc).[/font]

[font=georgia, serif]Recall that I'm trying to make a highly general system. Currently I can render every triangle on every object with one single "uber shader" (as someone called them somewhere). I intend to attempt to keep this approach if possible, and if I must "give in", it should only to adopt at most two or three shaders... at least for rendering. I don't want to be changing shaders like crazy like so many engines do. Currently I could literally render every triangle on every object with one single draw call, though I don't because I maintain several batches that contain objects based upon their location in 3D space (so whole batches can be "not drawn" because they're entirely outside the frustum).[/font]

[font=georgia, serif]I have found the various discussions of OpenGL textures confusing. I'm sure that's partly because not every discussion was written on the basis of the same (or current) version of OpenGL and GLSL. My code currently requires OpenGL and GLSL v3.20, but I'm willing to update to a newer version if handling textures becomes more generalized or flexible.[/font]

[font=georgia, serif][font=georgia, serif]How many "texture units" can I assume all high-end GPU cards to support (on the order of GTX580 or newer)?[/font][/font]
[font=georgia, serif] [/font]
[font=georgia, serif]In your opinion, what's the best way to achieve what I'm trying to achieve with OpenGL?[/font]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!