From 6385a182f0f93820c96cf274e50a56492491ee10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Mon, 26 Nov 2012 12:57:09 +0100 Subject: 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 Reviewed-by: Gunnar Sletta --- src/opengl/qglpixelbuffer.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/opengl/qglpixelbuffer.cpp') 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 #include #include #include @@ -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; @@ -241,6 +255,15 @@ bool QGLPixelBuffer::doneCurrent() return true; } +/*! + Returns the context of this pixelbuffer. +*/ +QGLContext *QGLPixelBuffer::context() const +{ + Q_D(const QGLPixelBuffer); + return d->qctx; +} + /*! \fn GLuint QGLPixelBuffer::generateDynamicTexture() const @@ -366,6 +389,8 @@ QImage QGLPixelBuffer::toImage() const return QImage(); const_cast(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 -- cgit v1.2.3