bigImage.visible = true;
}
}
- ShaderEffectItem{
+ ShaderEffect{
id: noiseIn
anchors.fill: parent
property real t: 0
uniform highp float maxWidth;
uniform highp float maxHeight;
- uniform highp mat4 qt_ModelViewProjectionMatrix;
+ uniform highp mat4 qt_Matrix;
uniform highp float timestamp;
uniform lowp float qt_Opacity;
+ vVec.xy * t * vData.y // apply speed vector..
+ 0.5 * vVec.zw * pow(t * vData.y, 2.);
- gl_Position = qt_ModelViewProjectionMatrix * vec4(pos.x, pos.y, 0, 1);
+ gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1);
highp float fadeIn = min(t * 10., 1.);
highp float fadeOut = 1. - max(0., min((t - 0.75) * 4., 1.));
uniform highp float maxWidth;
uniform highp float maxHeight;
- uniform highp mat4 qt_ModelViewProjectionMatrix;
+ uniform highp mat4 qt_Matrix;
uniform highp float timestamp;
uniform lowp float qt_Opacity;
+ vVec.xy * t * vData.y // apply speed vector..
+ 0.5 * vVec.zw * pow(t * vData.y, 2.);
- gl_Position = qt_ModelViewProjectionMatrix * vec4(pos.x, pos.y, 0, 1);
+ gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1);
highp float fadeIn = min(t * 10., 1.);
highp float fadeOut = 1. - max(0., min((t - 0.75) * 4., 1.));
attribute highp vec4 vVec; // x,y = constant speed, z,w = acceleration
attribute highp float r;
- uniform highp mat4 qt_ModelViewProjectionMatrix;
+ uniform highp mat4 qt_Matrix;
uniform highp float timestamp;
uniform lowp float qt_Opacity;
+ vVec.xy * t * vData.y // apply speed vector..
+ 0.5 * vVec.zw * pow(t * vData.y, 2.);
- gl_Position = qt_ModelViewProjectionMatrix * vec4(pos.x, pos.y, 0, 1);
+ gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1);
highp float fadeIn = min(t * 10., 1.);
highp float fadeOut = 1. - max(0., min((t - 0.75) * 4., 1.));
property variant source: theSource
property variant blurred: ShaderEffectSource {
smooth: true
- sourceItem: ShaderEffectItem {
+ sourceItem: ShaderEffect {
width: theItem.width
height: theItem.height
property variant delta: Qt.size(0.0, 1.0 / height)
property variant source: ShaderEffectSource {
smooth: true
- sourceItem: ShaderEffectItem {
+ sourceItem: ShaderEffect {
width: theItem.width
height: theItem.height
property variant delta: Qt.size(1.0 / width, 0.0)
attribute highp vec4 vVec; // x,y = constant speed, z,w = acceleration
attribute highp float r;
- uniform highp mat4 qt_ModelViewProjectionMatrix;
+ uniform highp mat4 qt_Matrix;
uniform highp float timestamp;
uniform lowp float qt_Opacity;
+ vVec.xy * t * vData.y // apply speed vector..
+ 0.5 * vVec.zw * pow(t * vData.y, 2.);
- gl_Position = qt_ModelViewProjectionMatrix * vec4(pos.x, pos.y, 0, 1);
+ gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1);
highp float fadeIn = min(t * 20., 1.);
highp float fadeOut = 1. - max(0., min((t - 0.75) * 4., 1.));
}
}
}
- ShaderEffectItem {
+ ShaderEffect {
width: 180
height: 180
property variant source: theSource
height: 40
}
}
- ShaderEffectItem {
+ ShaderEffect {
width: 180
height: 180
property variant source: theSource
property variant shadow: ShaderEffectSource {
smooth: true
- sourceItem: ShaderEffectItem {
+ sourceItem: ShaderEffect {
width: theItem.width
height: theItem.height
property variant delta: Qt.size(0.0, 1.0 / height)
property variant source: ShaderEffectSource {
smooth: true
- sourceItem: ShaderEffectItem {
+ sourceItem: ShaderEffect {
width: theItem.width
height: theItem.height
property variant delta: Qt.size(1.0 / width, 0.0)
height: 40
}
}
- ShaderEffectItem {
+ ShaderEffect {
width: 180
height: 180
property variant source: theSource
gl_FragColor.w = clamp(dot(sqrt(gx * gx + gy * gy), vec4(1.)), 0., 1.) * qt_Opacity;
}"
}
- ShaderEffectItem {
+ ShaderEffect {
width: 180
height: 180
property variant source: theSource
height: 40
}
}
- ShaderEffectItem {
+ ShaderEffect {
width: 180
height: 180
- mesh: GridMesh { resolution: Qt.size(10, 10) }
+ mesh: Qt.size(10, 10)
property variant source: theSource
property real bend: 0
property real minimize: 0
PauseAnimation { duration: 1300 }
}
vertexShader: "
- uniform highp mat4 qt_ModelViewProjectionMatrix;
+ uniform highp mat4 qt_Matrix;
uniform highp float bend;
uniform highp float minimize;
uniform highp float side;
highp float t = pos.y / height;
t = (3. - 2. * t) * t * t;
pos.x = mix(qt_Vertex.x, side * width, t * bend);
- gl_Position = qt_ModelViewProjectionMatrix * pos;
+ gl_Position = qt_Matrix * pos;
}"
Slider {
id: genieSlider
$$PWD/qsgitemview.cpp
SOURCES += \
- $$PWD/qsgshadereffectitem.cpp \
+ $$PWD/qsgshadereffect.cpp \
$$PWD/qsgshadereffectmesh.cpp \
$$PWD/qsgshadereffectnode.cpp \
$$PWD/qsgshadereffectsource.cpp \
HEADERS += \
- $$PWD/qsgshadereffectitem_p.h \
+ $$PWD/qsgshadereffect_p.h \
$$PWD/qsgshadereffectmesh_p.h \
$$PWD/qsgshadereffectnode_p.h \
$$PWD/qsgshadereffectsource_p.h \
#include "qsgtranslate_p.h"
#include "qsgstateoperations_p.h"
#include "qsganimation_p.h"
-#include <private/qsgshadereffectitem_p.h>
+#include <private/qsgshadereffect_p.h>
#include <private/qsgshadereffectsource_p.h>
//#include "private/qsgpincharea_p.h"
#include "qsgcanvasitem_p.h"
qmlRegisterType<QSGPinch>(uri,major,minor,"Pinch");
qmlRegisterType<QSGPinchEvent>();
- qmlRegisterType<QSGShaderEffectItem>("QtQuick", 2, 0, "ShaderEffectItem");
+ qmlRegisterType<QSGShaderEffectItem>("QtQuick", 2, 0, "ShaderEffectItem"); // TODO: Remove after grace period.
+ qmlRegisterType<QSGShaderEffect>("QtQuick", 2, 0, "ShaderEffect");
qmlRegisterType<QSGShaderEffectSource>("QtQuick", 2, 0, "ShaderEffectSource");
- qmlRegisterUncreatableType<QSGShaderEffectMesh>("QtQuick", 2, 0, "ShaderEffectMesh", QSGShaderEffectMesh::tr("Cannot create instance of abstract class ShaderEffectMesh."));
- qmlRegisterType<QSGGridMesh>("QtQuick", 2, 0, "GridMesh");
+ qmlRegisterUncreatableType<QSGShaderEffectMesh>("QtQuick", 2, 0, "ShaderEffectMesh", QSGShaderEffectMesh::tr("Cannot create instance of abstract class ShaderEffectMesh.")); // TODO: Remove after grace period.
+ qmlRegisterType<QSGGridMesh>("QtQuick", 2, 0, "GridMesh"); // TODO: Remove after grace period.
qmlRegisterUncreatableType<QSGPaintedItem>("QtQuick", 2, 0, "PaintedItem", QSGPaintedItem::tr("Cannot create instance of abstract class PaintedItem"));
**
****************************************************************************/
-#include <private/qsgshadereffectitem_p.h>
+#include <private/qsgshadereffect_p.h>
#include <private/qsgshadereffectnode_p.h>
#include "qsgmaterial.h"
QT_BEGIN_NAMESPACE
static const char qt_default_vertex_code[] =
- "uniform highp mat4 qt_ModelViewProjectionMatrix; \n"
+ "uniform highp mat4 qt_Matrix; \n"
"attribute highp vec4 qt_Vertex; \n"
"attribute highp vec2 qt_MultiTexCoord0; \n"
"varying highp vec2 qt_TexCoord0; \n"
"void main() { \n"
" qt_TexCoord0 = qt_MultiTexCoord0; \n"
- " gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex; \n"
+ " gl_Position = qt_Matrix * qt_Vertex; \n"
"}";
static const char qt_default_fragment_code[] =
return qt_texcoord_attribute_name;
}
+// TODO: Remove after grace period.
+QSGShaderEffectItem::QSGShaderEffectItem(QSGItem *parent)
+ : QSGShaderEffect(parent)
+{
+ qWarning("ShaderEffectItem has been deprecated. Use ShaderEffect instead.");
+}
+
+
/*!
- \qmlclass ShaderEffectItem QSGShaderEffectItem
+ \qmlclass ShaderEffect QSGShaderEffect
\since 5.0
\ingroup qml-basic-visual-elements
- \brief The ShaderEffectItem element applies custom shaders to a rectangle.
+ \brief The ShaderEffect element applies custom shaders to a rectangle.
\inherits Item
- The ShaderEffectItem element applies a custom OpenGL
+ The ShaderEffect 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
+ \o uniform mat4 qt_Matrix - combined transformation
matrix, the product of the matrices from the root item to this
- ShaderEffectItem, and an orthogonal projection.
+ ShaderEffect, and an orthogonal projection.
\o uniform float qt_Opacity - combined opacity, the product of the
- opacities from the root item to this ShaderEffectItem.
+ opacities from the root item to this ShaderEffect.
\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}).
width: 200; height: 100
Row {
Image { id: img; sourceSize { width: 100; height: 100 } source: "qt-logo.png" }
- ShaderEffectItem {
+ ShaderEffect {
width: 100; height: 100
property variant src: img
vertexShader: "
- uniform highp mat4 qt_ModelViewProjectionMatrix;
+ uniform highp mat4 qt_Matrix;
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;
+ gl_Position = qt_Matrix * qt_Vertex;
}"
fragmentShader: "
varying highp vec2 coord;
\endqml
\endrow
- By default, the ShaderEffectItem consists of four vertices, one for each
+ By default, the ShaderEffect 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.
+ specify a fine grid of vertices by specifying a \l mesh resolution.
\note Scene Graph textures have origin in the top-left corner rather than
bottom-left which is common in OpenGL.
*/
-QSGShaderEffectItem::QSGShaderEffectItem(QSGItem *parent)
+QSGShaderEffect::QSGShaderEffect(QSGItem *parent)
: QSGItem(parent)
- , m_mesh(0)
+ , m_meshResolution(1, 1)
+ , m_deprecatedMesh(0)
, m_cullMode(NoCulling)
, m_blending(true)
, m_dirtyData(true)
setFlag(QSGItem::ItemHasContents);
}
-QSGShaderEffectItem::~QSGShaderEffectItem()
+QSGShaderEffect::~QSGShaderEffect()
{
reset();
}
-void QSGShaderEffectItem::componentComplete()
+void QSGShaderEffect::componentComplete()
{
updateProperties();
QSGItem::componentComplete();
}
/*!
- \qmlproperty string ShaderEffectItem::fragmentShader
+ \qmlproperty string ShaderEffect::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)
+void QSGShaderEffect::setFragmentShader(const QByteArray &code)
{
if (m_source.fragmentCode.constData() == code.constData())
return;
}
/*!
- \qmlproperty string ShaderEffectItem::vertexShader
+ \qmlproperty string ShaderEffect::vertexShader
This property holds the vertex shader's GLSL source code.
The default shader expects the texture coordinate to be passed from the
sampler2D named "source".
*/
-void QSGShaderEffectItem::setVertexShader(const QByteArray &code)
+void QSGShaderEffect::setVertexShader(const QByteArray &code)
{
if (m_source.vertexCode.constData() == code.constData())
return;
}
/*!
- \qmlproperty bool ShaderEffectItem::blending
+ \qmlproperty bool ShaderEffect::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
property to false when blending is not needed. The default value is true.
*/
-void QSGShaderEffectItem::setBlending(bool enable)
+void QSGShaderEffect::setBlending(bool enable)
{
if (blending() == enable)
return;
}
/*!
- \qmlproperty object ShaderEffectItem::mesh
+ \qmlproperty size ShaderEffect::mesh
+
+ This property holds the mesh resolution. The default resolution is 1x1
+ which is the minimum and corresponds to a mesh with four vertices.
+ For non-linear vertex transformations, you probably want to set the
+ resolution higher.
- 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.
+ \row
+ \o \image declarative-gridmesh.png
+ \o \qml
+ import QtQuick 2.0
+
+ ShaderEffect {
+ width: 200
+ height: 200
+ mesh: Qt.size(20, 20)
+ property variant source: Image {
+ source: "qt-logo.png"
+ sourceSize { width: 200; height: 200 }
+ smooth: true
+ }
+ vertexShader: "
+ uniform highp mat4 qt_Matrix;
+ attribute highp vec4 qt_Vertex;
+ attribute highp vec2 qt_MultiTexCoord0;
+ varying highp vec2 qt_TexCoord0;
+ uniform highp float width;
+ void main() {
+ highp vec4 pos = qt_Vertex;
+ highp float d = .5 * smoothstep(0., 1., qt_MultiTexCoord0.y);
+ pos.x = width * mix(d, 1.0 - d, qt_MultiTexCoord0.x);
+ gl_Position = qt_Matrix * pos;
+ qt_TexCoord0 = qt_MultiTexCoord0;
+ }"
+ }
+ \endqml
+ \endrow
*/
-void QSGShaderEffectItem::setMesh(QSGShaderEffectMesh *mesh)
+QVariant QSGShaderEffect::mesh() const
+{
+ return m_deprecatedMesh ? qVariantFromValue(static_cast<QObject *>(m_deprecatedMesh))
+ : qVariantFromValue(m_meshResolution);
+}
+
+void QSGShaderEffect::setMesh(const QVariant &mesh)
{
- if (mesh == m_mesh)
+ // TODO: Replace QVariant with QSize after grace period.
+ QSGShaderEffectMesh *newMesh = qobject_cast<QSGShaderEffectMesh *>(qVariantValue<QObject *>(mesh));
+ if (newMesh && newMesh == m_deprecatedMesh)
return;
- if (m_mesh)
- disconnect(m_mesh, SIGNAL(geometryChanged()), this, 0);
- m_mesh = mesh;
- if (m_mesh)
- connect(m_mesh, SIGNAL(geometryChanged()), this, SLOT(updateGeometry()));
+ if (m_deprecatedMesh)
+ disconnect(m_deprecatedMesh, SIGNAL(geometryChanged()), this, 0);
+ m_deprecatedMesh = newMesh;
+ if (m_deprecatedMesh) {
+ qWarning("ShaderEffect: Setting the mesh to something other than a size is deprecated.");
+ connect(m_deprecatedMesh, SIGNAL(geometryChanged()), this, SLOT(updateGeometry()));
+ } else {
+ if (qVariantCanConvert<QSize>(mesh)) {
+ m_meshResolution = mesh.toSize();
+ } else {
+ QList<QByteArray> res = mesh.toByteArray().split('x');
+ bool ok = res.size() == 2;
+ if (ok) {
+ int w = res.at(0).toInt(&ok);
+ if (ok) {
+ int h = res.at(1).toInt(&ok);
+ if (ok)
+ m_meshResolution = QSize(w, h);
+ }
+ }
+ if (!ok)
+ qWarning("ShaderEffect: mesh resolution must be a size.");
+ }
+ m_defaultMesh.setResolution(m_meshResolution);
+ }
+
m_dirtyMesh = true;
update();
emit meshChanged();
}
/*!
- \qmlproperty enumeration ShaderEffectItem::cullMode
+ \qmlproperty enumeration ShaderEffect::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
+ \o ShaderEffect.NoCulling - Both sides are visible
+ \o ShaderEffect.BackFaceCulling - only front side is visible
+ \o ShaderEffect.FrontFaceCulling - only back side is visible
\endlist
The default is NoCulling.
*/
-void QSGShaderEffectItem::setCullMode(CullMode face)
+void QSGShaderEffect::setCullMode(CullMode face)
{
if (face == m_cullMode)
return;
emit cullModeChanged();
}
-void QSGShaderEffectItem::changeSource(int index)
+void QSGShaderEffect::changeSource(int index)
{
Q_ASSERT(index >= 0 && index < m_sources.size());
QVariant v = property(m_sources.at(index).name.constData());
setSource(v, index);
}
-void QSGShaderEffectItem::updateData()
+void QSGShaderEffect::updateData()
{
m_dirtyData = true;
update();
}
-void QSGShaderEffectItem::updateGeometry()
+void QSGShaderEffect::updateGeometry()
{
m_dirtyGeometry = true;
update();
}
-void QSGShaderEffectItem::setSource(const QVariant &var, int index)
+void QSGShaderEffect::setSource(const QVariant &var, int index)
{
Q_ASSERT(index >= 0 && index < m_sources.size());
}
}
-void QSGShaderEffectItem::disconnectPropertySignals()
+void QSGShaderEffect::disconnectPropertySignals()
{
disconnect(this, 0, this, SLOT(updateData()));
for (int i = 0; i < m_sources.size(); ++i) {
}
}
-void QSGShaderEffectItem::connectPropertySignals()
+void QSGShaderEffect::connectPropertySignals()
{
QSet<QByteArray>::const_iterator it;
for (it = m_source.uniformNames.begin(); it != m_source.uniformNames.end(); ++it) {
if (pi >= 0) {
QMetaProperty mp = metaObject()->property(pi);
if (!mp.hasNotifySignal())
- qWarning("QSGShaderEffectItem: property '%s' does not have notification method!", it->constData());
+ qWarning("QSGShaderEffect: property '%s' does not have notification method!", it->constData());
QByteArray signalName("2");
signalName.append(mp.notifySignal().signature());
connect(this, signalName, this, SLOT(updateData()));
} else {
- qWarning("QSGShaderEffectItem: '%s' does not have a matching property!", it->constData());
+ qWarning("QSGShaderEffect: '%s' does not have a matching property!", it->constData());
}
}
for (int i = 0; i < m_sources.size(); ++i) {
source.mapper->setMapping(this, i);
connect(source.mapper, SIGNAL(mapped(int)), this, SLOT(changeSource(int)));
} else {
- qWarning("QSGShaderEffectItem: '%s' does not have a matching source!", source.name.constData());
+ qWarning("QSGShaderEffect: '%s' does not have a matching source!", source.name.constData());
}
}
}
-void QSGShaderEffectItem::reset()
+void QSGShaderEffect::reset()
{
disconnectPropertySignals();
m_dirtyMesh = true;
}
-void QSGShaderEffectItem::updateProperties()
+void QSGShaderEffect::updateProperties()
{
QByteArray vertexCode = m_source.vertexCode;
QByteArray fragmentCode = m_source.fragmentCode;
lookThroughShaderCode(vertexCode);
lookThroughShaderCode(fragmentCode);
- if (!m_mesh && !m_source.attributeNames.contains(qt_position_attribute_name))
- qWarning("QSGShaderEffectItem: Missing reference to \'%s\'.", qt_position_attribute_name);
- if (!m_mesh && !m_source.attributeNames.contains(qt_texcoord_attribute_name))
- qWarning("QSGShaderEffectItem: Missing reference to \'%s\'.", qt_texcoord_attribute_name);
+ // TODO: Remove !m_deprecatedMesh check after grace period.
+ if (!m_deprecatedMesh && !m_source.attributeNames.contains(qt_position_attribute_name))
+ qWarning("QSGShaderEffect: Missing reference to \'%s\'.", qt_position_attribute_name);
+ if (!m_deprecatedMesh && !m_source.attributeNames.contains(qt_texcoord_attribute_name))
+ qWarning("QSGShaderEffect: Missing reference to \'%s\'.", qt_texcoord_attribute_name);
if (!m_source.respectsMatrix)
- qWarning("QSGShaderEffectItem: Missing reference to \'qt_ModelViewProjectionMatrix\'.");
+ qWarning("QSGShaderEffect: Missing reference to \'qt_Matrix\'.");
if (!m_source.respectsOpacity)
- qWarning("QSGShaderEffectItem: Missing reference to \'qt_Opacity\'.");
+ qWarning("QSGShaderEffect: Missing reference to \'qt_Opacity\'.");
for (int i = 0; i < m_sources.size(); ++i) {
QVariant v = property(m_sources.at(i).name);
connectPropertySignals();
}
-void QSGShaderEffectItem::lookThroughShaderCode(const QByteArray &code)
+void QSGShaderEffect::lookThroughShaderCode(const QByteArray &code)
{
// Regexp for matching attributes and uniforms.
// In human readable form: attribute|uniform [lowp|mediump|highp] <type> <name>
} else {
Q_ASSERT(decl == "uniform");
- if (name == "qt_ModelViewProjectionMatrix") {
+ if (name == "qt_Matrix") {
+ m_source.respectsMatrix = true;
+ } else if (name == "qt_ModelViewProjectionMatrix") {
+ // TODO: Remove after grace period.
+ qWarning("ShaderEffect: qt_ModelViewProjectionMatrix is deprecated. Use qt_Matrix instead.");
m_source.respectsMatrix = true;
} else if (name == "qt_Opacity") {
m_source.respectsOpacity = true;
}
}
-void QSGShaderEffectItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
+void QSGShaderEffect::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
m_dirtyGeometry = true;
QSGItem::geometryChanged(newGeometry, oldGeometry);
}
-QSGNode *QSGShaderEffectItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
+QSGNode *QSGShaderEffect::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
{
QSGShaderEffectNode *node = static_cast<QSGShaderEffectNode *>(oldNode);
node->setFlag(QSGNode::OwnsGeometry, false);
QSGGeometry *geometry = node->geometry();
QRectF rect(0, 0, width(), height());
- QSGShaderEffectMesh *mesh = m_mesh ? m_mesh : &m_defaultMesh;
+ QSGShaderEffectMesh *mesh = m_deprecatedMesh ? m_deprecatedMesh : &m_defaultMesh;
geometry = mesh->updateGeometry(geometry, m_source.attributeNames, rect);
if (!geometry) {
class QSignalMapper;
class QSGCustomMaterialShader;
-class QSGShaderEffectItem : public QSGItem
+class QSGShaderEffect : public QSGItem
{
Q_OBJECT
Q_PROPERTY(QByteArray fragmentShader READ fragmentShader WRITE setFragmentShader NOTIFY fragmentShaderChanged)
Q_PROPERTY(QByteArray vertexShader READ vertexShader WRITE setVertexShader NOTIFY vertexShaderChanged)
Q_PROPERTY(bool blending READ blending WRITE setBlending NOTIFY blendingChanged)
- Q_PROPERTY(QSGShaderEffectMesh *mesh READ mesh WRITE setMesh NOTIFY meshChanged)
+ Q_PROPERTY(QVariant mesh READ mesh WRITE setMesh NOTIFY meshChanged)
Q_PROPERTY(CullMode culling READ cullMode WRITE setCullMode NOTIFY cullModeChanged)
Q_ENUMS(CullMode)
FrontFaceCulling = QSGShaderEffectMaterial::FrontFaceCulling
};
- QSGShaderEffectItem(QSGItem *parent = 0);
- ~QSGShaderEffectItem();
+ QSGShaderEffect(QSGItem *parent = 0);
+ ~QSGShaderEffect();
virtual void componentComplete();
bool blending() const { return m_blending; }
void setBlending(bool enable);
- QSGShaderEffectMesh *mesh() const { return m_mesh; }
- void setMesh(QSGShaderEffectMesh *mesh);
+ QVariant mesh() const;
+ void setMesh(const QVariant &mesh);
CullMode cullMode() const { return m_cullMode; }
void setCullMode(CullMode face);
void lookThroughShaderCode(const QByteArray &code);
QSGShaderEffectProgram m_source;
- QSGShaderEffectMesh *m_mesh;
+ QSize m_meshResolution;
+ QSGShaderEffectMesh *m_deprecatedMesh; // TODO: Remove after grace period.
QSGGridMesh m_defaultMesh;
CullMode m_cullMode;
uint m_dirtyGeometry : 1;
};
+// TODO: Remove after grace period.
+class QSGShaderEffectItem : public QSGShaderEffect
+{
+public:
+ QSGShaderEffectItem(QSGItem *parent = 0);
+};
+
QT_END_NAMESPACE
QT_END_HEADER
#include "qsgshadereffectmesh_p.h"
#include "qsggeometry.h"
-#include "qsgshadereffectitem_p.h"
+#include "qsgshadereffect_p.h"
QT_BEGIN_NAMESPACE
}
/*!
- \qmlclass GridMesh QSGGridMesh
+ \class QSGGridMesh
\since 5.0
- \ingroup qml-utility-elements
- \brief GridMesh defines a mesh to be used with \l ShaderEffectItem.
+ \brief GridMesh defines a mesh with vertices arranged in a grid.
GridMesh defines a rectangular mesh consisting of vertices arranged in an
- evenly spaced grid. It can be assigned to the \l ShaderEffectItem's mesh
- property. The grid resolution is specified with the \l resolution property.
-
- \row
- \o \image declarative-gridmesh.png
- \o \qml
- import QtQuick 2.0
-
- ShaderEffectItem {
- width: 200
- height: 200
- mesh: GridMesh { resolution: Qt.size(20, 20) }
- property variant source: Image {
- source: "qt-logo.png"
- sourceSize {width: 200; height: 200 }
- smooth: true
- }
- vertexShader: "
- uniform highp mat4 qt_ModelViewProjectionMatrix;
- attribute highp vec4 qt_Vertex;
- attribute highp vec2 qt_MultiTexCoord0;
- varying highp vec2 qt_TexCoord0;
- uniform highp float width;
- void main() {
- highp vec4 pos = qt_Vertex;
- highp float d = .5 * smoothstep(0., 1., qt_MultiTexCoord0.y);
- pos.x = width * mix(d, 1.0 - d, qt_MultiTexCoord0.x);
- gl_Position = qt_ModelViewProjectionMatrix * pos;
- qt_TexCoord0 = qt_MultiTexCoord0;
- }"
- }
- \endqml
- \endrow
-
+ evenly spaced grid. It is used to generate \l{QSGGeometry}{geometry}.
+ The grid resolution is specified with the \l resolution property.
*/
QSGGridMesh::QSGGridMesh(QObject *parent)
}
/*!
- \qmlproperty size GridMesh::resolution
+ \property QSGGridMesh::resolution
This property holds the grid resolution. The resolution's width and height
specify the number of cells or spacings between vertices horizontally and
void QSGCustomMaterialShader::initialize()
{
m_opacityLoc = program()->uniformLocation("qt_Opacity");
- m_matrixLoc = program()->uniformLocation("qt_ModelViewProjectionMatrix");
+ m_matrixLoc = program()->uniformLocation("qt_Matrix");
+ // TODO: Remove after grace period.
+ if (m_matrixLoc == -1)
+ m_matrixLoc = program()->uniformLocation("qt_ModelViewProjectionMatrix");
}
const char *QSGCustomMaterialShader::vertexShader() const
void updateTextures() const;
protected:
- friend class QSGShaderEffectItem;
+ friend class QSGShaderEffect;
friend class QSGCustomMaterialShader;
// The type pointer needs to be unique. It is not safe to let the type object be part of the
ShaderEffectSource can be used as:
\list
- \o a texture source in a \l ShaderEffectItem.
+ \o a texture source in a \l ShaderEffect.
This allows you to apply custom shader effects to any QML element.
\o a cache for a complex element.
The complex element can be rendered once into the texture, which can
This property defines the OpenGL wrap modes associated with the texture.
Modifying this property makes most sense when the element is used as a
- source texture of a \l ShaderEffectItem.
+ source texture of a \l ShaderEffect.
\list
\o ShaderEffectSource.ClampToEdge - GL_CLAMP_TO_EDGE both horizontally and vertically
This property defines the internal OpenGL format of the texture.
Modifying this property makes most sense when the element is used as a
- source texture of a \l ShaderEffectItem. Depending on the OpenGL
+ source texture of a \l ShaderEffect. Depending on the OpenGL
implementation, this property might allow you to save some texture memory.
\list
"attribute highp vec2 vTex; \n"
"attribute highp vec4 vData; // x = time, y = lifeSpan, z = size, w = endSize \n"
"attribute highp vec4 vVec; // x,y = constant speed, z,w = acceleration \n"
- "uniform highp mat4 qt_ModelViewProjectionMatrix; \n"
+ "uniform highp mat4 qt_Matrix; \n"
"uniform highp float timestamp; \n"
"varying highp vec2 fTex; \n"
"void main() { \n"
" - currentSize / 2. + currentSize * vTex // adjust size \n"
" + vVec.xy * t * vData.y // apply speed vector.. \n"
" + 0.5 * vVec.zw * pow(t * vData.y, 2.); \n"
- " gl_Position = qt_ModelViewProjectionMatrix * vec4(pos.x, pos.y, 0, 1); \n"
+ " gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1); \n"
"}";
static const char qt_particles_default_fragment_code[] =//TODO: Default frag requires source?
source.item = qobject_cast<QSGItem *>(obj);
- // TODO: Copy better solution in QSGShaderEffectItem when they find it.
+ // TODO: Copy better solution in QSGShaderEffect when they find it.
// 'source.item' needs a canvas to get a scenegraph node.
// The easiest way to make sure it gets a canvas is to
// make it a part of the same item tree as 'this'.
if (pi >= 0) {
QMetaProperty mp = metaObject()->property(pi);
if (!mp.hasNotifySignal())
- qWarning("QSGShaderEffectItem: property '%s' does not have notification method!", it->constData());
+ qWarning("QSGCustomParticle: property '%s' does not have notification method!", it->constData());
QByteArray signalName("2");
signalName.append(mp.notifySignal().signature());
connect(this, signalName, this, SLOT(updateData()));
} else {
- qWarning("QSGShaderEffectItem: '%s' does not have a matching property!", it->constData());
+ qWarning("QSGCustomParticle: '%s' does not have a matching property!", it->constData());
}
}
for (int i = 0; i < m_sources.size(); ++i) {
source.mapper->setMapping(this, i);
connect(source.mapper, SIGNAL(mapped(int)), this, SLOT(changeSource(int)));
} else {
- qWarning("QSGShaderEffectItem: '%s' does not have a matching source!", source.name.constData());
+ qWarning("QSGCustomParticle: '%s' does not have a matching source!", source.name.constData());
}
}
}
lookThroughShaderCode(fragmentCode);
if (!m_source.attributeNames.contains(qt_position_attribute_name))
- qWarning("QSGShaderEffectItem: Missing reference to \'%s\'.", qt_position_attribute_name);
+ qWarning("QSGCustomParticle: Missing reference to \'%s\'.", qt_position_attribute_name);
if (!m_source.attributeNames.contains(qt_texcoord_attribute_name))
- qWarning("QSGShaderEffectItem: Missing reference to \'%s\'.", qt_texcoord_attribute_name);
+ qWarning("QSGCustomParticle: Missing reference to \'%s\'.", qt_texcoord_attribute_name);
if (!m_source.respectsMatrix)
- qWarning("QSGShaderEffectItem: Missing reference to \'qt_ModelViewProjectionMatrix\'.");
+ qWarning("QSGCustomParticle: Missing reference to \'qt_Matrix\'.");
if (!m_source.respectsOpacity)
- qWarning("QSGShaderEffectItem: Missing reference to \'qt_Opacity\'.");
+ qWarning("QSGCustomParticle: Missing reference to \'qt_Opacity\'.");
for (int i = 0; i < m_sources.size(); ++i) {
QVariant v = property(m_sources.at(i).name);
} else {
Q_ASSERT(decl == "uniform");//TODO: Shouldn't assert
- if (name == "qt_ModelViewProjectionMatrix") {
+ if (name == "qt_Matrix") {
+ m_source.respectsMatrix = true;
+ } else if (name == "qt_ModelViewProjectionMatrix") {
+ // TODO: Remove after grace period.
+ qWarning("ShaderEffect: qt_ModelViewProjectionMatrix is deprecated. Use qt_Matrix instead.");
m_source.respectsMatrix = true;
} else if (name == "qt_Opacity") {
m_source.respectsOpacity = true;
class QSGNode;
struct PlainVertices;
-//Genealogy: Hybrid of UltraParticle and ShaderEffectItem
+//Genealogy: Hybrid of UltraParticle and ShaderEffect
class QSGCustomParticle : public QSGParticlePainter
{
Q_OBJECT
resolveUniforms();
}
- const char *uniformMatrixName() const { return "qt_ModelViewProjectionMatrix"; }
+ const char *uniformMatrixName() const { return "qt_Matrix"; }
const char *uniformOpacityName() const { return "qt_Opacity"; }
void updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial);