3

I'm rolling my very first game engine :D. I'm working on the texture resource manager now, and I want to do it right.

Is it bad in any way to just fill up all of the ActiveTexture units that the driver supports? The alternative would be to conserve these slots and only set textures when they are actually needed, at the expense of more glBindTexture calls.

Hannesh
  • 6,768
  • 6
  • 42
  • 77
  • 1
    What do yo mean by 'slots'? You just keep as many textures in memory as needed and (ideally) bind only when necessary, trying to avoid the call if the correct texture is already binded. – Julio Gorgé Mar 03 '11 at 23:53
  • Ah sorry. By slots I meant meant units. As in the thing you select with a glActiveTexture(...) call ;). – Hannesh Mar 04 '11 at 00:01

2 Answers2

5

The way you asked your question I think you suffer from a misconception between texture objects i.e. the texture storage, and texture units i.e. the machinery behind multitexturing.

OpenGL has texture object and texture units. Texture objects hold the data, texture units map the data of the texture object that's bound to them into the rendering process.

Usually one uploads all the textures needed for a scene into texture objects. And for each render batch that makes use of common material settings binds the textures to the right texture units in the rendering process.

datenwolf
  • 149,702
  • 12
  • 167
  • 273
  • I'm sorry if my question was unclear, I do understand the difference between textures and texture units. If GL_MAX_TEXTURE_UNITS is greater than the number of textures I have, can I just map all textures into the texture units, and avoid having to use glBindTexture calls during drawing at all? – Hannesh Mar 04 '11 at 10:20
  • 1
    Sure you can do this, but what do you think was the benefit. Having all the textures bound to texture units will make the GPU sample from them. Unless you deactive single texture units, in which case the un-/binding doesn't cause any additional cost. The whole cose of binding a texture or enabling a texture units stems from cache invalidation. A much better approach to improve rendering performance is to sort drawing operations by used material and texture state and keep state switches to a minium. And dis-/enabling a texture unit also has its costs. – datenwolf Mar 04 '11 at 10:34
  • 1
    @datenwolf: Your answer here along with the dye/painting analogy here http://stackoverflow.com/questions/8866904/need-help-understanding-the-differences-and-relationship-between-glactivetexture (again by you) made me understand texture management in OpenGL :) Thanks! – legends2k Sep 05 '12 at 15:51
2

I think it's also to be noted if you're going to be using tons of textures, i.e uploading to the GPU you need to consider an approach to minimize the VRAM usage. In any case what I think might be a benifit on your behalf is stb_dxt which is a DXT1/DXT5 compressor wrote in ansi C. You can compress your textures and upload them using CompressedTexture2D, this way all textures you upload to the GPU will take 1/8th their normal space.

At some point compressing all the textures at runtime will slow down the loading of your game, which is why I would suggest using DDS textures, you can use nvidia-texture tools for converting / managing compression of your textures externally.

graphitemaster
  • 3,055
  • 4
  • 17
  • 14