summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@digia.com>2012-11-22 09:12:54 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-11-22 14:01:55 +0100
commitf813031835748fb1b121c81eab1195847e4ab30a (patch)
tree85afe81e8ba7a69e2f91d42e13023638e8aa5b06 /src
parentab0a007cb369a8e9a1bf43c9386a77d36199759b (diff)
Made renderText() work in samplebuffers example.
Since the OpenGL paint engine is now OpenGL 2.0 based, we need to save and restore all GL state to prevent it from being clobbered. Task-number: QTBUG-27020 Change-Id: I39831e074aa818583df34c4a88b13be559d0231b Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Mitch Curtis <mitch.curtis@digia.com> Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/opengl/qgl.cpp40
1 files changed, 17 insertions, 23 deletions
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp
index 817b7c329b..e440d5b9fc 100644
--- a/src/opengl/qgl.cpp
+++ b/src/opengl/qgl.cpp
@@ -4379,10 +4379,7 @@ static void qt_gl_draw_text(QPainter *p, int x, int y, const QString &str,
\note This function can only be used inside a
QPainter::beginNativePainting()/QPainter::endNativePainting() block
- if the default OpenGL paint engine is QPaintEngine::OpenGL. To make
- QPaintEngine::OpenGL the default GL engine, call
- QGL::setPreferredPaintEngine(QPaintEngine::OpenGL) before the
- QApplication constructor.
+ if a painter is active on the QGLWidget.
\l{Overpainting Example}{Overpaint} with QPainter::drawText() instead.
*/
@@ -4403,18 +4400,14 @@ void QGLWidget::renderText(int x, int y, const QString &str, const QFont &font,
bool auto_swap = autoBufferSwap();
QPaintEngine *engine = paintEngine();
- if (engine && engine->isActive()) {
- qWarning("QGLWidget::renderText(): Calling renderText() while a GL 2 paint engine is"
- " active on the same device is not allowed.");
- return;
- }
+
+ qt_save_gl_state();
QPainter *p;
bool reuse_painter = false;
if (engine->isActive()) {
reuse_painter = true;
p = engine->painter();
- qt_save_gl_state();
glDisable(GL_DEPTH_TEST);
glViewport(0, 0, width, height);
@@ -4444,14 +4437,15 @@ void QGLWidget::renderText(int x, int y, const QString &str, const QFont &font,
qt_gl_draw_text(p, x, y, str, font);
- if (reuse_painter) {
- qt_restore_gl_state();
- } else {
+ if (!reuse_painter) {
p->end();
delete p;
setAutoBufferSwap(auto_swap);
d->disable_clear_on_painter_begin = false;
}
+
+ qt_restore_gl_state();
+
#else // QT_OPENGL_ES
Q_UNUSED(x);
Q_UNUSED(y);
@@ -4476,6 +4470,10 @@ void QGLWidget::renderText(int x, int y, const QString &str, const QFont &font,
before calling this function to annotate the models without
depth-testing the text.
+ \note This function can only be used inside a
+ QPainter::beginNativePainting()/QPainter::endNativePainting() block
+ if a painter is active on the QGLWidget.
+
\l{Overpainting Example}{Overpaint} with QPainter::drawText() instead.
*/
void QGLWidget::renderText(double x, double y, double z, const QString &str, const QFont &font, int)
@@ -4501,21 +4499,16 @@ void QGLWidget::renderText(double x, double y, double z, const QString &str, con
QPaintEngine *engine = paintEngine();
- if (engine && engine->isActive()) {
- qWarning("QGLWidget::renderText(): Calling renderText() while a GL 2 paint engine is"
- " active on the same device is not allowed.");
- return;
- }
-
QPainter *p;
bool reuse_painter = false;
bool use_depth_testing = glIsEnabled(GL_DEPTH_TEST);
bool use_scissor_testing = glIsEnabled(GL_SCISSOR_TEST);
+ qt_save_gl_state();
+
if (engine->isActive()) {
reuse_painter = true;
p = engine->painter();
- qt_save_gl_state();
} else {
setAutoBufferSwap(false);
// disable glClear() as a result of QPainter::begin()
@@ -4543,14 +4536,15 @@ void QGLWidget::renderText(double x, double y, double z, const QString &str, con
glTranslated(0, 0, -win_z);
qt_gl_draw_text(p, qRound(win_x), qRound(win_y), str, font);
- if (reuse_painter) {
- qt_restore_gl_state();
- } else {
+ if (!reuse_painter) {
p->end();
delete p;
setAutoBufferSwap(auto_swap);
d->disable_clear_on_painter_begin = false;
}
+
+ qt_restore_gl_state();
+
#else // QT_OPENGL_ES
Q_UNUSED(x);
Q_UNUSED(y);