diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 43982312f0..fc304d8a96 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -2717,6 +2717,8 @@ reset() { _glGetInteger64v = (PFNGLGETINTEGER64VPROC) get_extension_func("glGetInteger64v"); + + _glGetInteger64v(GL_TIMESTAMP, &_timer_query_epoch); } #endif @@ -6889,6 +6891,7 @@ issue_timer_query(int pstats_index) { query = new CLP(LatencyQueryContext)(this, pstats_index); } else { query = new CLP(TimerQueryContext)(this, pstats_index); + query->_epoch = _timer_query_epoch; } if (_deleted_queries.size() >= 1) { diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.h b/panda/src/glstuff/glGraphicsStateGuardian_src.h index 6457cc920c..b56cbf1774 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.h +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.h @@ -1139,6 +1139,10 @@ public: BufferResidencyTracker _renderbuffer_residency; +#ifndef OPENGLES + GLint64 _timer_query_epoch = 0; +#endif + static PStatCollector _load_display_list_pcollector; static PStatCollector _primitive_batches_display_list_pcollector; static PStatCollector _vertices_display_list_pcollector; diff --git a/panda/src/glstuff/glLatencyQueryContext_src.cxx b/panda/src/glstuff/glLatencyQueryContext_src.cxx index a08ab74517..183f508c65 100644 --- a/panda/src/glstuff/glLatencyQueryContext_src.cxx +++ b/panda/src/glstuff/glLatencyQueryContext_src.cxx @@ -21,27 +21,9 @@ TypeHandle CLP(LatencyQueryContext)::_type_handle; CLP(LatencyQueryContext):: CLP(LatencyQueryContext)(CLP(GraphicsStateGuardian) *glgsg, int pstats_index) : - CLP(TimerQueryContext)(glgsg, pstats_index), - _timestamp(0) + CLP(TimerQueryContext)(glgsg, pstats_index) { - glgsg->_glGetInteger64v(GL_TIMESTAMP, &_timestamp); -} - -/** - * Returns the timestamp that is the result of this timer query. There's no - * guarantee about which clock this uses, the only guarantee is that - * subtracting a start time from an end time should yield a time in seconds. - * If is_answer_ready() did not return true, this function may block before it - * returns. - * - * It is only valid to call this from the draw thread. - */ -double CLP(LatencyQueryContext):: -get_timestamp() const { - GLint64 time_ns; - _glgsg->_glGetQueryObjecti64v(_index, GL_QUERY_RESULT, &time_ns); - - return (time_ns - _timestamp) * 0.000000001; + glgsg->_glGetInteger64v(GL_TIMESTAMP, &_epoch); } #endif // OPENGLES diff --git a/panda/src/glstuff/glLatencyQueryContext_src.h b/panda/src/glstuff/glLatencyQueryContext_src.h index 7c255cb5df..a3ee025641 100644 --- a/panda/src/glstuff/glLatencyQueryContext_src.h +++ b/panda/src/glstuff/glLatencyQueryContext_src.h @@ -26,10 +26,6 @@ public: ALLOC_DELETED_CHAIN(CLP(LatencyQueryContext)); - virtual double get_timestamp() const; - - GLint64 _timestamp; - public: static TypeHandle get_class_type() { return _type_handle; diff --git a/panda/src/glstuff/glTimerQueryContext_src.I b/panda/src/glstuff/glTimerQueryContext_src.I index c898c30261..2d89904b68 100644 --- a/panda/src/glstuff/glTimerQueryContext_src.I +++ b/panda/src/glstuff/glTimerQueryContext_src.I @@ -19,6 +19,7 @@ CLP(TimerQueryContext)(CLP(GraphicsStateGuardian) *glgsg, int pstats_index) : TimerQueryContext(pstats_index), _glgsg(glgsg), - _index(0) + _index(0), + _epoch(0) { } diff --git a/panda/src/glstuff/glTimerQueryContext_src.cxx b/panda/src/glstuff/glTimerQueryContext_src.cxx index a7b4ecb612..22712f7f50 100644 --- a/panda/src/glstuff/glTimerQueryContext_src.cxx +++ b/panda/src/glstuff/glTimerQueryContext_src.cxx @@ -90,7 +90,7 @@ get_timestamp() const { _glgsg->_glGetQueryObjectui64v(_index, GL_QUERY_RESULT, &time_ns); - return time_ns * 0.000000001; + return (time_ns - _epoch) * 0.000000001; } #endif // OPENGLES diff --git a/panda/src/glstuff/glTimerQueryContext_src.h b/panda/src/glstuff/glTimerQueryContext_src.h index 07709bc7af..8591b55cc0 100644 --- a/panda/src/glstuff/glTimerQueryContext_src.h +++ b/panda/src/glstuff/glTimerQueryContext_src.h @@ -39,6 +39,7 @@ public: GLuint _index; WPT(CLP(GraphicsStateGuardian)) _glgsg; + GLint64 _epoch; public: static TypeHandle get_class_type() {