TextureUnit on opengl (using opentk)

Generally this code:

GL.AttiveTexture(TextureUnit.Texture0);

GL.BindTExture(TextureTarget.Texture2D,textureId);

shader.SetInt (uniformName, textureNumber); // shader is from a class definition, simply encapsulates the shader functionality, nothing to do with opentk

 

TexutureUnit, opengl 32 are defined. From 0x84c0 increments, the decimal is 33984.

It could thus be written like this:

public void Active(TextureUnit unit, Shader shader, string uniformName) {
GL.ActiveTexture(unit);
GL.BindTexture(TextureTarget.Texture2D, this.TextureId);
int textureNumber = (int)unit - (int)TextureUnit.Texture0;
shader.SetInt(uniformName, textureNumber);
}

Further testing found that, in fact TextureUnit can be any number, is not limited to 31 digits after 33884. Although opentk designed TextureUnit this enumeration, enumeration but we all know that is essentially Int, it can turn strong. Int turn into arbitrary numbers can be.

Look opengl official document had this to say:

void glActiveTexture( GLenum texture);

Parameters

texture

Specifies which texture unit to make active. The number of texture units is implementation dependent, but must be at least 80. texture must be one of GL_TEXTUREi, where i ranges from zero to the value ofGL_MAX_COMBINED_TEXTURE_IMAGE_UNITS minus one. The initial value is GL_TEXTURE0.

Description

glActiveTexture selects which texture unit subsequent texture state calls will affect. The number of texture units an implementation supports is implementation dependent, but must be at least 80.

Errors

GL_INVALID_ENUM is generated if texture is not one of GL_TEXTUREi, where i ranges from zero to the value of GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS minus one.

 

It said, TextureUnit minimum value is GL_Texture0, is the largest + GL_Texture0 GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS , header files define search opengl, this value is 35661.

But the actual OpenGL implementation, any value that can be used, int the maximum, minimum values ​​are tested, there is no problem. As long as the shader parameter settings when minus GL_Texture0 on the line, even the overflow can work properly. It seems when opengl achieve, it is to make it as a digital processing algorithm is simple subtraction, so in order to work properly.

However, it is best to follow norms. Because, according to the standard opengl, set too large too small TextureUnit value, the error should be.

Guess you like

Origin www.cnblogs.com/mooniscrazy/p/11280186.html