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.cpp93
1 files changed, 74 insertions, 19 deletions
diff --git a/src/opengl/qgl_qpa.cpp b/src/opengl/qgl_qpa.cpp
index 49c0860..415e915 100644
--- a/src/opengl/qgl_qpa.cpp
+++ b/src/opengl/qgl_qpa.cpp
@@ -52,7 +52,7 @@
QT_BEGIN_NAMESPACE
-static QGLFormat qt_platformwindowformat_to_glformat(const QPlatformWindowFormat &format)
+QGLFormat QGLFormat::fromPlatformWindowFormat(const QPlatformWindowFormat &format)
{
QGLFormat retFormat;
retFormat.setAccum(format.accum());
@@ -83,7 +83,7 @@ static QGLFormat qt_platformwindowformat_to_glformat(const QPlatformWindowFormat
return retFormat;
}
-static QPlatformWindowFormat qt_glformat_to_platformwindowformat(const QGLFormat &format)
+QPlatformWindowFormat QGLFormat::toPlatformWindowFormat(const QGLFormat &format)
{
QPlatformWindowFormat retFormat;
retFormat.setAccum(format.accum());
@@ -120,27 +120,49 @@ bool QGLFormat::hasOpenGL()
return QApplicationPrivate::platformIntegration()->hasOpenGL();
}
+void qDeleteQGLContext(void *handle)
+{
+ QGLContext *context = static_cast<QGLContext *>(handle);
+ delete context;
+}
+
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<QWidget *>(d->paintDevice);
if (!widget->platformWindow()){
QGLFormat glformat = format();
- QPlatformWindowFormat winFormat = qt_glformat_to_platformwindowformat(glformat);
+ QPlatformWindowFormat winFormat = QGLFormat::toPlatformWindowFormat(glformat);
if (shareContext) {
winFormat.setSharedContext(shareContext->d_func()->platformContext);
}
winFormat.setWindowApi(QPlatformWindowFormat::OpenGL);
+ winFormat.setWindowSurface(false);
widget->setPlatformWindowFormat(winFormat);
widget->winId();//make window
}
d->platformContext = widget->platformWindow()->glContext();
Q_ASSERT(d->platformContext);
- d->glFormat = qt_platformwindowformat_to_glformat(d->platformContext->platformWindowFormat());
+ d->glFormat = QGLFormat::fromPlatformWindowFormat(d->platformContext->platformWindowFormat());
d->valid =(bool) d->platformContext;
+ if (d->valid) {
+ d->platformContext->setQGLContextHandle(this,qDeleteQGLContext);
+ }
+ }
+
+ if (d->valid) {
+ QPlatformGLContext *sharedPlatformGLContext = d->platformContext->platformWindowFormat().sharedGLContext();
+ if (sharedPlatformGLContext) {
+ QGLContext *actualSharedContext = QGLContext::fromPlatformGLContext(sharedPlatformGLContext);
+ if (actualSharedContext == shareContext) {
+ d->sharing = true;//Will add combination in QGLContext::create
+ }else {
+ QGLContextGroup::addShare(this,actualSharedContext);
+ }
+ }
}
return d->valid;
@@ -159,20 +181,30 @@ void QGLContext::reset()
d->transpColor = QColor();
d->initDone = false;
QGLContextGroup::removeShare(this);
+ if (d->platformContext) {
+ d->platformContext->setQGLContextHandle(0,0);
+ }
}
void QGLContext::makeCurrent()
{
Q_D(QGLContext);
d->platformContext->makeCurrent();
- QGLContextPrivate::setCurrentContext(this);
+
+ 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();
- QGLContextPrivate::setCurrentContext(0);
}
void QGLContext::swapBuffers() const
@@ -196,10 +228,9 @@ void QGLWidget::setContext(QGLContext *context,
qWarning("QGLWidget::setContext: Cannot set null context");
return;
}
- if (!context->deviceIsPixmap() && context->device() != this) {
- qWarning("QGLWidget::setContext: Context must refer to this widget");
- return;
- }
+
+ if (context->device() == 0) // a context may refere to more than 1 window.
+ context->setDevice(this); //but its better to point to 1 of them than none of them.
QGLContext* oldcx = d->glcx;
d->glcx = context;
@@ -244,22 +275,23 @@ class QGLTemporaryContextPrivate
{
public:
QWidget *widget;
- QGLContext *context;
+ QPlatformGLContext *context;
};
QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *)
: d(new QGLTemporaryContextPrivate)
{
- d->context = const_cast<QGLContext *>(QGLContext::currentContext());
+ 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->widget->platformWindow()->glContext()->makeCurrent();
}
@@ -294,11 +326,8 @@ bool QGLWidget::event(QEvent *e)
{
Q_D(QGLWidget);
if (e->type() == QEvent::WinIdChange) {
- if (d->glcx->isValid()) {
- if (QGLContext::currentContext() == d->glcx)
- QGLContextPrivate::setCurrentContext(0); //Its not valid anymore
- setContext(new QGLContext(d->glcx->requestedFormat(), this));
-
+ if (platformWindow()) {
+ d->glcx = QGLContext::fromPlatformGLContext(platformWindow()->glContext());
}
}
return QWidget::event(e);
@@ -342,4 +371,30 @@ void QGLWidget::setColormap(const QGLColormap & c)
Q_UNUSED(c);
}
+QGLContext::QGLContext(QPlatformGLContext *platformContext)
+ : d_ptr(new QGLContextPrivate(this))
+{
+ Q_D(QGLContext);
+ d->init(0,QGLFormat::fromPlatformWindowFormat(platformContext->platformWindowFormat()));
+ d->platformContext = platformContext;
+}
+
+QGLContext *QGLContext::fromPlatformGLContext(QPlatformGLContext *platformContext)
+{
+ if (!platformContext)
+ return 0;
+ if (platformContext->qGLContextHandle()) {
+ return reinterpret_cast<QGLContext *>(platformContext->qGLContextHandle());
+ }
+ QGLContext *glContext = new QGLContext(platformContext);
+ //Dont call create on context. This can cause the platformFormat to be set on the widget, which
+ //will cause the platformWindow to be recreated.
+ glContext->d_func()->platformContext->setQGLContextHandle(glContext,qDeleteQGLContext);
+ QGLFormat format = QGLFormat::fromPlatformWindowFormat(platformContext->platformWindowFormat());
+ glContext->d_func()->glFormat = format;
+ glContext->d_func()->valid = true;
+
+ return glContext;
+}
+
QT_END_NAMESPACE