From 512a265f760c9207b94d7ba61cef9316b23cf4e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trond=20Kjern=C3=A5sen?= Date: Tue, 8 Sep 2009 14:32:30 +0200 Subject: 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 --- demos/composition/main.cpp | 6 ++++ dist/changes-4.6.0 | 11 ++++++-- src/opengl/qgl.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++ src/opengl/qgl.h | 3 ++ src/opengl/qgl_p.h | 10 +------ 5 files changed, 87 insertions(+), 11 deletions(-) diff --git a/demos/composition/main.cpp b/demos/composition/main.cpp index 3a959a9..fe142ad 100644 --- a/demos/composition/main.cpp +++ b/demos/composition/main.cpp @@ -42,11 +42,17 @@ #include "composition.h" #include +#ifdef QT_OPENGL_SUPPORT +#include +#endif int main(int argc, char **argv) { // Q_INIT_RESOURCE(deform); +#ifdef QT_OPENGL_SUPPORT + QGL::setPreferredPaintEngine(QPaintEngine::OpenGL); +#endif QApplication app(argc, argv); CompositionWidget compWidget(0); diff --git a/dist/changes-4.6.0 b/dist/changes-4.6.0 index ca984ac..f9984d3 100644 --- a/dist/changes-4.6.0 +++ b/dist/changes-4.6.0 @@ -54,8 +54,15 @@ information about a particular change. this is that Nokia focuses on OpenGL for desktop hardware accelerated rendering. - - When mixing OpenGL and QPainter calls you need to surround your custom - OpenGL calls with QPainter::beginNativePainting() and + - The default engine used to draw onto OpenGL buffers has changed in + Qt 4.6. The QPaintEngine::OpenGL2 engine is now used as the default + engine. This *may* cause compatibility problems for applications + that use a mix of QPainter and native OpenGL calls to draw into a GL + buffer. Use the QGL::setPreferredPaintEngine() function to enforce + usage of the old GL paint engine. + + - When mixing OpenGL and QPainter calls you need to surround your + custom OpenGL calls with QPainter::beginNativePainting() and QPainter::endNativePainting(). This is to ensure that the paint engine flushes any pending drawing and sets up the GL modelview/projection matrices properly before you can issue custom 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 *****************************************************************************/ diff --git a/src/opengl/qgl.h b/src/opengl/qgl.h index daac760..b110665 100644 --- a/src/opengl/qgl.h +++ b/src/opengl/qgl.h @@ -43,6 +43,7 @@ #define QGL_H #include +#include #include #include #include @@ -130,6 +131,8 @@ class QGLContextPrivate; // Namespace class: namespace QGL { + Q_OPENGL_EXPORT void setPreferredPaintEngine(QPaintEngine::Type engineType); + enum FormatOption { DoubleBuffer = 0x0001, DepthBuffer = 0x0002, diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h index d4b7597..f8158a0 100644 --- a/src/opengl/qgl_p.h +++ b/src/opengl/qgl_p.h @@ -519,15 +519,7 @@ extern QPaintEngine* qt_qgl_paint_engine(); extern EGLDisplay qt_qgl_egl_display(); #endif -inline bool qt_gl_preferGL2Engine() -{ -#if defined(QT_OPENGL_ES_2) - return true; -#else - return (QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_2_0) - && qgetenv("QT_GL_USE_OPENGL1ENGINE").isEmpty(); -#endif -} +bool qt_gl_preferGL2Engine(); inline GLenum qt_gl_preferredTextureFormat() { -- cgit v0.12