glGetActiveUniform.3G man page

glGetActiveUniform — Returns information about an active uniform variable for the specified program object

C Specification

void glGetActiveUniform(GLuint program, GLuint index, GLsizei bufSize, GLsizei *length, GLint *size, GLenum *type, GLchar *name);

Parameters

program

Specifies the program object to be queried.

index

Specifies the index of the uniform variable to be queried.

bufSize

Specifies the maximum number of characters OpenGL is allowed to write in the character buffer indicated by name.

length

Returns the number of characters actually written by OpenGL in the string indicated by name (excluding the null terminator) if a value other than NULL is passed.

size

Returns the size of the uniform variable.

type

Returns the data type of the uniform variable.

name

Returns a null terminated string containing the name of the uniform variable.

Description

glGetActiveUniform returns information about an active uniform variable in the program object specified by program. The number of active uniform variables can be obtained by calling glGetProgram() with the value GL_ACTIVE_UNIFORMS. A value of 0 for index selects the first active uniform variable. Permissible values for index range from zero to the number of active uniform variables minus one.

Shaders may use either built-in uniform variables, user-defined uniform variables, or both. Built-in uniform variables have a prefix of "gl_" and reference existing OpenGL state or values derived from such state (e.g., gl_DepthRangeParameters, see the OpenGL Shading Language specification for a complete list.) User-defined uniform variables have arbitrary names and obtain their values from the application through calls to glUniform(). A uniform variable (either built-in or user-defined) is considered active if it is determined during the link operation that it may be accessed during program execution. Therefore, program should have previously been the target of a call to glLinkProgram(), but it is not necessary for it to have been linked successfully.

The size of the character buffer required to store the longest uniform variable name in program can be obtained by calling glGetProgram() with the value GL_ACTIVE_UNIFORM_MAX_LENGTH. This value should be used to allocate a buffer of sufficient size to store the returned uniform variable name. The size of this character buffer is passed in bufSize, and a pointer to this character buffer is passed in name.

glGetActiveUniform returns the name of the uniform variable indicated by index, storing it in the character buffer specified by name. The string returned will be null terminated. The actual number of characters written into this buffer is returned in length, and this count does not include the null termination character. If the length of the returned string is not required, a value of NULL can be passed in the length argument.

The type argument will return a pointer to the uniform variable's data type. The symbolic constants returned for uniform types are shown in the table below.

Returned Symbolic Contant Shader Uniform Type
GL_FLOATfloat
GL_FLOAT_VEC2vec2
GL_FLOAT_VEC3vec3
GL_FLOAT_VEC4vec4
GL_DOUBLEdouble
GL_DOUBLE_VEC2dvec2
GL_DOUBLE_VEC3dvec3
GL_DOUBLE_VEC4dvec4
GL_INTint
GL_INT_VEC2ivec2
GL_INT_VEC3ivec3
GL_INT_VEC4ivec4
GL_UNSIGNED_INTunsigned int
GL_UNSIGNED_INT_VEC2uvec2
GL_UNSIGNED_INT_VEC3uvec3
GL_UNSIGNED_INT_VEC4uvec4
GL_BOOLbool
GL_BOOL_VEC2bvec2
GL_BOOL_VEC3bvec3
GL_BOOL_VEC4bvec4
GL_FLOAT_MAT2mat2
GL_FLOAT_MAT3mat3
GL_FLOAT_MAT4mat4
GL_FLOAT_MAT2x3mat2x3
GL_FLOAT_MAT2x4mat2x4
GL_FLOAT_MAT3x2mat3x2
GL_FLOAT_MAT3x4mat3x4
GL_FLOAT_MAT4x2mat4x2
GL_FLOAT_MAT4x3mat4x3
GL_DOUBLE_MAT2dmat2
GL_DOUBLE_MAT3dmat3
GL_DOUBLE_MAT4dmat4
GL_DOUBLE_MAT2x3dmat2x3
GL_DOUBLE_MAT2x4dmat2x4
GL_DOUBLE_MAT3x2dmat3x2
GL_DOUBLE_MAT3x4dmat3x4
GL_DOUBLE_MAT4x2dmat4x2
GL_DOUBLE_MAT4x3dmat4x3
GL_SAMPLER_1Dsampler1D
GL_SAMPLER_2Dsampler2D
GL_SAMPLER_3Dsampler3D
GL_SAMPLER_CUBEsamplerCube
GL_SAMPLER_1D_SHADOWsampler1DShadow
GL_SAMPLER_2D_SHADOWsampler2DShadow
GL_SAMPLER_1D_ARRAYsampler1DArray
GL_SAMPLER_2D_ARRAYsampler2DArray
GL_SAMPLER_1D_ARRAY_SHADOWsampler1DArrayShadow
GL_SAMPLER_2D_ARRAY_SHADOWsampler2DArrayShadow
GL_SAMPLER_2D_MULTISAMPLEsampler2DMS
GL_SAMPLER_2D_MULTISAMPLE_ARRAYsampler2DMSArray
GL_SAMPLER_CUBE_SHADOWsamplerCubeShadow
GL_SAMPLER_BUFFERsamplerBuffer
GL_SAMPLER_2D_RECTsampler2DRect
GL_SAMPLER_2D_RECT_SHADOWsampler2DRectShadow
GL_INT_SAMPLER_1Disampler1D
GL_INT_SAMPLER_2Disampler2D
GL_INT_SAMPLER_3Disampler3D
GL_INT_SAMPLER_CUBEisamplerCube
GL_INT_SAMPLER_1D_ARRAYisampler1DArray
GL_INT_SAMPLER_2D_ARRAYisampler2DArray
GL_INT_SAMPLER_2D_MULTISAMPLEisampler2DMS
GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAYisampler2DMSArray
GL_INT_SAMPLER_BUFFERisamplerBuffer
GL_INT_SAMPLER_2D_RECTisampler2DRect
GL_UNSIGNED_INT_SAMPLER_1Dusampler1D
GL_UNSIGNED_INT_SAMPLER_2Dusampler2D
GL_UNSIGNED_INT_SAMPLER_3Dusampler3D
GL_UNSIGNED_INT_SAMPLER_CUBEusamplerCube
GL_UNSIGNED_INT_SAMPLER_1D_ARRAYusampler2DArray
GL_UNSIGNED_INT_SAMPLER_2D_ARRAYusampler2DArray
GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLEusampler2DMS
GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAYusampler2DMSArray
GL_UNSIGNED_INT_SAMPLER_BUFFERusamplerBuffer
GL_UNSIGNED_INT_SAMPLER_2D_RECTusampler2DRect
GL_IMAGE_1Dimage1D
GL_IMAGE_2Dimage2D
GL_IMAGE_3Dimage3D
GL_IMAGE_2D_RECTimage2DRect
GL_IMAGE_CUBEimageCube
GL_IMAGE_BUFFERimageBuffer
GL_IMAGE_1D_ARRAYimage1DArray
GL_IMAGE_2D_ARRAYimage2DArray
GL_IMAGE_2D_MULTISAMPLEimage2DMS
GL_IMAGE_2D_MULTISAMPLE_ARRAYimage2DMSArray
GL_INT_IMAGE_1Diimage1D
GL_INT_IMAGE_2Diimage2D
GL_INT_IMAGE_3Diimage3D
GL_INT_IMAGE_2D_RECTiimage2DRect
GL_INT_IMAGE_CUBEiimageCube
GL_INT_IMAGE_BUFFERiimageBuffer
GL_INT_IMAGE_1D_ARRAYiimage1DArray
GL_INT_IMAGE_2D_ARRAYiimage2DArray
GL_INT_IMAGE_2D_MULTISAMPLEiimage2DMS
GL_INT_IMAGE_2D_MULTISAMPLE_ARRAYiimage2DMSArray
GL_UNSIGNED_INT_IMAGE_1Duimage1D
GL_UNSIGNED_INT_IMAGE_2Duimage2D
GL_UNSIGNED_INT_IMAGE_3Duimage3D
GL_UNSIGNED_INT_IMAGE_2D_RECTuimage2DRect
GL_UNSIGNED_INT_IMAGE_CUBEuimageCube
GL_UNSIGNED_INT_IMAGE_BUFFERuimageBuffer
GL_UNSIGNED_INT_IMAGE_1D_ARRAYuimage1DArray
GL_UNSIGNED_INT_IMAGE_2D_ARRAYuimage2DArray
GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLEuimage2DMS
GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAYuimage2DMSArray
GL_UNSIGNED_INT_ATOMIC_COUNTERatomic_uint

If one or more elements of an array are active, the name of the array is returned in name, the type is returned in type, and the size parameter returns the highest array element index used, plus one, as determined by the compiler and/or linker. Only one active uniform variable will be reported for a uniform array.

Uniform variables that are declared as structures or arrays of structures will not be returned directly by this function. Instead, each of these uniform variables will be reduced to its fundamental components containing the "." and "[]" operators such that each of the names is valid as an argument to glGetUniformLocation(). Each of these reduced uniform variables is counted as one active uniform variable and is assigned an index. A valid name cannot be a structure, an array of structures, or a subcomponent of a vector or matrix.

The size of the uniform variable will be returned in size. Uniform variables other than arrays will have a size of 1. Structures and arrays of structures will be reduced as described earlier, such that each of the names returned will be a data type in the earlier list. If this reduction results in an array, the size returned will be as described for uniform arrays; otherwise, the size returned will be 1.

The list of active uniform variables may include both built-in uniform variables (which begin with the prefix "gl_") as well as user-defined uniform variable names.

This function will return as much information as it can about the specified active uniform variable. If no information is available, length will be 0, and name will be an empty string. This situation could occur if this function is called after a link operation that failed. If an error occurs, the return values length, size, type, and name will be unmodified.

Notes

The double types, GL_DOUBLE, GL_DOUBLE_VEC2, GL_DOUBLE_VEC3, GL_DOUBLE_VEC4, GL_DOUBLE_MAT2, GL_DOUBLE_MAT3, GL_DOUBLE_MAT4, GL_DOUBLE_MAT2x3, GL_DOUBLE_MAT2x4, GL_DOUBLE_MAT3x2, GL_DOUBLE_MAT3x4, GL_DOUBLE_MAT4x2, and GL_DOUBLE_MAT4x3 are only available if the GL version is 4.1 or higher.

The image types, GL_IMAGE_1D, GL_IMAGE_2D, GL_IMAGE_3D, GL_IMAGE_2D_RECT, GL_IMAGE_CUBE, GL_IMAGE_BUFFER, GL_IMAGE_1D_ARRAY, GL_IMAGE_2D_ARRAY, GL_IMAGE_2D_MULTISAMPLE, GL_IMAGE_2D_MULTISAMPLE_ARRAY, GL_INT_IMAGE_1D, GL_INT_IMAGE_2D, GL_INT_IMAGE_3D, GL_INT_IMAGE_2D_RECT, GL_INT_IMAGE_CUBE, GL_INT_IMAGE_BUFFER, GL_INT_IMAGE_1D_ARRAY, GL_INT_IMAGE_2D_ARRAY, GL_INT_IMAGE_2D_MULTISAMPLE, GL_INT_IMAGE_2D_MULTISAMPLE_ARRAY, GL_UNSIGNED_INT_IMAGE_1D, GL_UNSIGNED_INT_IMAGE_2D, GL_UNSIGNED_INT_IMAGE_3D, GL_UNSIGNED_INT_IMAGE_2D_RECT, GL_UNSIGNED_INT_IMAGE_CUBE, GL_UNSIGNED_INT_IMAGE_BUFFER, GL_UNSIGNED_INT_IMAGE_1D_ARRAY, GL_UNSIGNED_INT_IMAGE_2D_ARRAY, GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE, GL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAY, and the atomic counter type, GL_UNSIGNED_INT_ATOMIC_COUNTER are only available if the GL version is 4.2 or higher.

Errors

GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.

GL_INVALID_OPERATION is generated if program is not a program object.

GL_INVALID_VALUE is generated if index is greater than or equal to the number of active uniform variables in program.

GL_INVALID_VALUE is generated if bufSize is less than 0.

Associated Gets

glGet() with argument GL_MAX_VERTEX_UNIFORM_COMPONENTS, GL_MAX_GEOMETRY_UNIFORM_COMPONENTS, GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS, GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS, GL_MAX_FRAGMENT_UNIFORM_COMPONENTS.

glGetProgram() with argument GL_ACTIVE_UNIFORMS or GL_ACTIVE_UNIFORM_MAX_LENGTH.

glIsProgram()

See Also

glGetUniform(), glGetUniformLocation(), glLinkProgram(), glUniform(), glUseProgram()

Info

02/04/2016 [FIXME: source] [FIXME: manual]