Sync & queriesGL 1.5
glGetQueryObjectuiv
Reads a query's state or result as a 32-bit number; mostly used to ask whether the result is ready yet.
Part of the family glGet*, glGetQueryObject*
Signature
void glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint *params);
How it works
With GL_QUERY_RESULT_AVAILABLE it answers immediately: 1 if the result is ready, 0 if not. With GL_QUERY_RESULT it returns the result, but if the GPU has not got there yet it waits, and that wait is a full CPU–GPU stall. So check availability first, or only read queries that are a few frames old.
Parameters
idGLuint
The query.
pnameGLenum
What to read.
Common values
- GL_QUERY_RESULT_AVAILABLE
- 1 if the result is ready (never waits).
- GL_QUERY_RESULT
- The result (waits if it is not ready).
- GL_QUERY_RESULT_NO_WAIT
- The result if ready, otherwise params is left unchanged (GL 4.4).
paramsGLuint *
Where the value is written.
Tips & pitfalls
A time in nanoseconds overflows 32 bits after about 4.3 seconds; read timer results with
glGetQueryObjectui64v.
Example
example.cpp
1GLuint ready = 0;
2glGetQueryObjectuiv(oldest, GL_QUERY_RESULT_AVAILABLE, &ready);
3if (ready) { /* read it with glGetQueryObjectui64v */ }