diff options
author | Tom Cooksey <thomas.cooksey@nokia.com> | 2010-03-02 15:41:16 (GMT) |
---|---|---|
committer | Tom Cooksey <thomas.cooksey@nokia.com> | 2010-03-02 15:48:15 (GMT) |
commit | e614e3548bbe505c75e8b3a54f44f07522a6ecf5 (patch) | |
tree | 9b9a6515416a94434e346ec548e002fb6e11e96b /src/opengl/qgl_egl.cpp | |
parent | 03daf059647c0a0222e8774b0a083f58c8e64934 (diff) | |
download | Qt-e614e3548bbe505c75e8b3a54f44f07522a6ecf5.zip Qt-e614e3548bbe505c75e8b3a54f44f07522a6ecf5.tar.gz Qt-e614e3548bbe505c75e8b3a54f44f07522a6ecf5.tar.bz2 |
Add and use QGLContextPrivate::eglSurfaceForDevice()
The QGLContext only stores the EGLSurface for QWidgets & QGLWidgets,
other device types like QPixmap & QGLPixelBuffer store the surface
themsselves. With this patch it is possible to create a QGLContext
on a QPixmap, make it current and render GL to that QPixmap on X11.
Reviewed-By: TrustMe
Diffstat (limited to 'src/opengl/qgl_egl.cpp')
-rw-r--r-- | src/opengl/qgl_egl.cpp | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/opengl/qgl_egl.cpp b/src/opengl/qgl_egl.cpp index f1abab8..7bfcf27 100644 --- a/src/opengl/qgl_egl.cpp +++ b/src/opengl/qgl_egl.cpp @@ -40,8 +40,14 @@ ****************************************************************************/ #include <QtOpenGL/qgl.h> +#include <QtOpenGL/qglpixelbuffer.h> #include "qgl_p.h" #include "qgl_egl_p.h" +#include "qglpixelbuffer_p.h" + +#ifdef Q_WS_X11 +#include <QtGui/private/qpixmap_x11_p.h> +#endif QT_BEGIN_NAMESPACE @@ -154,12 +160,12 @@ void QGLContext::reset() void QGLContext::makeCurrent() { Q_D(QGLContext); - if (!d->valid || !d->eglContext || d->eglSurface == EGL_NO_SURFACE) { + if (!d->valid || !d->eglContext || d->eglSurfaceForDevice() == EGL_NO_SURFACE) { qWarning("QGLContext::makeCurrent(): Cannot make invalid context current"); return; } - if (d->eglContext->makeCurrent(d->eglSurface)) + if (d->eglContext->makeCurrent(d->eglSurfaceForDevice())) QGLContextPrivate::setCurrentContext(this); } @@ -179,7 +185,7 @@ void QGLContext::swapBuffers() const if (!d->valid || !d->eglContext) return; - d->eglContext->swapBuffers(d->eglSurface); + d->eglContext->swapBuffers(d->eglSurfaceForDevice()); } void QGLContextPrivate::destroyEglSurfaceForDevice() @@ -202,6 +208,27 @@ void QGLContextPrivate::destroyEglSurfaceForDevice() } } +EGLSurface QGLContextPrivate::eglSurfaceForDevice() const +{ + if (paintDevice->devType() == QInternal::Widget) + return eglSurface; + if (paintDevice->devType() == QInternal::Pixmap) { +#ifdef Q_WS_X11 + QPixmapData *pmd = static_cast<QPixmap*>(paintDevice)->data_ptr().data(); + if (pmd->classId() == QPixmapData::X11Class) { + QX11PixmapData* x11PixmapData = static_cast<QX11PixmapData*>(pmd); + return (EGLSurface)x11PixmapData->gl_surface; + } else +#endif + return eglSurface; + } + if (paintDevice->devType() == QInternal::Pbuffer) { + QGLPixelBuffer* pbuf = static_cast<QGLPixelBuffer*>(paintDevice); + return pbuf->d_func()->pbuf; + } + return EGL_NO_SURFACE; +} + void QGLWidget::setMouseTracking(bool enable) { QWidget::setMouseTracking(enable); |