From 3c600f0b6ec9484e6042ed5a7c288dc96c88f471 Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Mon, 16 May 2011 16:57:41 +0200 Subject: [PATCH] Added documentation for ShaderEffectItem. Also removed unused signal. --- doc/src/images/declarative-shadereffectitem.png | Bin 0 -> 6557 bytes src/declarative/items/qsgshadereffectitem.cpp | 141 ++++++++++++++++++++++++ src/declarative/items/qsgshadereffectitem_p.h | 1 - 3 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 doc/src/images/declarative-shadereffectitem.png diff --git a/doc/src/images/declarative-shadereffectitem.png b/doc/src/images/declarative-shadereffectitem.png new file mode 100644 index 0000000000000000000000000000000000000000..2c8e8447e74aa6af2590d9e0930b5ceebb0b4316 GIT binary patch literal 6557 zcmXw8byQT{*S>@>NQs1WNi#^7l+qbxedvj6Lp?Q=dkmw@x3#7V5b(8 zkSJpGKU0&_p{_w&Qe)N~Xt8|KHF8)P9WoXjE&IKAYL02sm%}&4@`m2ad)Y2cRA`3d z*BdK`=SmzQt52%Sp2n)`>FK?Fo8P+zZ!jBq_s!NgSiS>JKXmdiSpK}UV8WiLEAFa` z)q2pH!BOsVe9&-FuD*ZcFEEvErFaUE%D1og*Z@&$E_P1*LPPFB=Bz8SMYvMO()o2KnSz}cgy>l8HP3S9)z`W3s_9HlmK!?JhP(RCHY}*~&AIBEP ztO^PIaFA#rTfHlKq%9hCYhxY~p25W%#Zqr#Nx>{E2qm``A2y~alaI5UIr<|!e`y+NazMp%&mOv?Lg^s&4ky zrUc^}W}1Bit4hF4eOJIB>vJ(Eb+8_?Rn*+v{No1<@*&ugLW#K6-lQ}!t3d6Aqr2GU zNa+x9Zn%L}Ps1M@6+W|WhUaS}>2`Zd{J-ppI%w^RV}GV3h&^=_9yaEId}Y<6K|3ur zdvh76=L(67dmcZPE}z;x{Wv!}t5~e8`wd!5*(I82OB3=^*S)XZ-lN9%qt()ItUO(i zwcf#qr0nxYt|Xt+2Fesz?J3HHhJ%tx$gP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+Q&G3Lcis}# zzalX@E(67cxH%$hV@JL-B<<`Iv1^xqWV6AF-VsXYUu|4PI9*zA?BWC<3r09}>$wsDzTEkp<|iES5ju5XhYo_Mk+y(T5|`kqYT@L=E~*b*CxLte&9!Np* zbAf}fL!$@5<4OD(enH{m3MQ)$`>Q;feD~)Yo|c!^b72Ca|B6;KazJtJPai#|V<_mM zR5b4fn^zEDxk-i=PwbvPPuD7+vhaF;p$`x$39x4h3yKL_i<8{djMhIVj_jt^po$eE<=#N`Xk#D-Kgi93;`(N*Kc@VRy z>RVnl25i+7I@@)>kOw~5ZbPUwph#-mKLeHAo5ATqe#jwENRYVGsi(U9+aJ|`)SF^| zCR3+|Rq}+bcX2@{%PqcUZB-A+NFX6k@EREcWHX|my= zl}_fad>X}V_oGAXQXFa7w3>ESn9lJtYBphO!?;HM9#sgm)Fc;D$mqQud%|eMtOlu2 z$g;4e<_HsrI~=!;z>zJypE^Y}UaP#HunMwyoE_X8`^YLa!9&zeajXu4J>7=5&wG^$ zEq~4DLC6ZS+OoI6G?=86*YKzSp9!CwktP`pDQZSLN*W|&PUO<{=Hh5_axyX!6Y|1| z9o-2rb2C^jJKvEjlO1IaJ2BK`6tnzi;_!I+>?%fG$@=ecR@;Vlll1brG5=ctH6<;@ JGI?0w{{g+g&(#0` literal 0 HcmV?d00001 diff --git a/src/declarative/items/qsgshadereffectitem.cpp b/src/declarative/items/qsgshadereffectitem.cpp index 40ec25c..44e075c 100644 --- a/src/declarative/items/qsgshadereffectitem.cpp +++ b/src/declarative/items/qsgshadereffectitem.cpp @@ -85,6 +85,99 @@ const char *qtTexCoordAttributeName() return qt_texcoord_attribute_name; } +/*! + \qmlclass ShaderEffectItem QSGShaderEffectItem + \since 5.0 + \ingroup qml-basic-visual-elements + \brief The ShaderEffectItem element applies custom shaders to a rectangle. + \inherits Item + + The ShaderEffectItem element applies a custom OpenGL + \l{vertexShader}{vertex} and \l{fragmentShader}{fragment} shader to a + rectangle. It allows you to write effects such as drop shadow, blur, + colorize and page curl directly in QML. + + There are two types of input to the \l vertexShader: + uniform variables and attributes. Some are predefined: + \list + \o uniform mat4 qt_ModelViewProjectionMatrix - combined transformation + matrix, the product of the matrices from the root item to this + ShaderEffectItem, and an orthogonal projection. + \o uniform float qt_Opacity - combined opacity, the product of the + opacities from the root item to this ShaderEffectItem. + \o attribute vec4 qt_Vertex - vertex position, the top-left vertex has + position (0, 0), the bottom-right (\l{Item::width}{width}, + \l{Item::height}{height}). + \o attribute vec2 qt_MultiTexCoord0 - texture coordinate, the top-left + coordinate is (0, 0), the bottom-right (1, 1). + \endlist + + In addition, any property that can be mapped to an OpenGL Shading Language + (GLSL) type is available as a uniform variable. The following list shows + how properties are mapped to GLSL uniform variables: + \list + \o bool, int, qreal -> bool, int, float - If the type in the shader is not + the same as in QML, the value is converted automatically. + \o QColor -> vec4 - When colors are passed to the shader, they are first + premultiplied. Thus Qt.rgba(0.2, 0.6, 1.0, 0.5) becomes + vec4(0.1, 0.3, 0.5, 0.5) in the shader, for example. + \o QRect, QRectF -> vec4 - Qt.rect(x, y, w, h) becomes vec4(x, y, w, h) in + the shader. + \o QPoint, QPointF, QSize, QSizeF -> vec2 + \o QVector3D -> vec3 + \o QTransform -> mat4 + \o \l Image, \l ShaderEffectSource -> sampler2D - Origin is in the top-left + corner, and the color values are premultiplied. + \endlist + + The output from the \l fragmentShader should be premultiplied. If + \l blending is enabled, source-over blending is used. However, additive + blending can be achieved by outputting zero in the alpha channel. + + \row + \o \image declarative-shadereffectitem.png + \o \qml + import QtQuick 2.0 + + Rectangle { + width: 200; height: 100 + Row { + Image { id: img; sourceSize { width: 100; height: 100 } source: "qt-logo.png" } + ShaderEffectItem { + width: 100; height: 100 + property variant src: img + vertexShader: " + uniform highp mat4 qt_ModelViewProjectionMatrix; + attribute highp vec4 qt_Vertex; + attribute highp vec2 qt_MultiTexCoord0; + varying highp vec2 coord; + void main() { + coord = qt_MultiTexCoord0; + gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex; + }" + fragmentShader: " + varying highp vec2 coord; + uniform sampler2D src; + uniform lowp float qt_Opacity; + void main() { + lowp vec4 tex = texture2D(src, coord); + gl_FragColor = vec4(vec3(dot(tex.rgb, vec3(0.344, 0.5, 0.156))), tex.a) * qt_Opacity; + }" + } + } + } + \endqml + \endrow + + By default, the ShaderEffectItem consists of four vertices, one for each + corner. For non-linear vertex transformations, like page curl, you can + specify a fine grid of vertices by assigning a \l GridMesh to the \l mesh + property. + + \note Scene Graph textures have origin in the top-left corner rather than + bottom-left which is common in OpenGL. +*/ + QSGShaderEffectItem::QSGShaderEffectItem(QSGItem *parent) : QSGItem(parent) , m_mesh(0) @@ -109,6 +202,14 @@ void QSGShaderEffectItem::componentComplete() QSGItem::componentComplete(); } +/*! + \qmlproperty string ShaderEffectItem::fragmentShader + + This property holds the fragment shader's GLSL source code. + The default shader passes the texture coordinate along to the fragment + shader as "varying highp vec2 qt_TexCoord0". +*/ + void QSGShaderEffectItem::setFragmentShader(const QByteArray &code) { if (m_source.fragmentCode.constData() == code.constData()) @@ -121,6 +222,15 @@ void QSGShaderEffectItem::setFragmentShader(const QByteArray &code) emit fragmentShaderChanged(); } +/*! + \qmlproperty string ShaderEffectItem::vertexShader + + This property holds the vertex shader's GLSL source code. + The default shader expects the texture coordinate to be passed from the + vertex shader as "varying highp vec2 qt_TexCoord0", and it samples from a + sampler2D named "source". +*/ + void QSGShaderEffectItem::setVertexShader(const QByteArray &code) { if (m_source.vertexCode.constData() == code.constData()) @@ -133,6 +243,15 @@ void QSGShaderEffectItem::setVertexShader(const QByteArray &code) emit vertexShaderChanged(); } +/*! + \qmlproperty bool ShaderEffectItem::blending + + If this property is true, the output from the \l fragmentShader is blended + with the background using source-over blend mode. If false, the background + is disregarded. Blending decreases the performance, so you should set this + property to false when blending is not needed. The default value is true. +*/ + void QSGShaderEffectItem::setBlending(bool enable) { if (blending() == enable) @@ -144,6 +263,14 @@ void QSGShaderEffectItem::setBlending(bool enable) emit blendingChanged(); } +/*! + \qmlproperty object ShaderEffectItem::mesh + + This property holds the mesh definition. If not set, a simple mesh with one + vertex in each corner is used. Assign a \l GridMesh to this property to get + a higher resolution grid. +*/ + void QSGShaderEffectItem::setMesh(QSGShaderEffectMesh *mesh) { if (mesh == m_mesh) @@ -158,6 +285,20 @@ void QSGShaderEffectItem::setMesh(QSGShaderEffectMesh *mesh) emit meshChanged(); } +/*! + \qmlproperty enumeration ShaderEffectItem::cullMode + + This property defines which sides of the element should be visible. + + \list + \o ShaderEffectItem.NoCulling - Both sides are visible + \o ShaderEffectItem.BackFaceCulling - only front side is visible + \o ShaderEffectItem.FrontFaceCulling - only back side is visible + \endlist + + The default is NoCulling. +*/ + void QSGShaderEffectItem::setCullMode(CullMode face) { if (face == m_cullMode) diff --git a/src/declarative/items/qsgshadereffectitem_p.h b/src/declarative/items/qsgshadereffectitem_p.h index 84f8049..4017d35 100644 --- a/src/declarative/items/qsgshadereffectitem_p.h +++ b/src/declarative/items/qsgshadereffectitem_p.h @@ -106,7 +106,6 @@ Q_SIGNALS: void fragmentShaderChanged(); void vertexShaderChanged(); void blendingChanged(); - void marginsChanged(); void meshChanged(); void cullModeChanged(); -- 2.7.4