summaryrefslogtreecommitdiffstats
path: root/src/opengl
diff options
context:
space:
mode:
authorJørgen Lind <jorgen.lind@nokia.com>2010-11-18 12:03:59 (GMT)
committerJørgen Lind <jorgen.lind@nokia.com>2010-11-22 13:14:08 (GMT)
commit292f6a9ba1b5da049e4898525974c6f0575ccd65 (patch)
treeb44bdf07f56298d7206a180a41690c2de3371fc6 /src/opengl
parenta1acef227647b3043998f9ccf364ead5c29b882d (diff)
downloadQt-292f6a9ba1b5da049e4898525974c6f0575ccd65.zip
Qt-292f6a9ba1b5da049e4898525974c6f0575ccd65.tar.gz
Qt-292f6a9ba1b5da049e4898525974c6f0575ccd65.tar.bz2
Lighthouse: move the currentContext functionality to QPlatformGLContext
This means the threading functionality has been delegated down to QPlatformGLContext. However, it is still possible to use QGLContext::currentContext to retrieve the QGLContext. This so that QGLFunctions, QGLShaderProgram etc can be used without a QGLWidget. Reviewed-by: paul
Diffstat (limited to 'src/opengl')
-rw-r--r--src/opengl/qgl.cpp24
-rw-r--r--src/opengl/qgl.h8
-rw-r--r--src/opengl/qgl_qpa.cpp22
3 files changed, 47 insertions, 7 deletions
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp
index cf45239..65d3bbe 100644
--- a/src/opengl/qgl.cpp
+++ b/src/opengl/qgl.cpp
@@ -79,6 +79,10 @@
#include <private/qglwindowsurface_qws_p.h>
#endif
+#ifdef Q_WS_QPA
+#include <QtGui/QPlatformGLContext>
+#endif
+
#include <qglpixelbuffer.h>
#include <qglframebufferobject.h>
@@ -117,7 +121,9 @@ struct QGLThreadContext {
QGLContext *context;
};
+#ifndef Q_WS_QPA
static QThreadStorage<QGLThreadContext *> qgl_context_storage;
+#endif
Q_GLOBAL_STATIC(QGLFormat, qgl_default_format)
@@ -3381,14 +3387,31 @@ void QGLContext::setInitialized(bool on)
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 0;
+#else
QGLThreadContext *threadContext = qgl_context_storage.localData();
if (threadContext)
return threadContext->context;
return 0;
+#endif //Q_WS_QPA
}
void QGLContextPrivate::setCurrentContext(QGLContext *context)
{
+#ifdef Q_WS_QPA
+ Q_UNUSED(context);
+#else
QGLThreadContext *threadContext = qgl_context_storage.localData();
if (!threadContext) {
if (!QThread::currentThread()) {
@@ -3401,6 +3424,7 @@ void QGLContextPrivate::setCurrentContext(QGLContext *context)
}
threadContext->context = context;
QGLContext::currentCtx = context; // XXX: backwards-compat, not thread-safe
+#endif
}
/*!
diff --git a/src/opengl/qgl.h b/src/opengl/qgl.h
index 4f10e5c..1f864a3 100644
--- a/src/opengl/qgl.h
+++ b/src/opengl/qgl.h
@@ -48,6 +48,10 @@
#include <QtCore/qmap.h>
#include <QtCore/qscopedpointer.h>
+#ifdef Q_WS_QPA
+#include <QtGui/QPlatformWindowFormat>
+#endif
+
QT_BEGIN_HEADER
#if defined(Q_WS_WIN)
@@ -270,6 +274,10 @@ public:
static OpenGLVersionFlags openGLVersionFlags();
+#if defined(Q_WS_QPA)
+ static QGLFormat fromPlatformWindowFormat(const QPlatformWindowFormat &format);
+ static QPlatformWindowFormat toPlatformWindowFormat(const QGLFormat &format);
+#endif
private:
QGLFormatPrivate *d;
diff --git a/src/opengl/qgl_qpa.cpp b/src/opengl/qgl_qpa.cpp
index 1197013..28bea83 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,6 +120,12 @@ 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);
@@ -129,7 +135,7 @@ bool QGLContext::chooseContext(const QGLContext* shareContext)
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);
}
@@ -140,8 +146,11 @@ bool QGLContext::chooseContext(const QGLContext* shareContext)
}
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);
+ }
}
return d->valid;
@@ -254,13 +263,13 @@ 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;
@@ -269,7 +278,6 @@ QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *)
format.setWindowApi(QPlatformWindowFormat::OpenGL);
d->widget->winId();
-
d->widget->platformWindow()->glContext()->makeCurrent();
}