summaryrefslogtreecommitdiffstats
path: root/src/opengl/qgl.cpp
diff options
context:
space:
mode:
authorJørgen Lind <jorgen.lind@nokia.com>2010-11-23 14:34:09 (GMT)
committerJørgen Lind <jorgen.lind@nokia.com>2010-11-24 08:54:48 (GMT)
commit004cd14b84e3683cd92cf01061ee9688990f990c (patch)
tree8f879f07439b212de831c528e832d3c3ab4c6bb3 /src/opengl/qgl.cpp
parentf309a20b4177572282082b8c17ec9025b75a69b1 (diff)
downloadQt-004cd14b84e3683cd92cf01061ee9688990f990c.zip
Qt-004cd14b84e3683cd92cf01061ee9688990f990c.tar.gz
Qt-004cd14b84e3683cd92cf01061ee9688990f990c.tar.bz2
Lighthouse: Fix QGLContext::currentContext for systems with limited
resources. The example plugins EGLFS uses only 1 native context. Make sure that we only use this 1 context, and that we dont wrap it in many different QPlatformGLContexts or QGLContexts instanses. This change also removes the QPlatformWindow link which was made in the initial QPlatformGLContext change. Lighthouse has to support situations where a context isnt bound to a QPlatformWindow. Reviewed-by: gunnar
Diffstat (limited to 'src/opengl/qgl.cpp')
-rw-r--r--src/opengl/qgl.cpp58
1 files changed, 49 insertions, 9 deletions
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp
index 65d3bbe..5eb4c16 100644
--- a/src/opengl/qgl.cpp
+++ b/src/opengl/qgl.cpp
@@ -2095,6 +2095,14 @@ QGLContext::QGLContext(const QGLFormat &format)
d->init(0, format);
}
+QGLContext::QGLContext(QPlatformGLContext *platformContext)
+ : d_ptr(new QGLContextPrivate(this))
+{
+ Q_D(QGLContext);
+ d->init(0,QGLFormat::fromPlatformWindowFormat(platformContext->platformWindowFormat()));
+ d->platformContext = platformContext;
+}
+
/*!
Destroys the OpenGL context and frees its resources.
*/
@@ -3152,6 +3160,18 @@ void QGLContext::setDevice(QPaintDevice *pDev)
}
}
+QGLContext *QGLContext::fromPlatformGLContext(QPlatformGLContext *platformContext)
+{
+ if (!platformContext)
+ return 0;
+ if (platformContext->qGLContextHandle()) {
+ return reinterpret_cast<QGLContext *>(platformContext->qGLContextHandle());
+ }
+ QGLContext *glContext = new QGLContext(platformContext);
+ glContext->create();
+ return glContext;
+}
+
/*!
\fn bool QGLContext::isValid() const
@@ -3304,11 +3324,16 @@ bool QGLContext::areSharing(const QGLContext *context1, const QGLContext *contex
bool QGLContext::create(const QGLContext* shareContext)
{
Q_D(QGLContext);
+#ifdef Q_WS_QPA
+ if (!d->paintDevice && !d->platformContext)
+#else
if (!d->paintDevice)
+#endif
return false;
+
reset();
d->valid = chooseContext(shareContext);
- if (d->valid && d->paintDevice->devType() == QInternal::Widget) {
+ if (d->valid && d->paintDevice && d->paintDevice->devType() == QInternal::Widget) {
QWidgetPrivate *wd = qt_widget_private(static_cast<QWidget *>(d->paintDevice));
wd->usesDoubleBufferedGLContext = d->glFormat.doubleBuffer();
}
@@ -3389,14 +3414,7 @@ const QGLContext* QGLContext::currentContext()
{
#ifdef Q_WS_QPA
if (const QPlatformGLContext *threadContext = QPlatformGLContext::currentContext()) {
- if (threadContext->qGLContextHandle()) {
- return (const QGLContext *)threadContext->qGLContextHandle();
- } else {
- QWidget *widget = threadContext->platformWindow()->widget();
- QGLContext *context = new QGLContext(QGLFormat::fromPlatformWindowFormat(threadContext->platformWindowFormat()),widget);
- context->create(); //don't know how to pass in the sharecontext. (doesn't really matter though)
- return context;
- }
+ return QGLContext::fromPlatformGLContext(const_cast<QPlatformGLContext *>(threadContext));
}
return 0;
#else
@@ -3781,7 +3799,18 @@ QGLWidget::QGLWidget(QWidget *parent, const QGLWidget* shareWidget, Qt::WindowFl
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_NoSystemBackground);
setAutoFillBackground(true); // for compatibility
+#ifdef Q_WS_QPA
+ setPlatformWindowFormat(QGLFormat::toPlatformWindowFormat(QGLFormat::defaultFormat()));
+ winId(); // create window;
+ QGLContext *glContext = 0;
+ if (platformWindow())
+ glContext = QGLContext::fromPlatformGLContext(platformWindow()->glContext());
+ if (glContext){
+ d->init(glContext,shareWidget);
+ }
+#else
d->init(new QGLContext(QGLFormat::defaultFormat(), this), shareWidget);
+#endif
}
@@ -3821,7 +3850,18 @@ QGLWidget::QGLWidget(const QGLFormat &format, QWidget *parent, const QGLWidget*
setAttribute(Qt::WA_PaintOnScreen);
setAttribute(Qt::WA_NoSystemBackground);
setAutoFillBackground(true); // for compatibility
+#ifdef Q_WS_QPA
+ setPlatformWindowFormat(QGLFormat::toPlatformWindowFormat(QGLFormat::defaultFormat()));
+ winId(); // create window;
+ QGLContext *glContext = 0;
+ if (platformWindow())
+ glContext = QGLContext::fromPlatformGLContext(platformWindow()->glContext());
+ if (glContext){
+ d->init(glContext,shareWidget);
+ }
+#else
d->init(new QGLContext(format, this), shareWidget);
+#endif
}
/*!