diff options
Diffstat (limited to 'src/gui/kernel/qguiglcontext_qpa.cpp')
-rw-r--r-- | src/gui/kernel/qguiglcontext_qpa.cpp | 85 |
1 files changed, 76 insertions, 9 deletions
diff --git a/src/gui/kernel/qguiglcontext_qpa.cpp b/src/gui/kernel/qguiglcontext_qpa.cpp index fd827966c4..61a0479bd3 100644 --- a/src/gui/kernel/qguiglcontext_qpa.cpp +++ b/src/gui/kernel/qguiglcontext_qpa.cpp @@ -47,6 +47,7 @@ #include <QtCore/QThread> #include <QtGui/private/qguiapplication_p.h> +#include <QtGui/QScreen> #include <QDebug> @@ -69,6 +70,7 @@ public: : qGLContextHandle(0) , platformGLContext(0) , shareContext(0) + , screen(0) { } @@ -79,8 +81,11 @@ public: } void *qGLContextHandle; void (*qGLContextDeleteFunction)(void *handle); + + QSurfaceFormat requestedFormat; QPlatformGLContext *platformGLContext; QGuiGLContext *shareContext; + QScreen *screen; static void setCurrentContext(QGuiGLContext *context); }; @@ -117,29 +122,87 @@ QPlatformGLContext *QGuiGLContext::handle() const return d->platformGLContext; } +QPlatformGLContext *QGuiGLContext::shareHandle() const +{ + Q_D(const QGuiGLContext); + if (d->shareContext) + return d->shareContext->handle(); + return 0; +} + /*! - Creates a new GL context with the given format and shared context. + Creates a new GL context instance, you need to call create() before it can be used. */ -QGuiGLContext::QGuiGLContext(const QSurfaceFormat &format, QGuiGLContext *shareContext) +QGuiGLContext::QGuiGLContext() : d_ptr(new QGuiGLContextPrivate()) { Q_D(QGuiGLContext); - QPlatformGLContext *share = shareContext ? shareContext->handle() : 0; + d->screen = QGuiApplication::primaryScreen(); +} + +/*! + Sets the format the GL context should be compatible with. You need to call create() before it takes effect. +*/ +void QGuiGLContext::setFormat(const QSurfaceFormat &format) +{ + Q_D(QGuiGLContext); + d->requestedFormat = format; +} + +/*! + Sets the context to share textures, shaders, and other GL resources with. You need to call create() before it takes effect. +*/ +void QGuiGLContext::setShareContext(QGuiGLContext *shareContext) +{ + Q_D(QGuiGLContext); d->shareContext = shareContext; - d->platformGLContext = QGuiApplicationPrivate::platformIntegration()->createPlatformGLContext(format, share); } /*! - If this is the current context for the thread, doneCurrent is called + Sets the screen the GL context should be valid for. You need to call create() before it takes effect. */ -QGuiGLContext::~QGuiGLContext() +void QGuiGLContext::setScreen(QScreen *screen) +{ + Q_D(QGuiGLContext); + d->screen = screen; + if (!d->screen) + d->screen = QGuiApplication::primaryScreen(); +} + +/*! + Attempts to create the GL context with the desired parameters. + + Returns true if the native context was successfully created and is ready to be used.d +*/ +bool QGuiGLContext::create() +{ + destroy(); + + Q_D(QGuiGLContext); + d->platformGLContext = QGuiApplicationPrivate::platformIntegration()->createPlatformGLContext(this); + return d->platformGLContext; +} + +void QGuiGLContext::destroy() { Q_D(QGuiGLContext); if (QGuiGLContext::currentContext() == this) doneCurrent(); delete d->platformGLContext; + d->platformGLContext = 0; +} + +/*! + If this is the current context for the thread, doneCurrent is called +*/ +QGuiGLContext::~QGuiGLContext() +{ + destroy(); } +/*! + Returns if this context is valid, i.e. has been successfully created. +*/ bool QGuiGLContext::isValid() const { Q_D(const QGuiGLContext); @@ -210,18 +273,22 @@ QSurfaceFormat QGuiGLContext::format() const { Q_D(const QGuiGLContext); if (!d->platformGLContext) - return QSurfaceFormat(); + return d->requestedFormat; return d->platformGLContext->format(); } QGuiGLContext *QGuiGLContext::shareContext() const { Q_D(const QGuiGLContext); - if (!d->platformGLContext) - return 0; return d->shareContext; } +QScreen *QGuiGLContext::screen() const +{ + Q_D(const QGuiGLContext); + return d->screen; +} + /* internal: Needs to have a pointer to qGLContext. But since this is in QtGui we cant have any type information. |