18

Is there a limit to the number of textures that can be created in OpenGL - that is, with glGenTextures?

I know that there are some limits imposed by GL, eg. the number of textures that can be used in a fragment shader. However, I haven't been able to find any sort of documentation concerning the total number of integer "texture names" that are available to use.

2 Answers 2

24

The only limit of glGenTextures is given by the bit width of the texture name (GLint), which is 32 bit; indeed the number of texture names can be so great that you will probably never have problems when generating texture names.

The limit for textures is that of the graphics system's memory. The OpenGL implementation knows the texture size and format only when the application submits texture data using glTexImage2D (and other glTexImage* functions if available), which specifies the width, height and the internal texture format: having those parameters it's possible to determine the memory needed to store the texture data.

To check errors, you should query OpenGL error using glGetError, which returns GL_OUT_OF_MEMORY if the operation fails to allocate the required memory. This error can also be returned by glGenTextures and glTexImage2D etc.

This error is most likely to be returned by glTexImage2D etc., since the memory required for texture allocation is much larger than the memory required for marking a texture name as used.

1
  • 5
    Additionally, if you want to see if a texture can be created, use GL_PROXY_TEXTURE_*D when calling glTexImage to do a sort of dry-run. In doing this, you can avoid an error. Whether this is valuable or not, I'm not sure, since I don't think glTexImage failing is likely to cause any serious problems, but it's worth knowing nonetheless (especially if you want to test system capabilities).
    – user457812
    Jun 15, 2011 at 8:08
3

There is no limit on the number of texture names you can generate. There is a limit on texture memory however, so an implementation can still fail a glGenTextures call due to memory limitations.

So don't create a bunch of texture names and then not use them. Create what you need.

1
  • 1
    And make sure to delete them when you are done! otherwise your code will crash with a memory warning and you have no idea where it came from!
    – P i
    Jun 28, 2011 at 10:02

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.