Fixed OpenGL viewport being updated at each frame

That could cause ratio flickering on paint() on some devices
This commit is contained in:
Michaël Lemaire 2015-08-24 19:38:59 +02:00
parent 9b2c60fe16
commit 1077e4dca3
2 changed files with 16 additions and 1 deletions

View file

@ -18,6 +18,8 @@ OpenGLView::OpenGLView(QQuickItem *parent) :
mouse_button = Qt::NoButton;
connect(this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*)));
connect(this, SIGNAL(widthChanged()), this, SLOT(handleResize()));
connect(this, SIGNAL(heightChanged()), this, SLOT(handleResize()));
startTimer(50);
}
@ -45,9 +47,15 @@ void OpenGLView::paint()
{
renderer->initialize();
initialized = true;
resized = true;
}
if (resized)
{
renderer->resize(width(), height());
resized = false;
}
renderer->resize(width(), height());
renderer->prepareOpenGLState();
renderer->paint();
@ -57,6 +65,11 @@ void OpenGLView::paint()
}
}
void OpenGLView::handleResize()
{
resized = true;
}
void OpenGLView::wheelEvent(QWheelEvent *event)
{
if (not acceptInputs())

View file

@ -17,6 +17,7 @@ public:
public slots:
void handleWindowChanged(QQuickWindow *win);
void paint();
void handleResize();
protected:
virtual void wheelEvent(QWheelEvent *event) override;
@ -31,6 +32,7 @@ private:
private:
bool initialized;
bool resized;
MainModelerWindow *window;
OpenGLRenderer *renderer;