问题描述
OpenGL中可以创建的纹理数量是否有限制?也就是说,使用glGenTextures吗?
我知道GL有一些限制,例如。可以在片段着色器中使用的纹理的数量。然而,我还没有找到任何有关可用的整数纹理名称总数的文档。 解决方案 div>
glGenTextures的唯一限制是由纹理名称( GLint )的位宽给出的,它是32位;实际上纹理名称的数量可以非常多,以至于在生成纹理名称时您可能永远不会遇到问题。
纹理的限制是图形系统内存的限制。 OpenGL实现仅在应用程序使用 glTexImage2D (以及其他glTexImage *函数(如果可用))提交纹理数据时才知道纹理大小和格式,它指定宽度,高度和内部纹理格式:使用这些参数可以确定存储纹理数据所需的内存。
要检查错误,您应该使用 glGetError 查询OpenGL错误,该错误返回GL_OUT_OF_MEMORY如果操作未能分配所需的内存。这个错误也可以通过 glGenTextures 和 glTexImage2D 等返回。
这个错误最有可能返回 glTexImage2D 等,因为纹理分配所需的内存比标记纹理名称所需的内存大得多。
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.
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.
这篇关于glGenTextures - 纹理数量是否有限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!