Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glGenTextures - is there a limit to the number of textures?

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.

like image 996
Zilchonum Avatar asked Jun 15 '11 07:06

Zilchonum


People also ask

How many textures can you have in OpenGL?

OpenGL 3. x defines the minimum number for the per-stage limit to be 16, so hardware cannot have fewer than 16 textures-per-stage.

How are textures stored in OpenGL?

There are three kinds of storage for textures: mutable storage, immutable storage, and buffer storage. Only Buffer Textures can use buffer storage, where the texture gets its storage from a Buffer Object. And similarly, buffer textures cannot use mutable or immutable storage.

What is OpenGL es texture?

The OpenGL method can be used to generate multiple handles at the same time; here we generate just one. Once we have a texture handle, we use it to load the texture. First, we need to get the texture in a format that OpenGL will understand.

How do you change textures in OpenGL?

To replace texture data, just bind the texture and call glTexImage2D with the new data. bindTexture, at least the opengl one, just binds a texture name to a specific target, GL_TEXTURE_2D here. It does not delete or replace anything, just put a particular texture in use.


1 Answers

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.

like image 104
Luca Avatar answered Oct 14 '22 00:10

Luca