Sync & queriesGL 3.3

glQueryCounter

Records the GPU clock at the moment the GPU reaches this point in the command stream.

Signature

void glQueryCounter(GLuint id, GLenum target);

How it works

A timestamp instead of an interval. Put one before and one after a section and subtract the two results: the GPU time of that section in nanoseconds. Unlike GL_TIME_ELAPSED, timestamps can be nested and overlapped freely, so a profiler can mark every pass of the frame (shadows, G-buffer, lighting, post) with one counter each.

Parameters

idGLuint

The query that receives the time.

targetGLenum

Always GL_TIMESTAMP.

Errors

When the call is invalid it does nothing and sets an error, which glGetError returns:

GL_INVALID_ENUM
target is not GL_TIMESTAMP.

Example

example.cpp
1glQueryCounter(t[0], GL_TIMESTAMP);
2drawShadows();
3glQueryCounter(t[1], GL_TIMESTAMP);
4// frames later: shadowsNs = time(t[1]) - time(t[0])
Official Khronos documentation