diff options
author | Samuel Rødal <samuel.rodal@digia.com> | 2012-11-26 12:57:09 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-11-30 18:28:04 +0100 |
commit | 6385a182f0f93820c96cf274e50a56492491ee10 (patch) | |
tree | 5772f4c8570e620448e3ab7473c9e2df5af4005a /src/opengl/qglpixelbuffer.cpp | |
parent | 3ee48926e6584b4afeda1fc406d19d7b1a8d6f20 (diff) | |
download | qtbase-6385a182f0f93820c96cf274e50a56492491ee10.tar.gz |
Added explicit threading API to QtOpenGL.
Since QtOpenGL/QGLContext is implemented in terms of
QtGui/QOpenGLContext which has stricter requirements about how it's
supposed to be used, we need to apply these requirements to QGLContext
as well.
This change adds QGLContext::moveToThread(QThread *) and documents it as
a necessity for making a context current on another thread.
Also introduces QGLPixelbuffer::context() to access the QGLContext of a
pixelbuffer, and made QGLWidget::context() return a non-const
QGLContext, since there's no good reason why it shouldn't, and it leads
to less const_cast clutter.
We could have introduced a backdoor in QOpenGLContext instead, making it
loosen its requirements, but that would have made it harder / impossible
to fully support threaded OpenGL in all the platforms.
Task-number: QTBUG-22560
Change-Id: Ibb6f65f342e7c963e80cc42ab5664c5f1cab30b0
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Diffstat (limited to 'src/opengl/qglpixelbuffer.cpp')
-rw-r--r-- | src/opengl/qglpixelbuffer.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/opengl/qglpixelbuffer.cpp b/src/opengl/qglpixelbuffer.cpp index a5e748a1e7..dd13ef24eb 100644 --- a/src/opengl/qglpixelbuffer.cpp +++ b/src/opengl/qglpixelbuffer.cpp @@ -100,6 +100,7 @@ #include "gl2paintengineex/qpaintengineex_opengl2_p.h" +#include <qglframebufferobject.h> #include <qglpixelbuffer.h> #include <private/qglpixelbuffer_p.h> #include <private/qfont_p.h> @@ -115,11 +116,23 @@ QGLContext* QGLPBufferGLPaintDevice::context() const return pbuf->d_func()->qctx; } -void QGLPBufferGLPaintDevice::endPaint() { +void QGLPBufferGLPaintDevice::beginPaint() +{ + pbuf->makeCurrent(); + QGLPaintDevice::beginPaint(); +} + +void QGLPBufferGLPaintDevice::endPaint() +{ glFlush(); QGLPaintDevice::endPaint(); } +void QGLPBufferGLPaintDevice::setFbo(GLuint fbo) +{ + m_thisFBO = fbo; +} + void QGLPBufferGLPaintDevice::setPBuffer(QGLPixelBuffer* pb) { pbuf = pb; @@ -221,6 +234,7 @@ bool QGLPixelBuffer::makeCurrent() format.setSamples(d->req_format.samples()); d->fbo = new QOpenGLFramebufferObject(d->req_size, format); d->fbo->bind(); + d->glDevice.setFbo(d->fbo->handle()); glViewport(0, 0, d->req_size.width(), d->req_size.height()); } return true; @@ -242,6 +256,15 @@ bool QGLPixelBuffer::doneCurrent() } /*! + Returns the context of this pixelbuffer. +*/ +QGLContext *QGLPixelBuffer::context() const +{ + Q_D(const QGLPixelBuffer); + return d->qctx; +} + +/*! \fn GLuint QGLPixelBuffer::generateDynamicTexture() const Generates and binds a 2D GL texture that is the same size as the @@ -366,6 +389,8 @@ QImage QGLPixelBuffer::toImage() const return QImage(); const_cast<QGLPixelBuffer *>(this)->makeCurrent(); + if (d->fbo) + d->fbo->bind(); return qt_gl_read_framebuffer(d->req_size, d->format.alpha(), true); } @@ -615,7 +640,7 @@ GLuint QGLPixelBuffer::generateDynamicTexture() const bool QGLPixelBuffer::hasOpenGLPbuffers() { - return QOpenGLFramebufferObject::hasOpenGLFramebufferObjects(); + return QGLFramebufferObject::hasOpenGLFramebufferObjects(); } QT_END_NAMESPACE |