summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/opengl/doc/src/hellogl.qdoc22
-rw-r--r--examples/opengl/hellogl/glwidget.cpp6
2 files changed, 21 insertions, 7 deletions
diff --git a/examples/opengl/doc/src/hellogl.qdoc b/examples/opengl/doc/src/hellogl.qdoc
index b4aef0ae02..9740c91408 100644
--- a/examples/opengl/doc/src/hellogl.qdoc
+++ b/examples/opengl/doc/src/hellogl.qdoc
@@ -109,10 +109,24 @@
\snippet hellogl/glwidget.cpp 5
- In the above slot, the \c xRot variable is updated only if the new angle
- is different to the old one, the \c xRotationChanged() signal is emitted to
- allow other components to be updated, and the widget's
- \l{QGLWidget::updateGL()}{updateGL()} handler function is called.
+ In the above slot, the \c xRot variable is updated only if the new angle is
+ different to the old one, the \c xRotationChanged() signal is emitted to
+ allow other components to be updated, and an update is scheduled.
+
+ Note that the widget's \l{QGLWidget::updateGL()}{updateGL()} function is not
+ called directly from here. Triggering rendering and buffer swaps directly
+ from the input event handlers is not desirable. Such events may, depending
+ on the platform, occur at a high frequency, and calling a potentially
+ blocking function like \l{QOpenGLContext::swapBuffers()}{swapBuffers} may
+ lead to unexpected results due to the main thread not being able to process
+ the input events at a proper rate.
+
+ Instead, update() is used. This will eventually lead to a paint event, which
+ will in turn invoke paintGL(). Multiple calls to update() in a row will make
+ no difference while the event is still pending. This way the UI will perform
+ equally well with blocking swaps, that is, a a
+ \l{QGLFormat::swapInterval()}{swap interval} of 1, and non-vsynced
+ configurations.
The \c setYRotation() and \c setZRotation() slots perform the same task for
rotations measured by the \c yRot and \c zRot variables.
diff --git a/examples/opengl/hellogl/glwidget.cpp b/examples/opengl/hellogl/glwidget.cpp
index 29879fa804..3a9faaca5f 100644
--- a/examples/opengl/hellogl/glwidget.cpp
+++ b/examples/opengl/hellogl/glwidget.cpp
@@ -100,7 +100,7 @@ void GLWidget::setXRotation(int angle)
if (angle != xRot) {
xRot = angle;
emit xRotationChanged(angle);
- updateGL();
+ update();
}
}
//! [5]
@@ -111,7 +111,7 @@ void GLWidget::setYRotation(int angle)
if (angle != yRot) {
yRot = angle;
emit yRotationChanged(angle);
- updateGL();
+ update();
}
}
@@ -121,7 +121,7 @@ void GLWidget::setZRotation(int angle)
if (angle != zRot) {
zRot = angle;
emit zRotationChanged(angle);
- updateGL();
+ update();
}
}