Android OpenGL ES 2.0 Only Limited To 16 Textures In Memory?

北城以北 提交于 2019-12-01 18:15:23

The total number of texture objects is not normally limited. At least not within any reasonably range, theoretically you will run of ids that can be represented by a GLuint at some point. But you will run out of memory long before that happens. So the only practical limit is normally given by the amount of memory used for the texture data.

However, the number of texture units is very much limited. And from a quick look at your code, that's what you run into. From your texture loading code:

glActiveTexture(GL_TEXTURE0 + index);
glBindTexture(GL_TEXTURE_2D, texture[index]);

What you're trying to do is keep all textures bound, using a different texture unit for each. Then when you draw, you select which texture unit the shader samples from:

glUniform1i(uTextureUnit, index);

This is a perfectly valid approach... until you run out of texture units. Which is exactly what happens.

The maximum number of texture units is implementation dependent, and can be queried with:

GLint maxUnits = 0;
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxUnits);

The minimum for this value is 8. So unless you check the value, and find more, you can only rely on having 8 texture units.

If you need more than 8 textures, and want your code to run reliably across devices, your somewhat unconventional approach of keeping all textures bound will not work.

The easiest approach is that you do what most people do: Bind the texture you want to use before drawing. For this, you can always use texture unit 0. So you can remove all calls to glActiveTexture(), and simply place a bind call in the Draw_Polygon() method, instead of the glUniform1i() call:

glBindTexture(GL_TEXTURE_2D, texture[index]);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!