Make the shadereffect respect the flip property
authorJørgen Lind <jorgen.lind@nokia.com>
Fri, 6 May 2011 10:19:18 +0000 (12:19 +0200)
committerJørgen Lind <jorgen.lind@nokia.com>
Fri, 6 May 2011 10:19:18 +0000 (12:19 +0200)
examples/qml-compositor/qml/QmlCompositor/ShaderEffect.qml
src/qt-compositor/compositor_api/waylandsurfaceitem.cpp
src/qt-compositor/compositor_api/waylandsurfaceitem.h

index 09b4e37..b1412f6 100644 (file)
@@ -45,6 +45,34 @@ ShaderEffectItem {
     property color color: "#ffffff"
     property real blend;
 
+    onSourceChanged: {
+        if (source != null) {
+            source.visible = false;
+            vertexShader = source.isYInverted() ? vShaderInvertedY : vShader;
+        }
+    }
+
+    property string vShader: "
+    uniform highp mat4 qt_ModelViewProjectionMatrix;
+    attribute highp vec4 qt_Vertex;
+    attribute highp vec2 qt_MultiTexCoord0;
+    varying highp vec2 qt_TexCoord0;
+    void main() {
+        qt_TexCoord0 = qt_MultiTexCoord0;
+        gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex;
+    }
+    "
+    property string vShaderInvertedY: "
+    uniform highp mat4 qt_ModelViewProjectionMatrix;
+    attribute highp vec4 qt_Vertex;
+    attribute highp vec2 qt_MultiTexCoord0;
+    varying highp vec2 qt_TexCoord0;
+    void main() {
+        qt_TexCoord0 = vec2(0, 1) + qt_MultiTexCoord0 * vec2(1, -1);
+        gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex;
+    }
+    "
+
     fragmentShader: "
     uniform sampler2D source;
     uniform float qt_Opacity;
index b10d219..597bff0 100644 (file)
@@ -55,13 +55,10 @@ void WaylandSurfaceItem::surfaceDamaged(const QRect &)
         delete m_texture;
 
     if (m_surface->type() == WaylandSurface::Texture) {
-        //qDebug() << "createTextureFromId" << m_surface->texture() << m_surface->geometry().size();
         m_texture = canvas()->sceneGraphEngine()->createTextureFromId(m_surface->texture(),
                                                                       m_surface->geometry().size());
-        m_texture_needs_flipping = true;
     } else {
         m_texture = canvas()->sceneGraphEngine()->createTextureFromImage(m_surface->image());
-        m_texture_needs_flipping = false;
     }
 
     emit textureChanged();
@@ -71,7 +68,6 @@ WaylandSurfaceItem::WaylandSurfaceItem(QSGItem *parent)
     : QSGItem(parent)
     , m_surface(0)
     , m_texture(0)
-    , m_texture_needs_flipping(false)
 {
 }
 
@@ -79,7 +75,6 @@ WaylandSurfaceItem::WaylandSurfaceItem(WaylandSurface *surface, QSGItem *parent)
     : QSGItem(parent)
     , m_surface(0)
     , m_texture(0)
-    , m_texture_needs_flipping(false)
 {
     init(surface);
 }
@@ -193,11 +188,6 @@ QSGNode *WaylandSurfaceItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeDa
     }
     node->setTexture(m_texture);
 
-    if (m_texture_needs_flipping)
-        node->setRect(0, height(), width(), -height());
-    else
-        node->setRect(0, 0, width(), height());
-
     node->setFiltering(smooth() ? QSGTexture::Linear : QSGTexture::Nearest);
 
     return node;
index acf0321..9f4ae16 100644 (file)
@@ -96,8 +96,6 @@ private:
 
     WaylandSurface *m_surface;
     QSGTexture *m_texture;
-
-    bool m_texture_needs_flipping;
 };
 
 #endif