From 925fc21fcfdb48093032921e76c9274512699a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Mon, 26 Jul 2010 08:18:18 +0200 Subject: Added QGLFormat to QPlatformWindowFormat conversion --- src/gui/kernel/qplatformwindowformat_qpa.cpp | 68 +++++++++++++-------------- src/opengl/qgl_qpa.cpp | 70 ++++++++++++++++++++++++++-- 2 files changed, 100 insertions(+), 38 deletions(-) diff --git a/src/gui/kernel/qplatformwindowformat_qpa.cpp b/src/gui/kernel/qplatformwindowformat_qpa.cpp index 9d86948..1112ba9 100644 --- a/src/gui/kernel/qplatformwindowformat_qpa.cpp +++ b/src/gui/kernel/qplatformwindowformat_qpa.cpp @@ -98,8 +98,8 @@ public: }; /*! - \class QGLFormat - \brief The QGLFormat class specifies the display format of an OpenGL + \class QPlatformWindowFormat + \brief The QPlatformWindowFormat class specifies the display format of an OpenGL rendering context. \ingroup painting-3D @@ -133,7 +133,7 @@ public: different platforms, and some format options may have higher precedence than others. - You create and tell a QGLFormat object what rendering options you + You create and tell a QPlatformWindowFormat object what rendering options you want from an OpenGL rendering context. OpenGL drivers or accelerated hardware may or may not support @@ -143,7 +143,7 @@ public: context with the nearest subset of features. There are different ways to define the display characteristics of - a rendering context. One is to create a QGLFormat and make it the + a rendering context. One is to create a QPlatformWindowFormat and make it the default for the entire application: \snippet doc/src/snippets/code/src_opengl_qgl.cpp 0 @@ -164,7 +164,7 @@ public: */ /*! - Constructs a QGLFormat object with the following default settings: + Constructs a QPlatformWindowFormat object with the following default settings: \list \i \link setDoubleBuffer() Double buffer:\endlink Enabled. \i \link setDepth() Depth buffer:\endlink Enabled. @@ -187,7 +187,7 @@ QPlatformWindowFormat::QPlatformWindowFormat() /*! - Creates a QGLFormat object that is a copy of the current + Creates a QPlatformWindowFormat object that is a copy of the current defaultFormat(). If \a options is not 0, the default format is modified by the @@ -257,7 +257,7 @@ QPlatformWindowFormat &QPlatformWindowFormat::operator=(const QPlatformWindowFor } /*! - Destroys the QGLFormat. + Destroys the QPlatformWindowFormat. */ QPlatformWindowFormat::~QPlatformWindowFormat() { @@ -266,7 +266,7 @@ QPlatformWindowFormat::~QPlatformWindowFormat() } /*! - \fn bool QGLFormat::doubleBuffer() const + \fn bool QPlatformWindowFormat::doubleBuffer() const Returns true if double buffering is enabled; otherwise returns false. Double buffering is enabled by default. @@ -297,7 +297,7 @@ void QPlatformWindowFormat::setDoubleBuffer(bool enable) /*! - \fn bool QGLFormat::depth() const + \fn bool QPlatformWindowFormat::depth() const Returns true if the depth buffer is enabled; otherwise returns false. The depth buffer is enabled by default. @@ -327,7 +327,7 @@ void QPlatformWindowFormat::setDepth(bool enable) /*! - \fn bool QGLFormat::rgba() const + \fn bool QPlatformWindowFormat::rgba() const Returns true if RGBA color mode is set. Returns false if color index mode is set. The default color mode is RGBA. @@ -358,7 +358,7 @@ void QPlatformWindowFormat::setRgba(bool enable) /*! - \fn bool QGLFormat::alpha() const + \fn bool QPlatformWindowFormat::alpha() const Returns true if the alpha buffer in the framebuffer is enabled; otherwise returns false. The alpha buffer is disabled by default. @@ -386,7 +386,7 @@ void QPlatformWindowFormat::setAlpha(bool enable) /*! - \fn bool QGLFormat::accum() const + \fn bool QPlatformWindowFormat::accum() const Returns true if the accumulation buffer is enabled; otherwise returns false. The accumulation buffer is disabled by default. @@ -413,7 +413,7 @@ void QPlatformWindowFormat::setAccum(bool enable) /*! - \fn bool QGLFormat::stencil() const + \fn bool QPlatformWindowFormat::stencil() const Returns true if the stencil buffer is enabled; otherwise returns false. The stencil buffer is enabled by default. @@ -440,7 +440,7 @@ void QPlatformWindowFormat::setStencil(bool enable) /*! - \fn bool QGLFormat::stereo() const + \fn bool QPlatformWindowFormat::stereo() const Returns true if stereo buffering is enabled; otherwise returns false. Stereo buffering is disabled by default. @@ -467,7 +467,7 @@ void QPlatformWindowFormat::setStereo(bool enable) /*! - \fn bool QGLFormat::directRendering() const + \fn bool QPlatformWindowFormat::directRendering() const Returns true if direct rendering is enabled; otherwise returns false. @@ -496,7 +496,7 @@ void QPlatformWindowFormat::setDirectRendering(bool enable) } /*! - \fn bool QGLFormat::sampleBuffers() const + \fn bool QPlatformWindowFormat::sampleBuffers() const Returns true if multisample buffer support is enabled; otherwise returns false. @@ -550,7 +550,7 @@ void QPlatformWindowFormat::setSamples(int numSamples) { detach(); if (numSamples < 0) { - qWarning("QGLFormat::setSamples: Cannot have negative number of samples per pixel %d", numSamples); + qWarning("QPlatformWindowFormat::setSamples: Cannot have negative number of samples per pixel %d", numSamples); return; } d->numSamples = numSamples; @@ -615,7 +615,7 @@ QPlatformGLContext *QPlatformWindowFormat::sharedGLContext() const } ///*! -// \fn bool QGLFormat::hasOverlay() const +// \fn bool QPlatformWindowFormat::hasOverlay() const // Returns true if overlay plane is enabled; otherwise returns false. @@ -680,7 +680,7 @@ void QPlatformWindowFormat::setDepthBufferSize(int size) { detach(); if (size < 0) { - qWarning("QGLFormat::setDepthBufferSize: Cannot set negative depth buffer size %d", size); + qWarning("QPlatformWindowFormat::setDepthBufferSize: Cannot set negative depth buffer size %d", size); return; } d->depthSize = size; @@ -708,7 +708,7 @@ void QPlatformWindowFormat::setRedBufferSize(int size) { detach(); if (size < 0) { - qWarning("QGLFormat::setRedBufferSize: Cannot set negative red buffer size %d", size); + qWarning("QPlatformWindowFormat::setRedBufferSize: Cannot set negative red buffer size %d", size); return; } d->redSize = size; @@ -737,7 +737,7 @@ void QPlatformWindowFormat::setGreenBufferSize(int size) { detach(); if (size < 0) { - qWarning("QGLFormat::setGreenBufferSize: Cannot set negative green buffer size %d", size); + qWarning("QPlatformWindowFormat::setGreenBufferSize: Cannot set negative green buffer size %d", size); return; } d->greenSize = size; @@ -766,7 +766,7 @@ void QPlatformWindowFormat::setBlueBufferSize(int size) { detach(); if (size < 0) { - qWarning("QGLFormat::setBlueBufferSize: Cannot set negative blue buffer size %d", size); + qWarning("QPlatformWindowFormat::setBlueBufferSize: Cannot set negative blue buffer size %d", size); return; } d->blueSize = size; @@ -794,7 +794,7 @@ void QPlatformWindowFormat::setAlphaBufferSize(int size) { detach(); if (size < 0) { - qWarning("QGLFormat::setAlphaBufferSize: Cannot set negative alpha buffer size %d", size); + qWarning("QPlatformWindowFormat::setAlphaBufferSize: Cannot set negative alpha buffer size %d", size); return; } d->alphaSize = size; @@ -821,7 +821,7 @@ void QPlatformWindowFormat::setAccumBufferSize(int size) { detach(); if (size < 0) { - qWarning("QGLFormat::setAccumBufferSize: Cannot set negative accumulate buffer size %d", size); + qWarning("QPlatformWindowFormat::setAccumBufferSize: Cannot set negative accumulate buffer size %d", size); return; } d->accumSize = size; @@ -847,7 +847,7 @@ void QPlatformWindowFormat::setStencilBufferSize(int size) { detach(); if (size < 0) { - qWarning("QGLFormat::setStencilBufferSize: Cannot set negative stencil buffer size %d", size); + qWarning("QPlatformWindowFormat::setStencilBufferSize: Cannot set negative stencil buffer size %d", size); return; } d->stencilSize = size; @@ -865,13 +865,13 @@ int QPlatformWindowFormat::stencilBufferSize() const } /*! - Returns the default QGLFormat for the application. All QGLWidget + Returns the default QPlatformWindowFormat for the application. All QGLWidget objects that are created use this format unless another format is specified, e.g. when they are constructed. If no special default format has been set using setDefaultFormat(), the default format is the same as that created - with QGLFormat(). + with QPlatformWindowFormat(). \sa setDefaultFormat() */ @@ -882,7 +882,7 @@ QPlatformWindowFormat QPlatformWindowFormat::defaultFormat() } /*! - Sets a new default QGLFormat for the application to \a f. For + Sets a new default QPlatformWindowFormat for the application to \a f. For example, to set single buffering as the default instead of double buffering, your main() might contain code like this: \snippet doc/src/snippets/code/src_opengl_qgl.cpp 4 @@ -897,7 +897,7 @@ void QPlatformWindowFormat::setDefaultFormat(const QPlatformWindowFormat &f) /*! - Returns the default QGLFormat for overlay contexts. + Returns the default QPlatformWindowFormat for overlay contexts. The default overlay format is: \list @@ -923,7 +923,7 @@ void QPlatformWindowFormat::setDefaultFormat(const QPlatformWindowFormat &f) //} ///*! -// Sets a new default QGLFormat for overlay contexts to \a f. This +// Sets a new default QPlatformWindowFormat for overlay contexts to \a f. This // format is used whenever a QGLWidget is created with a format that // hasOverlay() enabled. @@ -953,10 +953,10 @@ void QPlatformWindowFormat::setDefaultFormat(const QPlatformWindowFormat &f) /*! - Returns true if all the options of the two QGLFormat objects + Returns true if all the options of the two QPlatformWindowFormat objects \a a and \a b are equal; otherwise returns false. - \relates QGLFormat + \relates QPlatformWindowFormat */ bool operator==(const QPlatformWindowFormat& a, const QPlatformWindowFormat& b) @@ -976,10 +976,10 @@ bool operator==(const QPlatformWindowFormat& a, const QPlatformWindowFormat& b) /*! - Returns false if all the options of the two QGLFormat objects + Returns false if all the options of the two QPlatformWindowFormat objects \a a and \a b are equal; otherwise returns true. - \relates QGLFormat + \relates QPlatformWindowFormat */ bool operator!=(const QPlatformWindowFormat& a, const QPlatformWindowFormat& b) diff --git a/src/opengl/qgl_qpa.cpp b/src/opengl/qgl_qpa.cpp index 917842b..8fa210b 100644 --- a/src/opengl/qgl_qpa.cpp +++ b/src/opengl/qgl_qpa.cpp @@ -52,6 +52,67 @@ QT_BEGIN_NAMESPACE +static QGLFormat qt_platformwindowformat_to_glformat(const QPlatformWindowFormat &format) +{ + QGLFormat retFormat; + retFormat.setAccum(format.accum()); + if (format.accumBufferSize() >= 0) + retFormat.setAccumBufferSize(format.accumBufferSize()); + retFormat.setAlpha(format.alpha()); + if (format.alphaBufferSize() >= 0) + retFormat.setAlphaBufferSize(format.alphaBufferSize()); + if (format.blueBufferSize() >= 0) + retFormat.setBlueBufferSize(format.blueBufferSize()); + retFormat.setDepth(format.depth()); + if (format.depthBufferSize() >= 0) + retFormat.setDepthBufferSize(format.depthBufferSize()); + retFormat.setDirectRendering(format.directRendering()); + retFormat.setDoubleBuffer(format.doubleBuffer()); + if (format.greenBufferSize() >= 0) + retFormat.setGreenBufferSize(format.greenBufferSize()); + if (format.redBufferSize() >= 0) + retFormat.setRedBufferSize(format.redBufferSize()); + retFormat.setRgba(format.rgba()); + retFormat.setSampleBuffers(format.sampleBuffers()); + retFormat.setSamples(format.sampleBuffers()); + retFormat.setStencil(format.stencil()); + if (format.stencilBufferSize() >= 0) + retFormat.setStencilBufferSize(format.stencilBufferSize()); + retFormat.setStereo(format.stereo()); + retFormat.setSwapInterval(format.swapInterval()); + return retFormat; +} + +static QPlatformWindowFormat qt_glformat_to_platformwindowformat(const QGLFormat &format) +{ + QPlatformWindowFormat retFormat; + retFormat.setAccum(format.accum()); + if (format.accumBufferSize() >= 0) + retFormat.setAccumBufferSize(format.accumBufferSize()); + retFormat.setAlpha(format.alpha()); + if (format.alphaBufferSize() >= 0) + retFormat.setAlphaBufferSize(format.alphaBufferSize()); + if (format.blueBufferSize() >= 0) + retFormat.setBlueBufferSize(format.blueBufferSize()); + retFormat.setDepth(format.depth()); + if (format.depthBufferSize() >= 0) + retFormat.setDepthBufferSize(format.depthBufferSize()); + retFormat.setDirectRendering(format.directRendering()); + retFormat.setDoubleBuffer(format.doubleBuffer()); + if (format.greenBufferSize() >= 0) + retFormat.setGreenBufferSize(format.greenBufferSize()); + if (format.redBufferSize() >= 0) + retFormat.setRedBufferSize(format.redBufferSize()); + retFormat.setRgba(format.rgba()); + retFormat.setSampleBuffers(format.sampleBuffers()); + retFormat.setSamples(format.sampleBuffers()); + retFormat.setStencil(format.stencil()); + if (format.stencilBufferSize() >= 0) + retFormat.setStencilBufferSize(format.stencilBufferSize()); + retFormat.setStereo(format.stereo()); + retFormat.setSwapInterval(format.swapInterval()); + return retFormat; +} bool QGLFormat::hasOpenGL() { @@ -61,14 +122,15 @@ bool QGLFormat::hasOpenGL() bool QGLContext::chooseContext(const QGLContext* shareContext) { Q_D(QGLContext); - if (!d->paintDevice && d->paintDevice->devType() != QInternal::Widget) { + if (!d->paintDevice || d->paintDevice->devType() != QInternal::Widget) { d->valid = false; }else { QWidget *widget = static_cast(d->paintDevice); if (!widget->platformWindow()){ - QPlatformWindowFormat format = widget->platformWindowFormat(); - format.setWindowApi(QPlatformWindowFormat::OpenGL); - widget->setPlatformWindowFormat(format); + QGLFormat glformat = format(); + QPlatformWindowFormat winFormat = qt_glformat_to_platformwindowformat(glformat); + winFormat.setWindowApi(QPlatformWindowFormat::OpenGL); + widget->setPlatformWindowFormat(winFormat); widget->winId();//make window } d->platformContext = widget->platformWindow()->glContext(); -- cgit v0.12