# of usable Tex Units

Started by
9 comments, last by Krohm 16 years, 2 months ago
Okay, my dilemma is that when queried, OpenGL tells me I have a maximum of 4 Texture Units available for multi-texturing/uploading to shader. However, when I ran the most recent Code Sampler HDR demo, I noticed that they used 5 texture units. So what gives? What is the actual number I have to work with? Or am I limited for good performance, and can get more for a performance hit? Any help would be appreciated.

[Hardware:] Falcon Northwest Tiki, Windows 7, Nvidia Geforce GTX 970

[Websites:] Development Blog | LinkedIn
[Unity3D :] Alloy Physical Shader Framework

Advertisement
The GL limit 'GL_MAX_TEXTURE_UNITS_ARB' gives you the maximum number of usable texture units in FFP. But when you are in programmable pipeline, you can use upto 'GL_MAX_TEXTURE_IMAGE_UNITS_ARB' texture units. Moreover GL_MAX_TEXTURE_IMAGE_UNITS_ARB >= GL_MAX_TEXTURE_UNITS_ARB.

For instance in my X1600 card GL_MAX_TEXTURE_UNITS_ARB = 8 and GL_MAX_TEXTURE_IMAGE_UNITS_ARB = 16.
Best Regards,KumGame07
Now that I've made that change, it says I have 16. Thanks for the info. ;)

However, that number needs clarification. That can't possibly mean I can have 16 textures bound, can it?

[Hardware:] Falcon Northwest Tiki, Windows 7, Nvidia Geforce GTX 970

[Websites:] Development Blog | LinkedIn
[Unity3D :] Alloy Physical Shader Framework

Yes, you can call glActiveTexture(GL_TEXTURE15) and glBindTexture
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Quote:Original post by n00body
That can't possibly mean I can have 16 textures bound, can it?
Yes, exactly. Take care however that only the first
GL_MAX_TEXTURE_UNITS do have complete state (such as tcGen and possibly texCoords).

Previously "Krohm"

Quote:Original post by Krohm
Quote:Original post by n00body
That can't possibly mean I can have 16 textures bound, can it?
Yes, exactly. Take care however that only the first
GL_MAX_TEXTURE_UNITS do have complete state (such as tcGen and possibly texCoords).


There is no TexGen because TexGen is for the fixed function. You should not even call glTexEnv. TexEnv is for fixed pipeline as well.
For texcoords, you need to query it. I think it was GL_MAX_TEXCOORDS or something like that.
Some of these cards have 16 image units and 8 texcoords.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
FYI max texture coordinates will be tied to the max vertex attributes, e.g. normals, vertices, texture coordinates, color ect... Last I checked there was only 16 registers for this on current cards so this is why we have 8 texture coordinates still.

attribute vec4 gl_Vertex;
attribute vec3 gl_Normal;
attribute vec4 gl_Color;
attribute vec4 gl_SecondaryColor;
attribute vec4 gl_MultiTexCoord0;
attribute vec4 gl_MultiTexCoord1;
attribute vec4 gl_MultiTexCoord2;
attribute vec4 gl_MultiTexCoord3;
attribute vec4 gl_MultiTexCoord4;
attribute vec4 gl_MultiTexCoord5;
attribute vec4 gl_MultiTexCoord6;
attribute vec4 gl_MultiTexCoord7;
attribute float gl_FogCoord;

is the list of attributes, and I think you have a few open slots, which I use for tangents and bitangents.
Quote:Original post by V-man
There is no TexGen because TexGen is for the fixed function. You should not even call glTexEnv. TexEnv is for fixed pipeline as well.

This is not quite the reason. In fact, texGen is a geometry operation and you can mix and match vertex-FFP with pixel shading. But even assuming you cannot, the wording, if you read the spec is quite similar...
Quote:From ARB_f_s spec
(16) Should aux texture units be additional units on top of existing
full-featured texture units, or should this spec fully deprecate
"legacy" texture units and only expose texture coordinate sets and
texture image units?

Background: Some implementations are able to expose more
"texture image units" (texture maps and associated parameters)
than "texture coordinate sets" (current texcoords, texgen, and
texture matrices). A conventional GL "texture unit" encompasses
both a texture image unit and a texture coordinate set as well as
texture environment state.

RESOLVED: Yes, deprecate "legacy" texture units. This is a more
flexible model.

...

specifies the active texture unit selector, ACTIVE_TEXTURE. Each
texture unit contains up to two distinct sub-units: a texture
coordinate processing unit (consisting of a texture matrix stack and
texture coordinate generation state
) and a texture image unit
(consisting of all the texture state defined in Section 3.8). In
implementations with a different number of supported texture
coordinate sets and texture image units, some texture units may
consist of only one of the two sub-units.

The active texture unit selector specifies the texture coordinate
set accessed by commands involving texture coordinate processing.
Such commands include those accessing the current matrix stack (if
MATRIX_MODE is TEXTURE), TexGen (section 2.10.4), Enable/Disable (if
any texture coordinate generation enum is selected), as well as
queries of the current texture coordinates and current raster
texture coordinates. If the texture coordinate set number
corresponding to the current value of ACTIVE_TEXTURE is greater than
or equal to the implementation-dependent constant
MAX_TEXTURE_COORDS_ARB, the error INVALID_OPERATION is generated by
any such command.

In general, a good reading of the spec is absolutely necessary to understand the key differences between image units and fully fledged texture units, it's heavily suggested, before you learn it the hard way.

Previously "Krohm"

Quote:Original post by MARS_999
FYI max texture coordinates will be tied to the max vertex attributes, e.g. normals, vertices, texture coordinates, color ect... Last I checked there was only 16 registers for this on current cards so this is why we have 8 texture coordinates still.

attribute vec4 gl_Vertex;
attribute vec3 gl_Normal;
attribute vec4 gl_Color;
attribute vec4 gl_SecondaryColor;
attribute vec4 gl_MultiTexCoord0;
attribute vec4 gl_MultiTexCoord1;
attribute vec4 gl_MultiTexCoord2;
attribute vec4 gl_MultiTexCoord3;
attribute vec4 gl_MultiTexCoord4;
attribute vec4 gl_MultiTexCoord5;
attribute vec4 gl_MultiTexCoord6;
attribute vec4 gl_MultiTexCoord7;
attribute float gl_FogCoord;

is the list of attributes, and I think you have a few open slots, which I use for tangents and bitangents.


I thought that use of those conventions was being deprecated in favor of glVertexAttribPointers.

[Hardware:] Falcon Northwest Tiki, Windows 7, Nvidia Geforce GTX 970

[Websites:] Development Blog | LinkedIn
[Unity3D :] Alloy Physical Shader Framework

Quote:This is not quite the reason. In fact, texGen is a geometry operation and you can mix and match vertex-FFP with pixel shading. But even assuming you cannot, the wording, if you read the spec is quite similar...


What I mean is that you might have 16 image units, but texGen will not work on tex unit 8 and above.
Image units are just for binding the texture and you sample it in your shader.

If you want don't want to use a vertex shader, that's fine but you still can't use all the image units the way you typically want to use them.

[Edited by - V-man on February 7, 2008 7:44:52 PM]
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement