Context & stateGL 1.0
glGetIntegerv
Reads an integer piece of state or a hardware limit.
Part of the family glGet*
Signature
void glGetIntegerv(GLenum pname, GLint *data);
How it works
The generic query for integer values. Use it to ask the driver about limits (how many texture units, the maximum texture size) or about current state (which framebuffer is bound, the current viewport).
Some values have several components — GL_VIEWPORT writes 4 integers — so data must have room for all of them.
Parameters
pnameGLenum
The value to query.
Common values
- GL_MAX_TEXTURE_IMAGE_UNITS
- Texture units available to the fragment shader (≥ 16).
- GL_MAX_TEXTURE_SIZE
- Largest width/height of a 2D texture.
- GL_MAX_VERTEX_ATTRIBS
- Number of vertex attribute locations (≥ 16).
- GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT
- Required alignment for glBindBufferRange offsets.
- GL_VIEWPORT
- Current viewport as 4 ints.
- GL_MAJOR_VERSION / GL_MINOR_VERSION
- Context version as numbers.
- GL_MAX_COMPUTE_WORK_GROUP_COUNT
- Use glGetIntegeri_v with index 0–2.
dataGLint *
Where the result is written.
Tips & pitfalls
Queries that read state can force the CPU to wait for the driver. Fine at startup, avoid in hot loops.
Errors
When the call is invalid it does nothing and sets an error, which glGetError returns:
- GL_INVALID_ENUM
- pname is not accepted.
Example
example.cpp
1GLint units = 0;
2glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &units);
3
4GLint viewport[4];
5glGetIntegerv(GL_VIEWPORT, viewport);