summaryrefslogtreecommitdiffstats
path: root/src/opengl/qgl.cpp
diff options
context:
space:
mode:
authorTrond Kjernåsen <trond@trolltech.com>2009-09-08 12:32:30 (GMT)
committerTrond Kjernåsen <trond@trolltech.com>2009-09-08 12:36:18 (GMT)
commit512a265f760c9207b94d7ba61cef9316b23cf4e8 (patch)
tree292049ef55db8f80fc785e79ac8d2390b812518e /src/opengl/qgl.cpp
parentb8e6f86ed8b27504f22da2167cb6aa9ecf829a71 (diff)
downloadQt-512a265f760c9207b94d7ba61cef9316b23cf4e8.zip
Qt-512a265f760c9207b94d7ba61cef9316b23cf4e8.tar.gz
Qt-512a265f760c9207b94d7ba61cef9316b23cf4e8.tar.bz2
Added a public function to enforce usage og the old GL engine.
Some applications that uses a mix of OpenGL and QPainter code may not work correctly with the new GL 2 engine (e.g. the composition demo). The same is most likely also true for user apps, therefore we need a way to enforce the usage of the old GL 1 engine for the sake of compatibility. Task-number: 260872 Reviewed-by: Samuel
Diffstat (limited to 'src/opengl/qgl.cpp')
-rw-r--r--src/opengl/qgl.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp
index 087902b..02bb8f9 100644
--- a/src/opengl/qgl.cpp
+++ b/src/opengl/qgl.cpp
@@ -141,6 +141,48 @@ QGLSignalProxy *QGLSignalProxy::instance()
return theSignalProxy();
}
+
+class QGLEngineSelector
+{
+public:
+ QGLEngineSelector() : engineType(QPaintEngine::MaxUser) { }
+
+ void setPreferredPaintEngine(QPaintEngine::Type type) {
+ if (type == QPaintEngine::OpenGL || type == QPaintEngine::OpenGL2)
+ engineType = type;
+ }
+
+ QPaintEngine::Type preferredPaintEngine() {
+ if (engineType == QPaintEngine::MaxUser) {
+ // No user-set engine - use the defaults
+#if defined(QT_OPENGL_ES_2)
+ engineType = QPaintEngine::OpenGL2;
+#else
+ // We can't do this in the constructor for this object because it
+ // needs to be called *before* the QApplication constructor
+ if ((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_2_0)
+ && qgetenv("QT_GL_USE_OPENGL1ENGINE").isEmpty())
+ engineType = QPaintEngine::OpenGL2;
+ else
+ engineType = QPaintEngine::OpenGL;
+#endif
+ }
+ return engineType;
+ }
+
+private:
+ QPaintEngine::Type engineType;
+};
+
+Q_GLOBAL_STATIC(QGLEngineSelector, qgl_engine_selector)
+
+
+bool qt_gl_preferGL2Engine()
+{
+ return qgl_engine_selector()->preferredPaintEngine() == QPaintEngine::OpenGL2;
+}
+
+
/*!
\namespace QGL
\inmodule QtOpenGL
@@ -181,6 +223,32 @@ QGLSignalProxy *QGLSignalProxy::instance()
\sa {Sample Buffers Example}
*/
+/*!
+ \fn void QGL::setPreferredPaintEngine(QPaintEngine::Type engineType)
+
+ \since 4.6
+
+ Sets the preferred OpenGL paint engine that is used to draw onto
+ QGLWidgets, QGLPixelBuffers and QGLFrameBufferObjects with QPainter
+ in Qt.
+
+ The \a engineType parameter specifies which of the GL engines to
+ use. Only \c QPaintEngine::OpenGL and \c QPaintEngine::OpenGL2 are
+ valid parameters to this function. All other values are ignored.
+
+ By default, the \c QPaintEngine::OpenGL2 engine is used if GL/GLES
+ version 2.0 is available, otherwise \c QPaintEngine::OpenGL is
+ used.
+
+ \warning This function must be called before the QApplication
+ constructor is called.
+*/
+void QGL::setPreferredPaintEngine(QPaintEngine::Type engineType)
+{
+ qgl_engine_selector()->setPreferredPaintEngine(engineType);
+}
+
+
/*****************************************************************************
QGLFormat implementation
*****************************************************************************/