Function familiesfamily
glGet*
Read state, limits or results back from OpenGL; the suffix says the type of what comes back.
Signature
void glGet{Integerv|Floatv|Booleanv|Doublev}(GLenum pname, T *data); void glGet{Shader|Program|QueryObject…}{iv|uiv|fv}(GLuint object, GLenum pname, T *params);
How it works
The getters come in two kinds: global queries (glGetIntegerv(GL_MAX_TEXTURE_SIZE, &n)) and queries about one object (glGetShaderiv(shader, GL_COMPILE_STATUS, &ok)). Strings and errors have their own: glGetString, glGetError.
They are cheap for limits read once at start-up, but can be slow in a frame. Some force the CPU to wait for the GPU (glGetBufferSubData, glGetQueryObject on a fresh query), and even simple ones make the driver synchronise its state. For anything you set yourself, keep your own copy instead of asking.
Reading the name
- iv
- Integer values through a pointer ("integer vector").
- uiv / ui64v
- Unsigned 32-bit / 64-bit (timer results need 64).
- fv / Booleanv / Doublev
- Float, boolean or double values.
- InfoLog
- A text log (compile and link errors) copied into your char buffer.
Functions in this family
glGetIntegervReads an integer piece of state or a hardware limit.glGetStringReturns text describing the driver: version, GPU name, vendor, GLSL version.glGetErrorReturns (and clears) the oldest error flag recorded by previous calls.glGetShaderivQueries a property of a shader — mainly whether it compiled.glGetShaderInfoLogReads the compiler's error and warning messages for a shader.glGetProgramivQueries a property of a program — mainly whether it linked.glGetProgramInfoLogReads the linker's error and warning messages for a program.glGetUniformLocationLooks up the location (slot number) of a uniform variable by its GLSL name.glGetAttribLocationAsks a linked program which location the linker gave a vertex input; -1 if it does not exist.glGetUniformBlockIndexFinds the index of a named uniform block inside a program.glGetBufferSubDataCopies bytes from a GPU buffer back into CPU memory.glGetQueryObjectuivReads a query's state or result as a 32-bit number; mostly used to ask whether the result is ready yet.glGetQueryObjectui64vReads a query result as a 64-bit number: the form to use for GPU times in nanoseconds.
Example
example.cpp
1GLint maxTex = 0;
2glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTex);
3
4GLint ok = 0;
5glGetShaderiv(shader, GL_COMPILE_STATUS, &ok);