From 3ef56c199a5ad80af4ecb21426b3945361602f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Kera=CC=88nen?= Date: Sat, 17 Mar 2018 21:50:40 +0200 Subject: [PATCH] libgui|GL: GLWindow owns a GLTimer that the application can use --- doomsday/libs/gui/include/de/gui/glwindow.h | 7 ++ doomsday/libs/gui/src/glwindow.cpp | 98 ++++++++++++--------- 2 files changed, 65 insertions(+), 40 deletions(-) diff --git a/doomsday/libs/gui/include/de/gui/glwindow.h b/doomsday/libs/gui/include/de/gui/glwindow.h index c8e86ee4e4..df9b9e533a 100644 --- a/doomsday/libs/gui/include/de/gui/glwindow.h +++ b/doomsday/libs/gui/include/de/gui/glwindow.h @@ -40,6 +40,8 @@ namespace de { +class GLTimer; + /** * Top-level window that contains an OpenGL drawing surface. @ingroup gui * @@ -114,6 +116,11 @@ class LIBGUI_PUBLIC GLWindow : public QOpenGLWindow, public Asset */ GLFramebuffer &framebuffer() const; + /** + * Provides access to the GL profiling timers. + */ + GLTimer &timer() const; + WindowEventHandler &eventHandler() const; /** diff --git a/doomsday/libs/gui/src/glwindow.cpp b/doomsday/libs/gui/src/glwindow.cpp index ab1f415756..7e9445f057 100644 --- a/doomsday/libs/gui/src/glwindow.cpp +++ b/doomsday/libs/gui/src/glwindow.cpp @@ -20,6 +20,7 @@ #include "de/GLWindow" #include "de/GuiApp" +#include "de/GLTimer" #include #include @@ -31,6 +32,7 @@ #include #include #include +#include #include #include @@ -51,12 +53,14 @@ DENG2_PIMPL(GLWindow) uint frameCount = 0; float fps = 0; -#if defined(DENG_HAVE_TIMER_QUERY) - bool timerQueryPending = false; - QOpenGLTimerQuery *timerQuery = nullptr; - QElapsedTimer gpuTimeRecordingStartedAt; - QVector recordedGpuTimes; -#endif +//#if defined(DENG_HAVE_TIMER_QUERY) +// bool timerQueryPending = false; +// QOpenGLTimerQuery *timerQuery = nullptr; +// QElapsedTimer gpuTimeRecordingStartedAt; +// QVector recordedGpuTimes; +//#endif + std::unique_ptr timer; + Id totalFrameTimeQueryId; Impl(Public *i) : Base(i) {} @@ -76,6 +80,7 @@ DENG2_PIMPL(GLWindow) void glInit() { GLInfo::glInit(); + timer.reset(new GLTimer); self().setState(Ready); } @@ -84,15 +89,16 @@ DENG2_PIMPL(GLWindow) self().setState(NotReady); readyNotified = false; readyPending = false; -#if defined (DENG_HAVE_TIMER_QUERY) - if (timerQuery) - { - if (timerQueryPending) timerQuery->waitForResult(); - delete timerQuery; - timerQuery = nullptr; - timerQueryPending = false; - } -#endif +//#if defined (DENG_HAVE_TIMER_QUERY) +// if (timerQuery) +// { +// if (timerQueryPending) timerQuery->waitForResult(); +// delete timerQuery; +// timerQuery = nullptr; +// timerQueryPending = false; +// } +//#endif + timer.reset(); GLInfo::glDeinit(); } @@ -132,6 +138,7 @@ DENG2_PIMPL(GLWindow) mainCall.enqueue([this] () { self().update(); }); } +#if 0 #if defined (DENG_HAVE_TIMER_QUERY) bool timerQueryReady() const { @@ -171,6 +178,7 @@ DENG2_PIMPL(GLWindow) } } #endif +#endif // 0 void updateFrameRateStatistics() { @@ -311,6 +319,11 @@ GLFramebuffer &GLWindow::framebuffer() const return d->backing; } +GLTimer &GLWindow::timer() const +{ + return *d->timer; +} + float GLWindow::frameRate() const { return d->fps; @@ -504,26 +517,29 @@ void GLWindow::paintGL() DENG2_ASSERT(QOpenGLContext::currentContext() != nullptr); - //if (GLInfo::extensions().EXT_timer_query) -#if defined (DENG_HAVE_TIMER_QUERY) - { - d->checkTimerQueryResult(); + //qDebug() << "Frame time:" << d->timer->elapsedTime(d->totalFrameTimeQueryId); - if (!d->timerQuery) - { - d->timerQuery = new QOpenGLTimerQuery(); - if (!d->timerQuery->create()) - { - LOG_GL_ERROR("Failed to create timer query object"); - } - } +//#if defined (DENG_HAVE_TIMER_QUERY) +// { +// d->checkTimerQueryResult(); - if (d->timerQueryReady()) - { - d->timerQuery->begin(); - } - } -#endif +// if (!d->timerQuery) +// { +// d->timerQuery = new QOpenGLTimerQuery(); +// if (!d->timerQuery->create()) +// { +// LOG_GL_ERROR("Failed to create timer query object"); +// } +// } + +// if (d->timerQueryReady()) +// { +// d->timerQuery->begin(); +// } +// } +//#endif + + //d->timer->beginTimer(d->totalFrameTimeQueryId); GLBuffer::resetDrawCount(); @@ -536,13 +552,15 @@ void GLWindow::paintGL() LIBGUI_ASSERT_GL_OK(); -#if defined (DENG_HAVE_TIMER_QUERY) - if (d->timerQueryReady()) - { - d->timerQuery->end(); - d->timerQueryPending = true; - } -#endif + //d->timer->endTimer(d->totalFrameTimeQueryId); + +//#if defined (DENG_HAVE_TIMER_QUERY) +// if (d->timerQueryReady()) +// { +// d->timerQuery->end(); +// d->timerQueryPending = true; +// } +//#endif } void GLWindow::windowAboutToClose()