Skip to content

Commit

Permalink
libgui|GL: GLWindow owns a GLTimer that the application can use
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent a88b91d commit 3ef56c1
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 40 deletions.
7 changes: 7 additions & 0 deletions doomsday/libs/gui/include/de/gui/glwindow.h
Expand Up @@ -40,6 +40,8 @@

namespace de {

class GLTimer;

/**
* Top-level window that contains an OpenGL drawing surface. @ingroup gui
*
Expand Down Expand Up @@ -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;

/**
Expand Down
98 changes: 58 additions & 40 deletions doomsday/libs/gui/src/glwindow.cpp
Expand Up @@ -20,6 +20,7 @@

#include "de/GLWindow"
#include "de/GuiApp"
#include "de/GLTimer"

#include <QElapsedTimer>
#include <QImage>
Expand All @@ -31,6 +32,7 @@
#include <de/GLBuffer>
#include <de/GLState>
#include <de/GLFramebuffer>
#include <de/Id>
#include <de/Log>
#include <de/c_wrapper.h>

Expand All @@ -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<TimeSpan> recordedGpuTimes;
#endif
//#if defined(DENG_HAVE_TIMER_QUERY)
// bool timerQueryPending = false;
// QOpenGLTimerQuery *timerQuery = nullptr;
// QElapsedTimer gpuTimeRecordingStartedAt;
// QVector<TimeSpan> recordedGpuTimes;
//#endif
std::unique_ptr<GLTimer> timer;
Id totalFrameTimeQueryId;

Impl(Public *i) : Base(i) {}

Expand All @@ -76,6 +80,7 @@ DENG2_PIMPL(GLWindow)
void glInit()
{
GLInfo::glInit();
timer.reset(new GLTimer);
self().setState(Ready);
}

Expand All @@ -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();
}

Expand Down Expand Up @@ -132,6 +138,7 @@ DENG2_PIMPL(GLWindow)
mainCall.enqueue([this] () { self().update(); });
}

#if 0
#if defined (DENG_HAVE_TIMER_QUERY)
bool timerQueryReady() const
{
Expand Down Expand Up @@ -171,6 +178,7 @@ DENG2_PIMPL(GLWindow)
}
}
#endif
#endif // 0

void updateFrameRateStatistics()
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -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()
Expand Down

0 comments on commit 3ef56c1

Please sign in to comment.