summaryrefslogtreecommitdiffstats
path: root/src/opengl/qgl_qpa.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/opengl/qgl_qpa.cpp')
-rw-r--r--src/opengl/qgl_qpa.cpp216
1 files changed, 112 insertions, 104 deletions
diff --git a/src/opengl/qgl_qpa.cpp b/src/opengl/qgl_qpa.cpp
index 9ba8b75362..e6c135bb7f 100644
--- a/src/opengl/qgl_qpa.cpp
+++ b/src/opengl/qgl_qpa.cpp
@@ -40,12 +40,14 @@
****************************************************************************/
#include <QApplication>
-#include <QtGui/private/qapplication_p.h>
+#include <private/qapplication_p.h>
#include <QPixmap>
#include <QDebug>
-#include <QtGui/private/qapplication_p.h>
+#include <private/qapplication_p.h>
+#include <QtGui/QPlatformGLContext>
#include <QtGui/QPlatformWindow>
+#include <QtGui/QSurfaceFormat>
#include "qgl.h"
#include "qgl_p.h"
@@ -53,81 +55,66 @@
QT_BEGIN_NAMESPACE
/*!
- Returns an OpenGL format for the platform window format specified by \a format.
+ Returns an OpenGL format for the window format specified by \a format.
*/
-QGLFormat QGLFormat::fromPlatformWindowFormat(const QPlatformWindowFormat &format)
+QGLFormat QGLFormat::fromSurfaceFormat(const QSurfaceFormat &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)
+ if (format.depthBufferSize() >= 0)
+ retFormat.setDepthBufferSize(format.depthBufferSize());
+ if (format.samples() > 1) {
+ retFormat.setSampleBuffers(format.samples());
+ retFormat.setSamples(true);
+ }
+ if (format.stencilBufferSize() > 0) {
+ retFormat.setStencil(true);
retFormat.setStencilBufferSize(format.stencilBufferSize());
+ }
+ retFormat.setDoubleBuffer(format.swapBehavior() != QSurfaceFormat::SingleBuffer);
retFormat.setStereo(format.stereo());
- retFormat.setSwapInterval(format.swapInterval());
return retFormat;
}
/*!
- Returns a platform window format for the OpenGL format specified by \a format.
+ Returns a window format for the OpenGL format specified by \a format.
*/
-QPlatformWindowFormat QGLFormat::toPlatformWindowFormat(const QGLFormat &format)
+QSurfaceFormat QGLFormat::toSurfaceFormat(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());
+ QSurfaceFormat retFormat;
+ if (format.alpha())
+ retFormat.setAlphaBufferSize(format.alphaBufferSize() == -1 ? 1 : 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());
- if (format.samples() >= 0)
- retFormat.setSamples(format.samples());
- retFormat.setStencil(format.stencil());
- if (format.stencilBufferSize() >= 0)
- retFormat.setStencilBufferSize(format.stencilBufferSize());
+ if (format.depth())
+ retFormat.setDepthBufferSize(format.depthBufferSize() == -1 ? 1 : format.depthBufferSize());
+ retFormat.setSwapBehavior(format.doubleBuffer() ? QSurfaceFormat::DoubleBuffer : QSurfaceFormat::DefaultSwapBehavior);
+ if (format.sampleBuffers())
+ retFormat.setSamples(format.samples() == -1 ? 4 : format.samples());
+ if (format.stencil())
+ retFormat.setStencilBufferSize(format.stencilBufferSize() == -1 ? 1 : format.stencilBufferSize());
retFormat.setStereo(format.stereo());
- retFormat.setSwapInterval(format.swapInterval());
return retFormat;
}
void QGLContextPrivate::setupSharing() {
Q_Q(QGLContext);
- QPlatformGLContext *sharedPlatformGLContext = platformContext->platformWindowFormat().sharedGLContext();
- if (sharedPlatformGLContext) {
- QGLContext *actualSharedContext = QGLContext::fromPlatformGLContext(sharedPlatformGLContext);
+ QGuiGLContext *sharedContext = guiGlContext->shareContext();
+ if (sharedContext) {
+ QGLContext *actualSharedContext = QGLContext::fromGuiGLContext(sharedContext);
sharing = true;
- QGLContextGroup::addShare(q,actualSharedContext);
+ QGLContextGroup::addShare(q, actualSharedContext);
}
}
@@ -150,26 +137,28 @@ bool QGLContext::chooseContext(const QGLContext* shareContext)
d->valid = false;
}else {
QWidget *widget = static_cast<QWidget *>(d->paintDevice);
- if (!widget->platformWindow()){
- QGLFormat glformat = format();
- QPlatformWindowFormat winFormat = QGLFormat::toPlatformWindowFormat(glformat);
- if (shareContext) {
- winFormat.setSharedContext(shareContext->d_func()->platformContext);
- }
- if (widget->testAttribute(Qt::WA_TranslucentBackground))
- winFormat.setAlpha(true);
- winFormat.setWindowApi(QPlatformWindowFormat::OpenGL);
- winFormat.setWindowSurface(false);
- widget->setPlatformWindowFormat(winFormat);
+ QGLFormat glformat = format();
+ QSurfaceFormat winFormat = QGLFormat::toSurfaceFormat(glformat);
+ if (widget->testAttribute(Qt::WA_TranslucentBackground))
+ winFormat.setAlphaBufferSize(qMax(winFormat.alphaBufferSize(), 8));
+
+ if (!widget->windowHandle()->handle()) {
+ widget->windowHandle()->setSurfaceType(QWindow::OpenGLSurface);
+ widget->windowHandle()->setFormat(winFormat);
widget->winId();//make window
}
- d->platformContext = widget->platformWindow()->glContext();
- Q_ASSERT(d->platformContext);
- d->glFormat = QGLFormat::fromPlatformWindowFormat(d->platformContext->platformWindowFormat());
- d->valid =(bool) d->platformContext;
- if (d->valid) {
- d->platformContext->setQGLContextHandle(this,qDeleteQGLContext);
- }
+
+ delete d->guiGlContext;
+ QGuiGLContext *shareGlContext = shareContext ? shareContext->d_func()->guiGlContext : 0;
+ d->guiGlContext = new QGuiGLContext;
+ d->guiGlContext->setFormat(winFormat);
+ d->guiGlContext->setShareContext(shareGlContext);
+ d->valid = d->guiGlContext->create();
+
+ if (d->valid)
+ d->guiGlContext->setQGLContextHandle(this,qDeleteQGLContext);
+
+ d->glFormat = QGLFormat::fromSurfaceFormat(d->guiGlContext->format());
d->setupSharing();
}
@@ -190,42 +179,55 @@ void QGLContext::reset()
d->transpColor = QColor();
d->initDone = false;
QGLContextGroup::removeShare(this);
- if (d->platformContext) {
- d->platformContext->setQGLContextHandle(0,0);
+ if (d->guiGlContext) {
+ d->guiGlContext->setQGLContextHandle(0,0);
}
}
void QGLContext::makeCurrent()
{
Q_D(QGLContext);
- d->platformContext->makeCurrent();
+ if (!d->paintDevice || d->paintDevice->devType() != QInternal::Widget)
+ return;
+
+ QWidget *widget = static_cast<QWidget *>(d->paintDevice);
+ if (!widget->windowHandle())
+ return;
- if (!d->workaroundsCached) {
- d->workaroundsCached = true;
- const char *renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
- if (renderer && strstr(renderer, "Mali")) {
- d->workaround_brokenFBOReadBack = true;
+ if (d->guiGlContext->makeCurrent(widget->windowHandle())) {
+ if (!d->workaroundsCached) {
+ d->workaroundsCached = true;
+ const char *renderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
+ if (renderer && strstr(renderer, "Mali")) {
+ d->workaround_brokenFBOReadBack = true;
+ }
}
}
-
}
void QGLContext::doneCurrent()
{
Q_D(QGLContext);
- d->platformContext->doneCurrent();
+ d->guiGlContext->doneCurrent();
}
void QGLContext::swapBuffers() const
{
Q_D(const QGLContext);
- d->platformContext->swapBuffers();
+ if (!d->paintDevice || d->paintDevice->devType() != QInternal::Widget)
+ return;
+
+ QWidget *widget = static_cast<QWidget *>(d->paintDevice);
+ if (!widget->windowHandle())
+ return;
+
+ d->guiGlContext->swapBuffers(widget->windowHandle());
}
void *QGLContext::getProcAddress(const QString &procName) const
{
Q_D(const QGLContext);
- return d->platformContext->getProcAddress(procName);
+ return (void *)d->guiGlContext->getProcAddress(procName.toAscii());
}
void QGLWidget::setContext(QGLContext *context,
@@ -283,33 +285,34 @@ void QGLContext::generateFontDisplayLists(const QFont & fnt, int listBase)
class QGLTemporaryContextPrivate
{
public:
- QWidget *widget;
- QPlatformGLContext *context;
+ QWindow *window;
+ QGuiGLContext *context;
+
+ QGLContext *oldContext;
};
QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *)
: d(new QGLTemporaryContextPrivate)
{
- d->context = const_cast<QPlatformGLContext *>(QPlatformGLContext::currentContext());
- if (d->context)
- d->context->doneCurrent();
- d->widget = new QWidget;
- d->widget->setGeometry(0,0,3,3);
- QPlatformWindowFormat format = d->widget->platformWindowFormat();
- format.setWindowApi(QPlatformWindowFormat::OpenGL);
- format.setWindowSurface(false);
- d->widget->setPlatformWindowFormat(format);
- d->widget->winId();
+ d->oldContext = const_cast<QGLContext *>(QGLContext::currentContext());
- d->widget->platformWindow()->glContext()->makeCurrent();
+ d->window = new QWindow;
+ d->window->setSurfaceType(QWindow::OpenGLSurface);
+ d->window->setGeometry(QRect(0, 0, 3, 3));
+ d->window->create();
+
+ d->context = new QGuiGLContext;
+ d->context->create();
+ d->context->makeCurrent(d->window);
}
QGLTemporaryContext::~QGLTemporaryContext()
{
- d->widget->platformWindow()->glContext()->doneCurrent();
- if (d->context)
- d->context->makeCurrent();
- delete d->widget;
+ if (d->oldContext)
+ d->oldContext->makeCurrent();
+
+ delete d->context;
+ delete d->window;
}
@@ -375,29 +378,34 @@ void QGLWidget::setColormap(const QGLColormap & c)
Q_UNUSED(c);
}
-QGLContext::QGLContext(QPlatformGLContext *platformContext)
+QGLContext::QGLContext(QGuiGLContext *context)
: d_ptr(new QGLContextPrivate(this))
{
Q_D(QGLContext);
- d->init(0,QGLFormat::fromPlatformWindowFormat(platformContext->platformWindowFormat()));
- d->platformContext = platformContext;
- d->platformContext->setQGLContextHandle(this,qDeleteQGLContext);
- d->valid = true;
+ d->init(0, QGLFormat::fromSurfaceFormat(context->format()));
+ d->guiGlContext = context;
+ d->guiGlContext->setQGLContextHandle(this,qDeleteQGLContext);
+ d->valid = context->isValid();
d->setupSharing();
}
+QGuiGLContext *QGLContext::contextHandle() const
+{
+ Q_D(const QGLContext);
+ return d->guiGlContext;
+}
+
/*!
- Returns a OpenGL context for the platform-specific OpenGL context given by
- \a platformContext.
+ Returns a OpenGL context for the window context specified by \a windowContext
*/
-QGLContext *QGLContext::fromPlatformGLContext(QPlatformGLContext *platformContext)
+QGLContext *QGLContext::fromGuiGLContext(QGuiGLContext *context)
{
- if (!platformContext)
+ if (!context)
return 0;
- if (platformContext->qGLContextHandle()) {
- return reinterpret_cast<QGLContext *>(platformContext->qGLContextHandle());
+ if (context->qGLContextHandle()) {
+ return reinterpret_cast<QGLContext *>(context->qGLContextHandle());
}
- QGLContext *glContext = new QGLContext(platformContext);
+ QGLContext *glContext = new QGLContext(context);
//Dont call create on context. This can cause the platformFormat to be set on the widget, which
//will cause the platformWindow to be recreated.
return glContext;