Reputation: 659
I use OpenGL 4 for some texture manipulations in visual C++. The platform that I am working on is Visual Studio 2015. Having looked at the implementation of GL_TEXTUREi texture units, I found out that the total number is limited to 0 to 31 (32 in total).
Does it mean that the maximum number of textures that could be accessed at the same time is limited by 32?
This is from the implementation source code:
#define GL_TEXTURE0 0x84C0
#define GL_TEXTURE1 0x84C1
#define GL_TEXTURE2 0x84C2
#define GL_TEXTURE3 0x84C3
#define GL_TEXTURE4 0x84C4
#define GL_TEXTURE5 0x84C5
#define GL_TEXTURE6 0x84C6
...
#define GL_TEXTURE31 0x84DF
Upvotes: 5
Views: 10662
Reputation: 474436
The number of textures that can be bound to OpenGL is not 32 or 16. It is not what you get with glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &texture_units);
. That function retrieves the number of textures that can be accessed by the fragment shader.
See, each shader has its own limit of the number of textures it can use. However, there is also a total number of textures that can be used, period. This is defined (in OpenGL) by GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS
.
So there are two limits: the textures-per-stage, and the textures-total-bound.
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. It can have a higher limit, but you know you get at least 16. 3.x defines the minimum number for the textures-total-bound as 48. AKA: 16 * 3 stages. Similarly, GL 4.x defines the numbers to be 16 textures-per-stage, and 80 textures-total-bound (ie: 16 * 5 stages).
Again, these are the minimum numbers. Hardware can (and does) vary.
To use more texture units than there are defined enumerators, you take the value of GL_TEXTURE0
and add it to the texture unit you want to manipulate:
glActiveTexture(GL_TEXTURE0 + unit_index);
Upvotes: 20