diff options
author | Kim Motoyoshi Kalland <[email protected]> | 2012-02-15 17:26:48 +0100 |
---|---|---|
committer | Qt by Nokia <[email protected]> | 2012-03-22 10:55:27 +0100 |
commit | 9d1b013d448423906b8f6352f69b715940d813c9 (patch) | |
tree | 933d18be186de8da36dfff106e5fcb196935dee1 /src/quick/items/qquickshadereffectsource.cpp | |
parent | 23d56db0c8e156fb19cec6a155105493d13a4f9f (diff) |
Share depth-stencil buffers between ShaderEffectSources of same size.
Change-Id: If325a38175249c3a3ffe5043d42ba35dbf90ce0c
Reviewed-by: Gunnar Sletta <[email protected]>
Diffstat (limited to 'src/quick/items/qquickshadereffectsource.cpp')
-rw-r--r-- | src/quick/items/qquickshadereffectsource.cpp | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/src/quick/items/qquickshadereffectsource.cpp b/src/quick/items/qquickshadereffectsource.cpp index 48196655ab..c55b1ca7f5 100644 --- a/src/quick/items/qquickshadereffectsource.cpp +++ b/src/quick/items/qquickshadereffectsource.cpp @@ -54,6 +54,39 @@ QT_BEGIN_NAMESPACE DEFINE_BOOL_CONFIG_OPTION(qmlFboOverlay, QML_FBO_OVERLAY) +namespace +{ + class BindableFbo : public QSGBindable + { + public: + BindableFbo(QOpenGLFramebufferObject *fbo, QSGDepthStencilBuffer *depthStencil); + virtual ~BindableFbo(); + virtual void bind() const; + private: + QOpenGLFramebufferObject *m_fbo; + QSGDepthStencilBuffer *m_depthStencil; + }; + + BindableFbo::BindableFbo(QOpenGLFramebufferObject *fbo, QSGDepthStencilBuffer *depthStencil) + : m_fbo(fbo) + , m_depthStencil(depthStencil) + { + } + + BindableFbo::~BindableFbo() + { + if (m_depthStencil) + m_depthStencil->detach(); + } + + void BindableFbo::bind() const + { + m_fbo->bind(); + if (m_depthStencil) + m_depthStencil->attach(); + } +} + class QQuickShaderEffectSourceTextureProvider : public QSGTextureProvider { Q_OBJECT @@ -239,6 +272,7 @@ void QQuickShaderEffectTexture::grab() delete m_fbo; delete m_secondaryFbo; m_fbo = m_secondaryFbo = 0; + m_depthStencilBuffer.clear(); m_dirtyTexture = false; if (m_grab) emit scheduledUpdateCompleted(); @@ -272,13 +306,12 @@ void QQuickShaderEffectTexture::grab() delete m_secondaryFbo; QOpenGLFramebufferObjectFormat format; - format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); format.setInternalTextureFormat(m_format); format.setSamples(8); m_secondaryFbo = new QOpenGLFramebufferObject(m_size, format); + m_depthStencilBuffer = m_context->depthStencilBufferForFbo(m_secondaryFbo); } else { QOpenGLFramebufferObjectFormat format; - format.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); format.setInternalTextureFormat(m_format); format.setMipmap(m_mipmap); if (m_recursive) { @@ -287,6 +320,7 @@ void QQuickShaderEffectTexture::grab() m_secondaryFbo = new QOpenGLFramebufferObject(m_size, format); glBindTexture(GL_TEXTURE_2D, m_secondaryFbo->texture()); updateBindOptions(true); + m_depthStencilBuffer = m_context->depthStencilBufferForFbo(m_secondaryFbo); } else { delete m_fbo; delete m_secondaryFbo; @@ -294,6 +328,7 @@ void QQuickShaderEffectTexture::grab() m_secondaryFbo = 0; glBindTexture(GL_TEXTURE_2D, m_fbo->texture()); updateBindOptions(true); + m_depthStencilBuffer = m_context->depthStencilBufferForFbo(m_fbo); } } } @@ -336,7 +371,7 @@ void QQuickShaderEffectTexture::grab() m_renderer->setClearColor(Qt::transparent); if (m_multisampling) { - m_renderer->renderScene(QSGBindableFbo(m_secondaryFbo)); + m_renderer->renderScene(BindableFbo(m_secondaryFbo, m_depthStencilBuffer.data())); if (deleteFboLater) { delete m_fbo; @@ -354,7 +389,7 @@ void QQuickShaderEffectTexture::grab() QOpenGLFramebufferObject::blitFramebuffer(m_fbo, r, m_secondaryFbo, r); } else { if (m_recursive) { - m_renderer->renderScene(QSGBindableFbo(m_secondaryFbo)); + m_renderer->renderScene(BindableFbo(m_secondaryFbo, m_depthStencilBuffer.data())); if (deleteFboLater) { delete m_fbo; @@ -368,7 +403,7 @@ void QQuickShaderEffectTexture::grab() } qSwap(m_fbo, m_secondaryFbo); } else { - m_renderer->renderScene(QSGBindableFbo(m_fbo)); + m_renderer->renderScene(BindableFbo(m_fbo, m_depthStencilBuffer.data())); } } |