GLGETACTIVEUNIFORMSI(3G)

πŸ’… glGetActiveUniformsiv(3G) πŸ’…

okay so bestie, welcome to glGetActiveUniformsiv β€” yes that's a mouthful, no I will not be pronouncing it out loud β€” and it lives in the [FIXME: manual] manual, section 3G. iconic. let's get into it 🫢


✨ NAME ✨

glGetActiveUniformsiv β€” returns information about several active uniform variables for the specified program object. that's the whole vibe. it's giving "i have questions and i need answers about my uniforms" πŸ’…


🌸 C SPECIFICATION 🌸

like, literally this is the function signature, copy it exactly, do not touch it, she is perfect:

void glGetActiveUniformsiv(GLuint program, GLsizei uniformCount,
                           const GLuint *uniformIndices, GLenum pname,
                           GLint *params);

πŸŽ€ PARAMETERS πŸŽ€

okay so now we meet the cast of characters. five of them. all important. no skips πŸ’–

  • program β€” specifies the program object to be queried. like, which program are we snooping on. that's the one πŸ•΅οΈβ€β™€οΈ
  • uniformCount β€” specifies both the number of elements in the array of indices uniformIndices and the number of parameters written to params upon successful return. so she's doing double duty, highkey a multi-hyphenate πŸ’… one number, two jobs, we love a main character ✨
  • uniformIndices β€” specifies the address of an array of uniformCount integers containing the indices of uniforms within program whose parameter pname should be queried. so it's the lil guest list of which uniforms we're asking about πŸ“‹
  • pname β€” specifies the property of each uniform in uniformIndices that should be written into the corresponding element of params. like, what do you wanna know about them. the property in question πŸ‘‘πŸ¦‹
  • params β€” specifies the address of an array of uniformCount integers which are to receive the value of pname for each uniform in uniformIndices. this is the answer sheet, the receipts, where the tea gets written down πŸ“

🌈 DESCRIPTION 🌈

so here's the whole situation, bestie:

glGetActiveUniformsiv queries the value of the parameter named pname for each of the uniforms within program whose indices are specified in the array of uniformCount unsigned integers uniformIndices.

upon success, the value of the parameter for each uniform is written into the corresponding entry in the array whose address is given in params. one in, one out. matching entries. slay ✨

🚨 and listen β€” if an error is generated, nothing is written into params. like, nothing. zero. not a single entry. so don't go reading your params array all hopeful after an error, because she is untouched πŸ˜­πŸ’€

Okay so when pname is GL_UNIFORM_TYPE, you get back an array telling you the type of each uniform β€” one entry per element of your uniformIndices array, in the same order. It's giving very "match the answer sheet to the question sheet" energy ✨

And these are literally all the possible values it can hand back, paired with the shader type they mean:

  • GL_FLOAT β€” float
  • GL_FLOAT_VEC2 β€” vec2
  • GL_FLOAT_VEC3 β€” vec3
  • GL_FLOAT_VEC4 β€” vec4
  • GL_DOUBLE β€” double
  • GL_DOUBLE_VEC2 β€” dvec2
  • GL_DOUBLE_VEC3 β€” dvec3
  • GL_DOUBLE_VEC4 β€” dvec4
  • GL_INT β€” int
  • GL_INT_VEC2 β€” ivec2
  • GL_INT_VEC3 β€” ivec3
  • GL_INT_VEC4 β€” ivec4
  • GL_UNSIGNED_INT β€” unsigned int
  • GL_UNSIGNED_INT_VEC2 β€” uvec2
  • GL_UNSIGNED_INT_VEC3 β€” uvec3
  • GL_UNSIGNED_INT_VEC4 β€” uvec4
  • GL_BOOL β€” bool
  • GL_BOOL_VEC2 β€” bvec2
  • GL_BOOL_VEC3 β€” bvec3
  • GL_BOOL_VEC4 β€” bvec4
  • GL_FLOAT_MAT2 β€” mat2
  • GL_FLOAT_MAT3 β€” mat3
  • GL_FLOAT_MAT4 β€” mat4
  • GL_FLOAT_MAT2x3 β€” mat2x3
  • GL_FLOAT_MAT2x4 β€” mat2x4
  • GL_FLOAT_MAT3x2 β€” mat3x2
  • GL_FLOAT_MAT3x4 β€” mat3x4
  • GL_FLOAT_MAT4x2 β€” mat4x2
  • GL_FLOAT_MAT4x3 β€” mat4x3
  • GL_DOUBLE_MAT2 β€” dmat2
  • GL_DOUBLE_MAT3 β€” dmat3
  • GL_DOUBLE_MAT4 β€” dmat4
  • GL_DOUBLE_MAT2x3 β€” dmat2x3
  • GL_DOUBLE_MAT2x4 β€” dmat2x4
  • GL_DOUBLE_MAT3x2 β€” dmat3x2
  • GL_DOUBLE_MAT3x4 β€” dmat3x4
  • GL_DOUBLE_MAT4x2 β€” dmat4x2

...still going through the type match-ups, bestie, we're in the back half now, no stopping πŸ‘‘ (each one's the GL_* enum on the left and the exact GLSL type name string it hands back on the right β€” character for character, no cap):

  • GL_DOUBLE_MAT4x3 β†’ dmat4x3
  • GL_SAMPLER_1D β†’ sampler1D
  • GL_SAMPLER_2D β†’ sampler2D
  • GL_SAMPLER_3D β†’ sampler3D
  • GL_SAMPLER_CUBE β†’ samplerCube
  • GL_SAMPLER_1D_SHADOW β†’ sampler1DShadow
  • GL_SAMPLER_2D_SHADOW β†’ sampler2DShadow
  • GL_SAMPLER_1D_ARRAY β†’ sampler1DArray
  • GL_SAMPLER_2D_ARRAY β†’ sampler2DArray
  • GL_SAMPLER_1D_ARRAY_SHADOW β†’ sampler1DArrayShadow
  • GL_SAMPLER_2D_ARRAY_SHADOW β†’ sampler2DArrayShadow
  • GL_SAMPLER_2D_MULTISAMPLE β†’ sampler2DMS
  • GL_SAMPLER_2D_MULTISAMPLE_ARRAY β†’ sampler2DMSArray
  • GL_SAMPLER_CUBE_SHADOW β†’ samplerCubeShadow
  • GL_SAMPLER_BUFFER β†’ samplerBuffer
  • GL_SAMPLER_2D_RECT β†’ sampler2DRect
  • GL_SAMPLER_2D_RECT_SHADOW β†’ sampler2DRectShadow
  • GL_INT_SAMPLER_1D β†’ isampler1D
  • GL_INT_SAMPLER_2D β†’ isampler2D
  • GL_INT_SAMPLER_3D β†’ isampler3D
  • GL_INT_SAMPLER_CUBE β†’ isamplerCube
  • GL_INT_SAMPLER_1D_ARRAY β†’ isampler1DArray
  • GL_INT_SAMPLER_2D_ARRAY β†’ isampler2DArray
  • GL_INT_SAMPLER_2D_MULTISAMPLE β†’ isampler2DMS
  • GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY β†’ isampler2DMSArray
  • GL_INT_SAMPLER_BUFFER β†’ isamplerBuffer
  • GL_INT_SAMPLER_2D_RECT β†’ isampler2DRect
  • GL_UNSIGNED_INT_SAMPLER_1D β†’ usampler1D
  • GL_UNSIGNED_INT_SAMPLER_2D β†’ usampler2D
  • GL_UNSIGNED_INT_SAMPLER_3D β†’ usampler3D
  • GL_UNSIGNED_INT_SAMPLER_CUBE β†’ usamplerCube
  • GL_UNSIGNED_INT_SAMPLER_1D_ARRAY β†’ usampler2DArray
  • GL_UNSIGNED_INT_SAMPLER_2D_ARRAY β†’ usampler2DArray
  • GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE β†’ usampler2DMS
  • GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY β†’ usampler2DMSArray
  • GL_UNSIGNED_INT_SAMPLER_BUFFER β†’ usamplerBuffer
  • GL_UNSIGNED_INT_SAMPLER_2D_RECT β†’ usampler2DRect
🫢 real talk, bestie: those last two usampler lines β€” GL_UNSIGNED_INT_SAMPLER_1D_ARRAY β†’ usampler2DArray and GL_UNSIGNED_INT_SAMPLER_2D_ARRAY β†’ usampler2DArray β€” that's literally what the page says, so I'm passing it straight to you exactly like that. Copy it verbatim, don't go "fixing" it on me. πŸ’…

okay so now β€” GL_UNIFORM_SIZE πŸŽ€

If pname is GL_UNIFORM_SIZE, then what comes back is an array identifying the size of the uniforms specified by the corresponding array of uniformIndices. That array is returned, periodt.

And the sizes it returns? They're in units of the type returned by a query of GL_UNIFORM_TYPE β€” so like, whatever type GL_UNIFORM_TYPE just told you that uniform was, that's the unit of measurement for its size ✨.

For active uniforms that are arrays, the size is the number of active elements in the array πŸ¦‹. For all other uniforms β€” everything that isn't one of those array situations β€” the size is one. One. That's it. That's the number. πŸ™‚β€β†•οΈ

So like, here's the tea on each pname value you can pass, bestie πŸ’– β€” this is the part where it actually tells you what comes back:

  • If pname is GL_UNIFORM_NAME_LENGTH, then you get back an array that tells you the length β€” including the terminating null character β€” of the uniform name strings specified by the corresponding array of uniformIndices. ✨
  • If pname is GL_UNIFORM_BLOCK_INDEX, then you get an array identifying the uniform block index of each of the uniforms specified by the corresponding array of uniformIndices. And heads up: the uniform block index of a uniform that's chillin' in the default uniform block is -1. 🫢
  • If pname is GL_UNIFORM_OFFSET, then you get an array of uniform buffer offsets. For uniforms in a named uniform block, the returned value is its offset, in basic machine units, relative to the beginning of the uniform block in the buffer object data store. For atomic counter uniforms, the returned value is its offset relative to the beginning of its active atomic counter buffer. For all other uniforms, -1 is returned. πŸ’€
  • If pname is GL_UNIFORM_ARRAY_STRIDE, then you get an array identifying the stride between elements of each of the uniforms specified by the corresponding array of uniformIndices. For uniforms in named uniform blocks and for uniforms declared as atomic counters, the stride is the difference, in basic machine units, of consecutive elements in an array β€” or zero for uniforms not declared as an array. For all other uniforms, a stride of -1 is returned. πŸ‘‘
  • If pname is GL_UNIFORM_MATRIX_STRIDE, then you get an array identifying the stride between columns of a column-major matrix or rows of a row-major matrix, in basic machine units, of each of the uniforms specified by the corresponding array of uniformIndices. The matrix stride of a uniform associated with the default uniform block is -1. Note that this info only makes sense for uniforms that are matrices β€” for uniforms that aren't matrices but are declared in a named uniform block, a matrix stride of zero is returned. no cap 🧚
  • If pname is GL_UNIFORM_IS_ROW_MAJOR, then you get an array identifying whether each of the uniforms specified by the corresponding array of uniformIndices is a row-major matrix or not. A value of one means row-major matrix, and a value of zero means column-major matrix, a matrix in the default uniform block, or a non-matrix. literally the vibe check for matrices 🌈
  • If pname is GL_UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX, then you get an array identifying the active atomic counter buffer index of each of the uniforms specified by the corresponding array of uniformIndices. For uniforms other than atomic counters, the returned buffer index is -1. These returned indices may be passed to glGetActiveAtomicCounterBufferiv() to query the properties of the associated buffer β€” and not necessarily the binding point specified in the uniform declaration. iykyk 😭

🌸 NOTES 🌸

Ok so 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. gatekept fr πŸ’…

And GL_UNIFORM_ATOMIC_COUNTER_BUFFER_INDEX is only accepted by pname 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 uniformCount is greater than or equal to the value of GL_ACTIVE_UNIFORMS for program.
  • GL_INVALID_ENUM is generated if pname is not an accepted token.
bestie if you're seeing these, something's not slaying. double-check your program and your pname before you spiral πŸ™ˆ

πŸ¦‹ ASSOCIATED GETS πŸ¦‹

  • glGet() with argument GL_MAX_VERTEX_UNIFORM_COMPONENTS, GL_MAX_TESS_CONTROL_UNIFORM_COMPONENTS, GL_MAX_TESS_EVALUATION_UNIFORM_COMPONENTS, GL_MAX_GEOMETRY_UNIFORM_COMPONENTS, GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, or GL_MAX_COMBINED_UNIFORM_COMPONENTS.
  • glGetProgram() with argument GL_ACTIVE_UNIFORMS or GL_ACTIVE_UNIFORM_MAX_LENGTH.
  • glIsProgram()

πŸ‘‘ VERSION SUPPORT πŸ‘‘

Ok the original had a whole table situation, but here's the same tea in list form, because we're cute like that πŸ’–

glGetActiveUniformsiv across the OpenGL versions:

  • 2.0 β€” not supported
  • 2.1 β€” not supported
  • 3.0 β€” not supported
  • 3.1 β€” supported βœ”
  • 3.2 β€” supported βœ”
  • 3.3 β€” supported βœ”
  • 4.0 β€” supported βœ”
  • 4.1 β€” supported βœ”
  • 4.2 β€” supported βœ”
  • 4.3 β€” supported βœ”
  • 4.4 β€” supported βœ”
  • 4.5 β€” supported βœ”

so it's giving 3.1 and up only, periodt 🌸


πŸŽ€ SEE ALSO πŸŽ€

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


Copyright Β© 2011-2014 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. http://opencontent.org/openpub/.

Copyright Β© 2011-2014 Khronos Group


ok that's the whole page, you made it to the end bestie, iconic behavior ✨🫢 This lil beauty comes from [FIXME: source], dated 08/09/2021, and it lives under the name GLGETACTIVEUNIFORMSI(3G) β€” go forth and query those uniforms, mwah πŸ’…πŸ’–

πŸ“¦ where this page comes from