Support for an idle render time step.

The basics of this is, if the application has changed its active state
then we only call paintGL every N milliseconds.  Currently the default
time step is 100 milliseconds.
This commit is contained in:
Geenz 2014-03-12 19:10:26 -04:00
parent e249b29b45
commit 9c61f12926
2 changed files with 35 additions and 2 deletions

View file

@ -12,17 +12,21 @@
#include <QMimeData>
#include <QUrl>
GLCanvas::GLCanvas() : QGLWidget(QGLFormat(QGL::NoDepthBuffer, QGL::NoStencilBuffer)) {
GLCanvas::GLCanvas() : QGLWidget(QGLFormat(QGL::NoDepthBuffer, QGL::NoStencilBuffer)), _throttleRendering(false), _idleRenderInterval(100) {
}
void GLCanvas::initializeGL() {
Application::getInstance()->initializeGL();
setAttribute(Qt::WA_AcceptTouchEvents);
setAcceptDrops(true);
connect(Application::getInstance(), &Application::focusChanged, this, &GLCanvas::activeChanged);
connect(&_frameTimer, &QTimer::timeout, this, &GLCanvas::throttleRender);
}
void GLCanvas::paintGL() {
Application::getInstance()->paintGL();
if (!_throttleRendering) {
Application::getInstance()->paintGL();
}
}
void GLCanvas::resizeGL(int width, int height) {
@ -49,6 +53,27 @@ void GLCanvas::mouseReleaseEvent(QMouseEvent* event) {
Application::getInstance()->mouseReleaseEvent(event);
}
void GLCanvas::activeChanged()
{
if (!isActiveWindow())
{
if (!_throttleRendering)
{
_frameTimer.start(_idleRenderInterval);
_throttleRendering = true;
}
} else {
_frameTimer.stop();
_throttleRendering = false;
}
}
void GLCanvas::throttleRender()
{
_frameTimer.start(_idleRenderInterval);
Application::getInstance()->paintGL();
}
int updateTime = 0;
bool GLCanvas::event(QEvent* event) {
switch (event->type()) {

View file

@ -10,6 +10,7 @@
#define __hifi__GLCanvas__
#include <QGLWidget>
#include <QTimer>
/// customized canvas that simply forwards requests/events to the singleton application
class GLCanvas : public QGLWidget {
@ -17,6 +18,10 @@ public:
GLCanvas();
protected:
QTimer _frameTimer;
bool _throttleRendering;
int _idleRenderInterval;
virtual void initializeGL();
virtual void paintGL();
virtual void resizeGL(int width, int height);
@ -34,6 +39,9 @@ protected:
virtual void dragEnterEvent(QDragEnterEvent *event);
virtual void dropEvent(QDropEvent* event);
void activeChanged();
void throttleRender();
};
#endif /* defined(__hifi__GLCanvas__) */