summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dist/changes-4.6.05
-rw-r--r--src/gui/painting/qpaintengine.cpp4
-rw-r--r--src/gui/painting/qpaintengineex_p.h2
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp37
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h1
-rw-r--r--src/opengl/qgl_p.h2
6 files changed, 50 insertions, 1 deletions
diff --git a/dist/changes-4.6.0 b/dist/changes-4.6.0
index 6a94f26..bedf58a 100644
--- a/dist/changes-4.6.0
+++ b/dist/changes-4.6.0
@@ -49,3 +49,8 @@ information about a particular change.
- QStyleOptionGraphicsItem::levelOfDetails is obsoleted and its value
is always initialized to 1. For a more fine-grained value use
QStyleOptionGraphicsItem::levelOfDetailFromTransform(const QTransform &).
+
+ - When mixing OpenGL and QPainter calls you need to first call syncState()
+ on the paint engine, for example "painter->paintEngine()->syncState()".
+ This is to ensure that the engine flushes any pending drawing and sets up
+ the GL modelview/projection matrices properly.
diff --git a/src/gui/painting/qpaintengine.cpp b/src/gui/painting/qpaintengine.cpp
index 7de1ec4..9859425 100644
--- a/src/gui/painting/qpaintengine.cpp
+++ b/src/gui/painting/qpaintengine.cpp
@@ -49,6 +49,7 @@
#include <private/qtextengine_p.h>
#include <qvarlengtharray.h>
#include <private/qfontengine_p.h>
+#include <private/qpaintengineex_p.h>
QT_BEGIN_NAMESPACE
@@ -302,6 +303,9 @@ void QPaintEngine::syncState()
{
Q_ASSERT(state);
updateState(*state);
+
+ if (isExtended())
+ static_cast<QPaintEngineEx *>(this)->sync();
}
static QPaintEngine *qt_polygon_recursion = 0;
diff --git a/src/gui/painting/qpaintengineex_p.h b/src/gui/painting/qpaintengineex_p.h
index 593726c..1c55242 100644
--- a/src/gui/painting/qpaintengineex_p.h
+++ b/src/gui/painting/qpaintengineex_p.h
@@ -216,6 +216,8 @@ public:
inline QPainterState *state() { return static_cast<QPainterState *>(QPaintEngine::state); }
inline const QPainterState *state() const { return static_cast<const QPainterState *>(QPaintEngine::state); }
+ virtual void sync() {}
+
virtual QPixmapFilter *createPixmapFilter(int /*type*/) const { return 0; }
protected:
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
index e7b6ee4..40f3a8d 100644
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
@@ -449,6 +449,43 @@ void QGL2PaintEngineExPrivate::drawTexture(const QGLRect& dest, const QGLRect& s
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
+void QGL2PaintEngineEx::sync()
+{
+ Q_D(QGL2PaintEngineEx);
+ ensureActive();
+ d->transferMode(BrushDrawingMode);
+
+ QGLContext *ctx = d->ctx;
+ glUseProgram(0);
+
+#ifndef QT_OPENGL_ES_2
+ // be nice to people who mix OpenGL 1.x code with QPainter commands
+ // by setting modelview and projection matrices to mirror the GL 1
+ // paint engine
+ const QTransform& mtx = state()->matrix;
+
+ float mv_matrix[4][4] =
+ {
+ { mtx.m11(), mtx.m12(), 0, mtx.m13() },
+ { mtx.m21(), mtx.m22(), 0, mtx.m23() },
+ { 0, 0, 1, 0 },
+ { mtx.dx(), mtx.dy(), 0, mtx.m33() }
+ };
+
+ const QSize sz = d->drawable.size();
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(0, sz.width(), sz.height(), 0, -999999, 999999);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadMatrixf(&mv_matrix[0][0]);
+#endif
+
+ glDisable(GL_BLEND);
+ glActiveTexture(GL_TEXTURE0);
+}
+
void QGL2PaintEngineExPrivate::transferMode(EngineMode newMode)
{
if (newMode == mode)
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h
index dececa3..7213474 100644
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2_p.h
@@ -126,6 +126,7 @@ public:
return static_cast<const QOpenGL2PaintEngineState *>(QPaintEngineEx::state());
}
void updateClipRegion(const QRegion &clipRegion, Qt::ClipOperation op);
+ virtual void sync();
private:
Q_DISABLE_COPY(QGL2PaintEngineEx)
diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h
index b1a63b5..b3523d4 100644
--- a/src/opengl/qgl_p.h
+++ b/src/opengl/qgl_p.h
@@ -440,7 +440,7 @@ inline bool qt_gl_preferGL2Engine()
return true;
#else
return (QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_2_0)
- && !qgetenv("QT_GL_USE_OPENGL2ENGINE").isEmpty();
+ && qgetenv("QT_GL_USE_OPENGL1ENGINE").isEmpty();
#endif
}