diff options
author | Gunnar Sletta <gunnar.sletta@nokia.com> | 2010-12-06 15:16:28 +0100 |
---|---|---|
committer | Gunnar Sletta <gunnar.sletta@nokia.com> | 2010-12-06 15:16:28 +0100 |
commit | ea79f0155fdf28f3ed1c3248bdf6d0fc5f622d64 (patch) | |
tree | b057d688838e4b7b6f220de1d11145d496990254 | |
parent | ba1c7be72879f9954029aa54023ac30a6e66710d (diff) | |
parent | 930274905328e52e0e9db07d520958b61587c612 (diff) |
Merge branch 'master' of scm.dev.nokia.troll.no:research/qt-scene-graph
-rw-r--r-- | src/effects/shadereffectitem.cpp | 49 | ||||
-rw-r--r-- | src/effects/shadereffectitem.h | 2 | ||||
-rw-r--r-- | tests/animated-circle.qml | 6 | ||||
-rw-r--r-- | tests/big-flickable.qml | 18 | ||||
-rw-r--r-- | tests/effects.qml | 30 | ||||
-rw-r--r-- | tests/mousearea.qml | 2 | ||||
-rw-r--r-- | tests/rotatingcircle.qml | 2 |
7 files changed, 81 insertions, 28 deletions
diff --git a/src/effects/shadereffectitem.cpp b/src/effects/shadereffectitem.cpp index b6668e5..4563a35 100644 --- a/src/effects/shadereffectitem.cpp +++ b/src/effects/shadereffectitem.cpp @@ -183,6 +183,7 @@ ShaderEffectSource::ShaderEffectSource(QObject *parent) , m_size(0, 0) , m_static(false) , m_fbo(0) + , m_multisampledFbo(0) , m_renderer(0) , m_refs(0) , m_dirtyTexture(true) @@ -196,6 +197,7 @@ ShaderEffectSource::~ShaderEffectSource() if (m_refs && m_sourceItem) QxItemPrivate::get(m_sourceItem)->derefFromEffectItem(); delete m_fbo; + delete m_multisampledFbo; delete m_renderer; } @@ -404,17 +406,38 @@ void ShaderEffectSource::update() Q_ASSERT(m_renderer); const QGLContext *ctx = QGLContext::currentContext(); - if (m_renderer->openGLFeatures() == 0) + if (m_renderer->openGLFeatures() == 0) { m_renderer->initializeGLFunctions(ctx); + QList<QByteArray> extensions = QByteArray((const char *)glGetString(GL_EXTENSIONS)).split(' '); + m_multisamplingSupported = extensions.contains("GL_EXT_framebuffer_multisample") + && extensions.contains("GL_EXT_framebuffer_blit"); + } if (!m_fbo) { - // TODO: Implement support for multisampling. - QGLFramebufferObjectFormat format; - format.setAttachment(QGLFramebufferObject::CombinedDepthStencil); - format.setMipmap(m_mipmap != None); - m_fbo = new QGLFramebufferObject(m_size, format); + if (ctx->format().sampleBuffers() && m_multisamplingSupported) { + // If mipmapping was just enabled, m_fbo might be 0 while m_multisampledFbo != 0. + if (!m_multisampledFbo) { + QGLFramebufferObjectFormat format; + format.setAttachment(QGLFramebufferObject::CombinedDepthStencil); + format.setSamples(ctx->format().samples()); + m_multisampledFbo = new QGLFramebufferObject(m_size, format); + } + { + QGLFramebufferObjectFormat format; + format.setAttachment(QGLFramebufferObject::NoAttachment); + format.setMipmap(m_mipmap != None); + m_fbo = new QGLFramebufferObject(m_size, format); + } + } else { + QGLFramebufferObjectFormat format; + format.setAttachment(QGLFramebufferObject::CombinedDepthStencil); + format.setMipmap(m_mipmap != None); + m_fbo = new QGLFramebufferObject(m_size, format); + } } + Q_ASSERT(m_size == m_fbo->size()); + Q_ASSERT(m_multisampledFbo == 0 || m_size == m_multisampledFbo->size()); QRectF r(0, 0, m_sourceItem->width(), m_sourceItem->height()); r.adjust(-m_margins.width(), -m_margins.height(), m_margins.width(), m_margins.height()); @@ -422,7 +445,13 @@ void ShaderEffectSource::update() m_renderer->setProjectMatrixToRect(r); m_renderer->setClearColor(Qt::transparent); - m_renderer->renderScene(BindableFbo(const_cast<QGLContext *>(QGLContext::currentContext()), m_fbo)); + if (m_multisampledFbo) { + m_renderer->renderScene(BindableFbo(const_cast<QGLContext *>(QGLContext::currentContext()), m_multisampledFbo)); + QRect r(0, 0, m_size.width(), m_size.height()); + QGLFramebufferObject::blitFramebuffer(m_fbo, r, m_multisampledFbo, r); + } else { + m_renderer->renderScene(BindableFbo(const_cast<QGLContext *>(QGLContext::currentContext()), m_fbo)); + } if (m_mipmap != None) { QGLFramebufferObject::bindDefault(); glBindTexture(GL_TEXTURE_2D, m_fbo->texture()); @@ -460,7 +489,8 @@ void ShaderEffectSource::updateSizeAndTexture() size.setHeight(1); if (m_fbo && m_fbo->size() != size) { delete m_fbo; - m_fbo = 0; + delete m_multisampledFbo; + m_fbo = m_multisampledFbo = 0; } if (m_size.width() != size.width()) { m_size.setWidth(size.width()); @@ -474,7 +504,8 @@ void ShaderEffectSource::updateSizeAndTexture() } else { if (m_fbo) { delete m_fbo; - m_fbo = 0; + delete m_multisampledFbo; + m_fbo = m_multisampledFbo = 0; } if (!m_sourceImage.isEmpty()) { // TODO: Implement async loading and loading over network. diff --git a/src/effects/shadereffectitem.h b/src/effects/shadereffectitem.h index e20769e..bcdf220 100644 --- a/src/effects/shadereffectitem.h +++ b/src/effects/shadereffectitem.h @@ -168,11 +168,13 @@ private: const TextureReference *m_texture; QGLFramebufferObject *m_fbo; + QGLFramebufferObject *m_multisampledFbo; Renderer *m_renderer; QSGContext *m_context; int m_refs; uint m_dirtyTexture : 1; // Causes update no matter what. uint m_dirtySceneGraph : 1; // Causes update if not static. + uint m_multisamplingSupported : 1; }; class ShaderEffectNode : public GeometryNode diff --git a/tests/animated-circle.qml b/tests/animated-circle.qml index af2571c..921a4bb 100644 --- a/tests/animated-circle.qml +++ b/tests/animated-circle.qml @@ -1,6 +1,6 @@ -import QtQuick 1.0 +import QtQuick 2.0 -Item +Item { width: 800 height: 600 @@ -16,6 +16,6 @@ Item x: parent.width / 2 + parent.width / 3 * Math.sin(t * Math.PI * 2) - width / 2.; y: parent.height / 2 + parent.height / 3 * Math.cos(t * Math.PI * 2) - height / 2.; - NumberAnimation on t { from: 0; to: 1; duration: 5000; loops: Animation.Infinite } + NumberAnimation on t { from: 0; to: 1; duration: 5000; loops: Animation.Infinite } } } diff --git a/tests/big-flickable.qml b/tests/big-flickable.qml index 378300b..e3591b0 100644 --- a/tests/big-flickable.qml +++ b/tests/big-flickable.qml @@ -1,20 +1,20 @@ -import Qt 4.7 +import QtQuick 2.0 Item { width: 360 height: 640 Flickable { - id: flick + id: flick anchors.fill: parent - contentWidth: 4000 - contentHeight: 3000 + contentWidth: 4000 + contentHeight: 3000 - Image { - source: "img.png" - width: flick.contentWidth - height: flick.contentHeight + Image { + source: "img.png" + width: flick.contentWidth + height: flick.contentHeight } } -}
\ No newline at end of file +} diff --git a/tests/effects.qml b/tests/effects.qml index 3f7786c..a7d9ab2 100644 --- a/tests/effects.qml +++ b/tests/effects.qml @@ -159,7 +159,6 @@ Rectangle { color: "red" font.pixelSize: 12 text: effectSource2.static ? "Static" : "Dynamic" - horizontalAlignment: Text.AlignHCenter } } @@ -243,7 +242,6 @@ Rectangle { color: "red" font.pixelSize: 12 text: effectSource3.static ? "Static" : "Dynamic" - horizontalAlignment: Text.AlignHCenter } } @@ -379,7 +377,6 @@ Rectangle { color: "red" font.pixelSize: 12 text: effectSource5.static ? "Static" : "Dynamic" - horizontalAlignment: Text.AlignHCenter } } @@ -570,6 +567,25 @@ Rectangle { visible: !parent.active } } + + Text { + anchors.left: effect1.left + anchors.top: effect1.top + anchors.margins: 3 + color: "red" + font.pixelSize: 12 + text: effectSource2.mipmap ? "Mipmap on" : "Mipmap off" + opacity: 0 + + SequentialAnimation on opacity { + id: mipmapStateAnim + running: false + PropertyAction { value: 1 } + PauseAnimation { duration: 1000 } + NumberAnimation { to: 0; duration: 1000 } + } + } + ShaderEffectItem { id: effect2 @@ -800,6 +816,7 @@ Rectangle { onClicked: { parent.value = Math.min(1.25 * parent.value, parent.max) } } MouseArea { + id: mipmapButton anchors.left: parent.left anchors.top: parent.top height: parent.height / 2 @@ -823,10 +840,13 @@ Rectangle { width: parent.width height: 4 rotation: -45 - visible: !controls.mipmap + visible: controls.mipmap } } - onClicked: { parent.mipmap = !parent.mipmap } + onClicked: { + parent.mipmap = !parent.mipmap + mipmapStateAnim.restart() + } } } } diff --git a/tests/mousearea.qml b/tests/mousearea.qml index 6924dd6..48e9044 100644 --- a/tests/mousearea.qml +++ b/tests/mousearea.qml @@ -1,4 +1,4 @@ -import QtQuick 1.0 +import QtQuick 2.0 Item diff --git a/tests/rotatingcircle.qml b/tests/rotatingcircle.qml index bf71196..d1d9342 100644 --- a/tests/rotatingcircle.qml +++ b/tests/rotatingcircle.qml @@ -1,4 +1,4 @@ -import QtQuick 1.0 +import QtQuick 2.0 Item { width: 800 |