GLGETACTIVEUNIFORM(3G)
π GLGETACTIVEUNIFORM(3G) π
okay so bestie, welcome to glGetActiveUniform β it's giving "tell me everything about this one uniform variable in this one program object," and honestly? iconic. it's a section 3G manual page, so settle in.
β¨ NAME β¨
glGetActiveUniform β returns the deets about one (1) active uniform variable inside the program object you point at. that's it, that's the whole vibe π
πΈ C SPECIFICATION πΈ
void glGetActiveUniform(GLuint program, GLuint index, GLsizei bufSize,
GLsizei *length, GLint *size, GLenum *type,
GLchar *name);
like, copy it exactly, no cap β every type and pointer matters here π«Ά
π¦ PARAMETERS π¦
programβ the program object you're interrogating. this is who you're asking about πindexβ which uniform variable you want the tea on. it's the index, bestie, not the name πbufSizeβ the absolute max number of characters OpenGL is allowed to write into the character buffer you handed over inname. think of it as a hard limit, fr fr π§lengthβ if you pass something that isn'tNULL, this gets filled with the number of characters OpenGL actually wrote into the string atnameβ and that count does not include the null terminator π€sizeβ returns the size of the uniform variable. like, how big it is π«typeβ returns the data type of the uniform variable πnameβ returns a null terminated string holding the name of the uniform variable. the actual name, in text, for you π
π DESCRIPTION π
so glGetActiveUniform returns info about an active uniform variable in the program object specified by program. periodt.
wanna know how many active uniform variables there even are? call glGetProgram() with the value GL_ACTIVE_UNIFORMS β that's the count, bestie π’. and a value of 0 for index selects the very first active uniform variable, like the main character of the list π. permissible values for index range from zero all the way up to the number of active uniform variables minus one. so zero-indexed, as everything in your life should be.
now, the shader lore β¨: shaders may use either built-in uniform variables, user-defined uniform variables, or both. slay, versatile.
- built-in uniform variables have a prefix of
"gl_"and they reference existing OpenGL state or values derived from such state β e.g.gl_DepthRangeParameters. (see the OpenGL Shading Language specification for a complete list, because this page is not about to list them all π) - user-defined uniform variables have arbitrary names and they obtain their values from the application through calls to
glUniform(). that's you, you're the application, you're doing that π
a uniform variable β built-in or user-defined, doesn't matter β is considered active if it's determined during the link operation that it may be accessed during program execution. so basically the linker did a vibe check and went "yeah, this one might get used" β
. and because of that, program should have previously been the target of a call to glLinkProgram() β but plot twist: it is not necessary for it to have been linked successfully π
now, buffer sizing, because this is the part that bites people π. the size of the character buffer you need 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. that size β of this character buffer β is what you pass in bufSize, and a pointer to this character buffer is what you pass in name. match made in heaven π«Ά
then 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, as strings should be π. the actual number of characters written into this buffer comes back in length, and β say it with me β this count does not include the null termination character. and if you don't care about the length of the returned string at all? just pass a value of NULL in the length argument and move on with your life π
ngl bestie,bufSizeis a real one β OpenGL will not write past what you tell it, so give it room. the longest-name size fromGL_ACTIVE_UNIFORM_MAX_LENGTHis literally right there for you π
So like, type is gonna write a pointer to the uniform variable's data type into wherever you pointed it π
β and bestie, the symbolic constants it hands back for each uniform type? Literally a whole glow-up list, here's the full rundown, no skips:
GL_FLOATβfloatGL_FLOAT_VEC2βvec2GL_FLOAT_VEC3βvec3GL_FLOAT_VEC4βvec4GL_DOUBLEβdoubleGL_DOUBLE_VEC2βdvec2GL_DOUBLE_VEC3βdvec3GL_DOUBLE_VEC4βdvec4GL_INTβintGL_INT_VEC2βivec2GL_INT_VEC3βivec3GL_INT_VEC4βivec4GL_UNSIGNED_INTβunsigned intGL_UNSIGNED_INT_VEC2βuvec2GL_UNSIGNED_INT_VEC3βuvec3GL_UNSIGNED_INT_VEC4βuvec4GL_BOOLβboolGL_BOOL_VEC2βbvec2GL_BOOL_VEC3βbvec3GL_BOOL_VEC4βbvec4GL_FLOAT_MAT2βmat2GL_FLOAT_MAT3βmat3GL_FLOAT_MAT4βmat4GL_FLOAT_MAT2x3βmat2x3GL_FLOAT_MAT2x4βmat2x4GL_FLOAT_MAT3x2βmat3x2GL_FLOAT_MAT3x4βmat3x4GL_FLOAT_MAT4x2βmat4x2GL_FLOAT_MAT4x3βmat4x3GL_DOUBLE_MAT2βdmat2GL_DOUBLE_MAT3βdmat3GL_DOUBLE_MAT4βdmat4GL_DOUBLE_MAT2x3βdmat2x3GL_DOUBLE_MAT2x4βdmat2x4GL_DOUBLE_MAT3x2βdmat3x2GL_DOUBLE_MAT3x4βdmat3x4GL_DOUBLE_MAT4x2βdmat4x2
okay so we're still deep in the type table, bestie β like, the table, the one that maps what GL tells you (params) to what it actually means in shader-speak. Picking up right where we left off, no skipping, every single row, let's go πββοΈπ¨
GL_DOUBLE_MAT4x3βdmat4x3GL_SAMPLER_1Dβsampler1DGL_SAMPLER_2Dβsampler2DGL_SAMPLER_3Dβsampler3DGL_SAMPLER_CUBEβsamplerCubeGL_SAMPLER_1D_SHADOWβsampler1DShadowGL_SAMPLER_2D_SHADOWβsampler2DShadowGL_SAMPLER_1D_ARRAYβsampler1DArrayGL_SAMPLER_2D_ARRAYβsampler2DArrayGL_SAMPLER_1D_ARRAY_SHADOWβsampler1DArrayShadowGL_SAMPLER_2D_ARRAY_SHADOWβsampler2DArrayShadowGL_SAMPLER_2D_MULTISAMPLEβsampler2DMSGL_SAMPLER_2D_MULTISAMPLE_ARRAYβsampler2DMSArrayGL_SAMPLER_CUBE_SHADOWβsamplerCubeShadowGL_SAMPLER_BUFFERβsamplerBufferGL_SAMPLER_2D_RECTβsampler2DRectGL_SAMPLER_2D_RECT_SHADOWβsampler2DRectShadowGL_INT_SAMPLER_1Dβisampler1DGL_INT_SAMPLER_2Dβisampler2DGL_INT_SAMPLER_3Dβisampler3DGL_INT_SAMPLER_CUBEβisamplerCubeGL_INT_SAMPLER_1D_ARRAYβisampler1DArrayGL_INT_SAMPLER_2D_ARRAYβisampler2DArrayGL_INT_SAMPLER_2D_MULTISAMPLEβisampler2DMSGL_INT_SAMPLER_2D_MULTISAMPLE_ARRAYβisampler2DMSArrayGL_INT_SAMPLER_BUFFERβisamplerBufferGL_INT_SAMPLER_2D_RECTβisampler2DRectGL_UNSIGNED_INT_SAMPLER_1Dβusampler1DGL_UNSIGNED_INT_SAMPLER_2Dβusampler2DGL_UNSIGNED_INT_SAMPLER_3Dβusampler3DGL_UNSIGNED_INT_SAMPLER_CUBEβusamplerCubeGL_UNSIGNED_INT_SAMPLER_1D_ARRAYβusampler2DArrayGL_UNSIGNED_INT_SAMPLER_2D_ARRAYβusampler2DArrayGL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLEβusampler2DMSGL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAYβusampler2DMSArrayGL_UNSIGNED_INT_SAMPLER_BUFFERβusamplerBufferGL_UNSIGNED_INT_SAMPLER_2D_RECTβusampler2DRectGL_IMAGE_1Dβimage1DGL_IMAGE_2Dβimage2D
π«Ά real talk: yes, usampler2DArray shows up twice up there, and no, that's not me being sloppy β that's literally how it's written in the spec, so I'm keeping it character-for-character. Copy it exactly as-is and move on, bestie. no cap π
and we're still going, the image squad is just getting started β hold that thought β¨
GL_IMAGE_3Dβimage3DGL_IMAGE_2D_RECTβimage2DRectGL_IMAGE_CUBEβimageCubeGL_IMAGE_BUFFERβimageBufferGL_IMAGE_1D_ARRAYβimage1DArrayGL_IMAGE_2D_ARRAYβimage2DArrayGL_IMAGE_2D_MULTISAMPLEβimage2DMSGL_IMAGE_2D_MULTISAMPLE_ARRAYβimage2DMSArrayGL_INT_IMAGE_1Dβiimage1DGL_INT_IMAGE_2Dβiimage2DGL_INT_IMAGE_3Dβiimage3DGL_INT_IMAGE_2D_RECTβiimage2DRectGL_INT_IMAGE_CUBEβiimageCubeGL_INT_IMAGE_BUFFERβiimageBufferGL_INT_IMAGE_1D_ARRAYβiimage1DArrayGL_INT_IMAGE_2D_ARRAYβiimage2DArrayGL_INT_IMAGE_2D_MULTISAMPLEβiimage2DMSGL_INT_IMAGE_2D_MULTISAMPLE_ARRAYβiimage2DMSArrayGL_UNSIGNED_INT_IMAGE_1Dβuimage1DGL_UNSIGNED_INT_IMAGE_2Dβuimage2DGL_UNSIGNED_INT_IMAGE_3Dβuimage3DGL_UNSIGNED_INT_IMAGE_2D_RECTβuimage2DRectGL_UNSIGNED_INT_IMAGE_CUBEβuimageCubeGL_UNSIGNED_INT_IMAGE_BUFFERβuimageBufferGL_UNSIGNED_INT_IMAGE_1D_ARRAYβuimage1DArrayGL_UNSIGNED_INT_IMAGE_2D_ARRAYβuimage2DArrayGL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLEβuimage2DMSGL_UNSIGNED_INT_IMAGE_2D_MULTISAMPLE_ARRAYβuimage2DMSArrayGL_UNSIGNED_INT_ATOMIC_COUNTERβatomic_uint
okay bestie, arrays time πΈ and this is the part where people get confused, so like, breathe.
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. Not the count of active elements β the highest index used, plus one. That distinction is doing a lot of work, ngl π
And only one active uniform variable will be reported for a uniform array. One array = one report. Periodt.
π Lowkey important: size is not "how many elements are active". It's the top index + 1. Don't get it twisted.
Now, the structures thing, and honestly this is the icon of "wait what" π
Uniform variables that are declared as structures or arrays of structures will not be returned directly by this function. Nope. 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. So like, the compiler is out here decomposing your struct into a bunch of dotted names, and every one of those gets its own lil index π«Ά
And check this caveat, it's giving rules: a valid name cannot be a structure, an array of structures, or a subcomponent of a vector or matrix. So don't come asking for mystruct and expect a happy answer β ask for the leaf nodes, bestie π
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
sizereturned will be as described for uniform arrays; otherwise, thesizereturned will be1.
so: non-array = 1. Reduction that lands on an array = array rules. Reduction that doesn't = 1. easy π§
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. So yeah, the gl_ squad is in the list too β don't be surprised, iykyk π
This function will return as much information as it can about the specified active uniform variable π
But if no information is available, length will be 0, and name will be an empty string. When could that happen? This situation could occur if this function is called after a link operation that failed π yep. Failed link β shrug.
π And the big one, keep this in your notes: if an error occurs, the return valueslength,size,type, andnamewill be unmodified. Not zeroed, not cleared β untouched. So check those errors, bestie, fr fr.
β¨ NOTES β¨
okay so before you go indexing anything, there's a whole vibe check about which types even exist on your driver π
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. not before. don't even try π
And the image types, bestie, are a whole list: 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 β plus the atomic counter type GL_UNSIGNED_INT_ATOMIC_COUNTER β are only available if the GL version is 4.2 or higher. yes, all of them. every single one. i counted π«Ά
π ERRORS π
so here's where it can go wrong. and it will, if you're not paying attention π
GL_INVALID_VALUEβ gets generated if program is not a value generated by OpenGL. like, where did you even get that number babeGL_INVALID_OPERATIONβ gets generated if program is not a program object. close but no cigarGL_INVALID_VALUEβ gets generated if index is greater than or equal to the number of active uniform variables in program. you asked for uniform #9000 and there are like three of themGL_INVALID_VALUEβ gets generated if bufSize is less than0. negative buffer size. genuinely what are you doing π
fr fr, check your values before you call this, it's giving "debugging at 3am" energy otherwise
π¦ ASSOCIATED GETS π¦
the little functions that hang out with this one, iykyk:
glGet()with argumentGL_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 argumentGL_ACTIVE_UNIFORMSorGL_ACTIVE_UNIFORM_MAX_LENGTH.glIsProgram()
those last two are literally your besties for this function, no cap π
π VERSION SUPPORT π
bestie the original had a whole table with cute little boxes and checkmarks, so let me just tell you the tea:
glGetActiveUniform is supported everywhere. like, every single version:
2.0β β2.1β β3.0β β3.1β β3.2β β3.3β β4.0β β4.1β β4.2β β4.3β β4.4β β4.5β β
twelve for twelve. ate and left no crumbs π
π₯ SEE ALSO π₯
go read these next, they're all connected:
glGetUniform()glGetUniformLocation()glLinkProgram()glUniform()glUseProgram()
π COPYRIGHT π
Copyright Β© 2003-2005 3Dlabs Inc. Ltd. Copyright Β© 2010-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 (yes, again) π
Copyright Β© 2003-2005 3Dlabs Inc. Ltd. Copyright Β© 2010-2014 Khronos Group
and that's the whole page, bestie π«Ά it's from [FIXME: source], dated 08/09/2021, and it lives at GLGETACTIVEUNIFORM(3G) β go forth and query those uniforms, you absolute icon π
β¨
π¦ where this page comes from
- centos-stream 9: gl-manpages 1.1-24.20190306.el9 Β· MIT and Open Publication
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms