Both of them can be used to get time elapsed in nanoseconds. The former uses scoped glBeginQuery/glEndQuery. Is that the difference?
what is the difference between querying time elapsed in OpenGL with GL_TIME_ELAPSED and GL_TIMESTAMP
2 Answers
Is that the difference?
You say that as though it were some minor difference.
GL_TIME_ELAPSED
delivers the GPU time it took to process the commands in the query's scope (ie: glBegin/EndQuery
). GL_TIMESTAMP
is not a count of anything. It merely gets the GPU time, in nanoseconds, since... well, something. The start time is implementation defined, but it is always increasing (unless it overflows).
To put it another way, GL_TIME_ELAPSED
is like a stopwatch: the time between when you start and stop. It's a delta. GL_TIMESTAMP
is like looking at a clock: it's always increasing. It's an absolute time, but it's relative to something implementation dependent.

- 449,505
- 63
- 781
- 982
They are functionally identical, except for the difference between using glBeginQuery()
/glEndQuery()
and glQueryCounter()
, as you pointed out.
See: the examples portion of the ARB_timer_query specification.

- 5,653
- 17
- 32
-
2Well, it depends on how you define "functionally identical". Using glBeginQuery()/glEndQuery() has the disadvantage that queries of the same type cannot be nested, while one can easily just take timestamps at arbitrary points. Another thing worth mentioning in this context is issue 11 in the extension spec you linked: "Can the GL implementation use different clocks to implement the TIME_ELAPSED and TIMESTAMP queries?" THe short answer is: "yes". – derhass Jun 27 '14 at 18:51
-
Can you elaborate on how you come to that conclusion? glBeginQuery/glEndQuery has the *potential* to be a bit smarter by not counting time spent when context switching to another application, but I don't know how drivers actually handle that. I don't really see the point of glBeginQuery(GL_TIMESTAMP) otherwise. – rdb Sep 07 '14 at 21:37