diff options
author | Marko Niemelä <marko.a.niemela@nokia.com> | 2011-08-02 14:02:27 +0300 |
---|---|---|
committer | Marko Niemelä <marko.a.niemela@nokia.com> | 2011-08-02 14:02:27 +0300 |
commit | 5c11609d474eabe3e0ecd801f5b42850a1bcef0c (patch) | |
tree | fa5621ae09aafd92ab144d28234a69aa3d45bb20 | |
parent | ad316ac4d3485f061e40e5970a17a24bb1c7ac25 (diff) |
5 files changed, 33 insertions, 47 deletions
diff --git a/src/shadereffect.cpp b/src/shadereffect.cpp index bbea43c..ece0241 100644 --- a/src/shadereffect.cpp +++ b/src/shadereffect.cpp @@ -105,50 +105,27 @@ void ShaderEffect::updateRenderTargets() p.setCompositionMode(QPainter::CompositionMode_SourceOver); QRectF sourceRect = m_renderTargets[i]->sourceRect(); - QSize textureSize = m_renderTargets[i]->textureSize(); - qreal yflip = m_renderTargets[i]->isMirrored() ? -1.0 : 1.0; // flip y to match scenegraph, it also flips texturecoordinates - qreal xscale = 1.0; - qreal yscale = 1.0 * yflip; - - qreal leftMargin = 0.0; - qreal rightMargin = 0.0; - qreal topMargin = 0.0; - qreal bottomMargin = 0.0; - - qreal width = m_renderTargets[i]->sourceItem()->width(); - qreal height = m_renderTargets[i]->sourceItem()->height(); - - if (!sourceRect.isEmpty()) { - leftMargin = -sourceRect.left(); - rightMargin = sourceRect.right() - width; - topMargin = -sourceRect.top(); - bottomMargin = sourceRect.bottom() - height; - } - if ((width + leftMargin + rightMargin) > 0 && (height + topMargin + bottomMargin) > 0) { - if (!textureSize.isEmpty()) { - qreal textureWidth = textureSize.width(); - qreal textureHeight = textureSize.height(); - - xscale = width / (width + leftMargin + rightMargin); - yscale = height / (height + topMargin + bottomMargin); - - p.translate(textureWidth / 2, textureHeight / 2); - p.scale(xscale, yscale * yflip); - p.translate(-textureWidth / 2, -textureHeight / 2); - p.scale(textureWidth / width, textureHeight / height); - } else { - xscale = width / (width + leftMargin + rightMargin); - yscale = height / (height + topMargin + bottomMargin); - - p.translate(width / 2, height / 2); - p.scale(xscale, yscale * yflip); - p.translate(-width / 2, -height / 2); - } + qreal textureWidth = m_renderTargets[i]->fbo()->size().width(); + qreal textureHeight = m_renderTargets[i]->fbo()->size().height(); + + qreal sourceWidth = m_renderTargets[i]->sourceItem()->width(); + qreal sourceHeight = m_renderTargets[i]->sourceItem()->height(); + + if (!sourceRect.isEmpty() > 0) { + sourceWidth = sourceRect.width(); + sourceHeight = sourceRect.height(); } - drawSource(&p); + if (sourceWidth > 0 && sourceHeight > 0) { + qreal xscale = textureWidth / sourceWidth; + qreal yscale = textureHeight / sourceHeight; + p.scale(xscale, yscale * yflip); + p.translate(-sourceRect.left(), -sourceRect.top()); + drawSource(&p); + } + p.end(); m_renderTargets[i]->markSceneGraphDirty(); } diff --git a/tests/manual/qmlshadersplugintest/qml/qmlshadersplugintest/TestItemMargins.qml b/tests/manual/qmlshadersplugintest/qml/qmlshadersplugintest/TestItemMargins.qml index 94f7824..8c7fcbf 100644 --- a/tests/manual/qmlshadersplugintest/qml/qmlshadersplugintest/TestItemMargins.qml +++ b/tests/manual/qmlshadersplugintest/qml/qmlshadersplugintest/TestItemMargins.qml @@ -53,16 +53,21 @@ Rectangle { interval: 2000 repeat: true onTriggered: { - if (marginTester.testMarginX < 20) { + if (marginTester.testMarginX == 10) { marginTester.testMarginX = 50 marginTester.testMarginY = 120 + theSource.sourceRect = Qt.rect(-testMarginX, -testMarginY, parent.width + testMarginX*2, parent.height + testMarginY*2) } - else { + else if (marginTester.testMarginX == -200){ marginTester.testMarginX = 10 marginTester.testMarginY = 10 + theSource.sourceRect = Qt.rect(-testMarginX, -testMarginY, parent.width + testMarginX*2, parent.height + testMarginY*2) + } else { + marginTester.testMarginX = -200 + marginTester.testMarginY = -180 + theSource.sourceRect = Qt.rect(-testMarginX, -testMarginY, 150, 200) } - theSource.sourceRect = Qt.rect(-testMarginX, -testMarginY, parent.width + testMarginX*2, parent.height + testMarginY*2) console.log("onTriggered") } } diff --git a/tests/manual/qmlshadersplugintest/qml/qmlshadersplugintest/TestItemMarginsWithTextureSize.qml b/tests/manual/qmlshadersplugintest/qml/qmlshadersplugintest/TestItemMarginsWithTextureSize.qml index 83784c3..fb9f2e3 100644 --- a/tests/manual/qmlshadersplugintest/qml/qmlshadersplugintest/TestItemMarginsWithTextureSize.qml +++ b/tests/manual/qmlshadersplugintest/qml/qmlshadersplugintest/TestItemMarginsWithTextureSize.qml @@ -53,16 +53,20 @@ Rectangle { interval: 2000 repeat: true onTriggered: { - if (marginTester.testMarginX < 20) { + if (marginTester.testMarginX == 10) { marginTester.testMarginX = 50 marginTester.testMarginY = 120 + theSource.sourceRect = Qt.rect(-testMarginX, -testMarginY, parent.width + testMarginX*2, parent.height + testMarginY*2) } - else { + else if (marginTester.testMarginX == -200){ marginTester.testMarginX = 10 marginTester.testMarginY = 10 + theSource.sourceRect = Qt.rect(-testMarginX, -testMarginY, parent.width + testMarginX*2, parent.height + testMarginY*2) + } else { + marginTester.testMarginX = -200 + marginTester.testMarginY = -180 + theSource.sourceRect = Qt.rect(-testMarginX, -testMarginY, 150, 200) } - - theSource.sourceRect = Qt.rect(-testMarginX, -testMarginY, parent.width + testMarginX*2, parent.height + testMarginY*2) } } diff --git a/tests/manual/qmlshadersplugintest/qml/qmlshadersplugintest/expected_results/Expected-TestItemMargins-3.png b/tests/manual/qmlshadersplugintest/qml/qmlshadersplugintest/expected_results/Expected-TestItemMargins-3.png Binary files differnew file mode 100644 index 0000000..a112818 --- /dev/null +++ b/tests/manual/qmlshadersplugintest/qml/qmlshadersplugintest/expected_results/Expected-TestItemMargins-3.png diff --git a/tests/manual/qmlshadersplugintest/qml/qmlshadersplugintest/expected_results/Expected-TestItemMarginsWithTextureSize-3.png b/tests/manual/qmlshadersplugintest/qml/qmlshadersplugintest/expected_results/Expected-TestItemMarginsWithTextureSize-3.png Binary files differnew file mode 100644 index 0000000..a486d4d --- /dev/null +++ b/tests/manual/qmlshadersplugintest/qml/qmlshadersplugintest/expected_results/Expected-TestItemMarginsWithTextureSize-3.png |