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

后端 未结 2 748
逝去的感伤
逝去的感伤 2021-02-07 23:48

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 o

2条回答
  •  深忆病人
    2021-02-08 00:27

    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.

提交回复
热议问题