mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 12:14:00 +02:00
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:
parent
e249b29b45
commit
9c61f12926
2 changed files with 35 additions and 2 deletions
|
@ -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()) {
|
||||
|
|
|
@ -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__) */
|
||||
|
|
Loading…
Reference in a new issue