diff options
author | Liang Qi <liang.qi@theqtcompany.com> | 2015-03-24 07:37:43 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@theqtcompany.com> | 2015-03-24 07:38:02 +0100 |
commit | 135ebe4f3d268121047fdbfee49f2dd52006165e (patch) | |
tree | 6b303103f36e69e29cfa860b8b7afc584c55d6f3 /src/platformsupport/platformcompositor/qopenglcompositor.cpp | |
parent | e7feb956280105113b3e58f12e5f32f54199a95a (diff) | |
parent | 1e8f50a8d069c97ea6a4f00d664c12e594884f54 (diff) |
Merge remote-tracking branch 'origin/5.5' into dev
Change-Id: If5d2e621c2fa5476c3ab687a3f4620c54fc3b32e
Diffstat (limited to 'src/platformsupport/platformcompositor/qopenglcompositor.cpp')
-rw-r--r-- | src/platformsupport/platformcompositor/qopenglcompositor.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/platformsupport/platformcompositor/qopenglcompositor.cpp b/src/platformsupport/platformcompositor/qopenglcompositor.cpp index 3048b2b777..3fd6c999a2 100644 --- a/src/platformsupport/platformcompositor/qopenglcompositor.cpp +++ b/src/platformsupport/platformcompositor/qopenglcompositor.cpp @@ -32,6 +32,7 @@ ****************************************************************************/ #include <QtGui/QOpenGLContext> +#include <QtGui/QOpenGLFramebufferObject> #include <QtGui/QWindow> #include <QtGui/QMatrix4x4> #include <qpa/qplatformbackingstore.h> @@ -76,7 +77,7 @@ QOpenGLCompositor::QOpenGLCompositor() Q_ASSERT(!compositor); m_updateTimer.setSingleShot(true); m_updateTimer.setInterval(0); - connect(&m_updateTimer, SIGNAL(timeout()), SLOT(renderAll())); + connect(&m_updateTimer, SIGNAL(timeout()), SLOT(handleRenderAllRequest())); } QOpenGLCompositor::~QOpenGLCompositor() @@ -98,10 +99,26 @@ void QOpenGLCompositor::update() m_updateTimer.start(); } -void QOpenGLCompositor::renderAll() +QImage QOpenGLCompositor::grab() { Q_ASSERT(m_context && m_targetWindow); m_context->makeCurrent(m_targetWindow); + QScopedPointer<QOpenGLFramebufferObject> fbo(new QOpenGLFramebufferObject(m_targetWindow->geometry().size())); + renderAll(fbo.data()); + return fbo->toImage(); +} + +void QOpenGLCompositor::handleRenderAllRequest() +{ + Q_ASSERT(m_context && m_targetWindow); + m_context->makeCurrent(m_targetWindow); + renderAll(0); +} + +void QOpenGLCompositor::renderAll(QOpenGLFramebufferObject *fbo) +{ + if (fbo) + fbo->bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); @@ -120,7 +137,10 @@ void QOpenGLCompositor::renderAll() render(m_windows.at(i)); m_blitter.release(); - m_context->swapBuffers(m_targetWindow); + if (!fbo) + m_context->swapBuffers(m_targetWindow); + else + fbo->release(); for (int i = 0; i < m_windows.size(); ++i) m_windows.at(i)->endCompositing(); |