aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKim Motoyoshi Kalland <kim.kalland@nokia.com>2011-07-27 11:06:00 +0200
committerQt by Nokia <qt-info@nokia.com>2011-07-28 16:44:53 +0200
commit8cc1663ea20725214133d51920c37145a949f80f (patch)
tree504331aa78f7aea38ccffa5024b48ac4a1f61131 /src
parent99309c5fcf0821ed4da69796b1a315cff7f48250 (diff)
Renamed ShaderEffectItem to ShaderEffect and some API changes.
The ShaderEffectItem was renamed to ShaderEffect to be consistent with other QML element names. The GLSL uniform variable qt_ModelViewProjectionMatrix was renamed to qt_Matrix which is easier to type and remember. The GridMesh element was removed. The mesh resolution is now specified simply with a QSize. To make the transition easier, the old API will continue to work for some time, but will output warnings if used. Eventually, I will remove the old API completely. Change-Id: Iec4f2aa624a2c76a7db6750c58f73dbcb316ab6a Reviewed-on: http://codereview.qt.nokia.com/2270 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/declarative/items/items.pri4
-rw-r--r--src/declarative/items/qsgitemsmodule.cpp9
-rw-r--r--src/declarative/items/qsgshadereffect.cpp (renamed from src/declarative/items/qsgshadereffectitem.cpp)200
-rw-r--r--src/declarative/items/qsgshadereffect_p.h (renamed from src/declarative/items/qsgshadereffectitem_p.h)22
-rw-r--r--src/declarative/items/qsgshadereffectmesh.cpp45
-rw-r--r--src/declarative/items/qsgshadereffectnode.cpp5
-rw-r--r--src/declarative/items/qsgshadereffectnode_p.h2
-rw-r--r--src/declarative/items/qsgshadereffectsource.cpp6
-rw-r--r--src/declarative/particles/qsgcustomparticle.cpp26
-rw-r--r--src/declarative/particles/qsgcustomparticle_p.h2
-rw-r--r--src/declarative/scenegraph/util/qsgsimplematerial.h2
11 files changed, 190 insertions, 133 deletions
diff --git a/src/declarative/items/items.pri b/src/declarative/items/items.pri
index 85492b72fa..848c782a6e 100644
--- a/src/declarative/items/items.pri
+++ b/src/declarative/items/items.pri
@@ -109,13 +109,13 @@ SOURCES += \
$$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 \
diff --git a/src/declarative/items/qsgitemsmodule.cpp b/src/declarative/items/qsgitemsmodule.cpp
index dd1cca2f91..62a4bd06cb 100644
--- a/src/declarative/items/qsgitemsmodule.cpp
+++ b/src/declarative/items/qsgitemsmodule.cpp
@@ -69,7 +69,7 @@
#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"
@@ -170,10 +170,11 @@ static void qt_sgitems_defineModule(const char *uri, int major, int minor)
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"));
diff --git a/src/declarative/items/qsgshadereffectitem.cpp b/src/declarative/items/qsgshadereffect.cpp
index 653e0c2056..6045c5fee9 100644
--- a/src/declarative/items/qsgshadereffectitem.cpp
+++ b/src/declarative/items/qsgshadereffect.cpp
@@ -39,7 +39,7 @@
**
****************************************************************************/
-#include <private/qsgshadereffectitem_p.h>
+#include <private/qsgshadereffect_p.h>
#include <private/qsgshadereffectnode_p.h>
#include "qsgmaterial.h"
@@ -55,13 +55,13 @@
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[] =
@@ -85,14 +85,22 @@ const char *qtTexCoordAttributeName()
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.
@@ -100,11 +108,11 @@ const char *qtTexCoordAttributeName()
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}).
@@ -143,17 +151,17 @@ const char *qtTexCoordAttributeName()
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;
@@ -169,18 +177,18 @@ const char *qtTexCoordAttributeName()
\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)
@@ -191,26 +199,26 @@ QSGShaderEffectItem::QSGShaderEffectItem(QSGItem *parent)
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;
@@ -223,7 +231,7 @@ void QSGShaderEffectItem::setFragmentShader(const QByteArray &code)
}
/*!
- \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
@@ -231,7 +239,7 @@ void QSGShaderEffectItem::setFragmentShader(const QByteArray &code)
sampler2D named "source".
*/
-void QSGShaderEffectItem::setVertexShader(const QByteArray &code)
+void QSGShaderEffect::setVertexShader(const QByteArray &code)
{
if (m_source.vertexCode.constData() == code.constData())
return;
@@ -244,7 +252,7 @@ void QSGShaderEffectItem::setVertexShader(const QByteArray &code)
}
/*!
- \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
@@ -252,7 +260,7 @@ void QSGShaderEffectItem::setVertexShader(const QByteArray &code)
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;
@@ -264,42 +272,103 @@ void QSGShaderEffectItem::setBlending(bool enable)
}
/*!
- \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;
@@ -308,26 +377,26 @@ void QSGShaderEffectItem::setCullMode(CullMode face)
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());
@@ -360,7 +429,7 @@ void QSGShaderEffectItem::setSource(const QVariant &var, int index)
}
}
-void QSGShaderEffectItem::disconnectPropertySignals()
+void QSGShaderEffect::disconnectPropertySignals()
{
disconnect(this, 0, this, SLOT(updateData()));
for (int i = 0; i < m_sources.size(); ++i) {
@@ -370,7 +439,7 @@ void QSGShaderEffectItem::disconnectPropertySignals()
}
}
-void QSGShaderEffectItem::connectPropertySignals()
+void QSGShaderEffect::connectPropertySignals()
{
QSet<QByteArray>::const_iterator it;
for (it = m_source.uniformNames.begin(); it != m_source.uniformNames.end(); ++it) {
@@ -378,12 +447,12 @@ void QSGShaderEffectItem::connectPropertySignals()
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) {
@@ -397,12 +466,12 @@ void QSGShaderEffectItem::connectPropertySignals()
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();
@@ -424,7 +493,7 @@ void QSGShaderEffectItem::reset()
m_dirtyMesh = true;
}
-void QSGShaderEffectItem::updateProperties()
+void QSGShaderEffect::updateProperties()
{
QByteArray vertexCode = m_source.vertexCode;
QByteArray fragmentCode = m_source.fragmentCode;
@@ -436,14 +505,15 @@ void QSGShaderEffectItem::updateProperties()
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);
@@ -453,7 +523,7 @@ void QSGShaderEffectItem::updateProperties()
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>
@@ -474,7 +544,11 @@ void QSGShaderEffectItem::lookThroughShaderCode(const QByteArray &code)
} 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;
@@ -492,13 +566,13 @@ void QSGShaderEffectItem::lookThroughShaderCode(const QByteArray &code)
}
}
-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);
@@ -520,7 +594,7 @@ QSGNode *QSGShaderEffectItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeD
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) {
diff --git a/src/declarative/items/qsgshadereffectitem_p.h b/src/declarative/items/qsgshadereffect_p.h
index 0099aee96c..0cced9a229 100644
--- a/src/declarative/items/qsgshadereffectitem_p.h
+++ b/src/declarative/items/qsgshadereffect_p.h
@@ -64,13 +64,13 @@ class QSGContext;
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)
@@ -82,8 +82,8 @@ public:
FrontFaceCulling = QSGShaderEffectMaterial::FrontFaceCulling
};
- QSGShaderEffectItem(QSGItem *parent = 0);
- ~QSGShaderEffectItem();
+ QSGShaderEffect(QSGItem *parent = 0);
+ ~QSGShaderEffect();
virtual void componentComplete();
@@ -96,8 +96,8 @@ public:
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);
@@ -130,7 +130,8 @@ private:
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;
@@ -151,6 +152,13 @@ private:
uint m_dirtyGeometry : 1;
};
+// TODO: Remove after grace period.
+class QSGShaderEffectItem : public QSGShaderEffect
+{
+public:
+ QSGShaderEffectItem(QSGItem *parent = 0);
+};
+
QT_END_NAMESPACE
QT_END_HEADER
diff --git a/src/declarative/items/qsgshadereffectmesh.cpp b/src/declarative/items/qsgshadereffectmesh.cpp
index 375a033d9d..6d3d17e4ff 100644
--- a/src/declarative/items/qsgshadereffectmesh.cpp
+++ b/src/declarative/items/qsgshadereffectmesh.cpp
@@ -41,7 +41,7 @@
#include "qsgshadereffectmesh_p.h"
#include "qsggeometry.h"
-#include "qsgshadereffectitem_p.h"
+#include "qsgshadereffect_p.h"
QT_BEGIN_NAMESPACE
@@ -51,46 +51,13 @@ QSGShaderEffectMesh::QSGShaderEffectMesh(QObject *parent)
}
/*!
- \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)
@@ -185,7 +152,7 @@ QSGGeometry *QSGGridMesh::updateGeometry(QSGGeometry *geometry, const QVector<QB
}
/*!
- \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
diff --git a/src/declarative/items/qsgshadereffectnode.cpp b/src/declarative/items/qsgshadereffectnode.cpp
index b4dc213b4c..8bd781ce58 100644
--- a/src/declarative/items/qsgshadereffectnode.cpp
+++ b/src/declarative/items/qsgshadereffectnode.cpp
@@ -195,7 +195,10 @@ char const *const *QSGCustomMaterialShader::attributeNames() const
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
diff --git a/src/declarative/items/qsgshadereffectnode_p.h b/src/declarative/items/qsgshadereffectnode_p.h
index 4fb7595602..eee70703ea 100644
--- a/src/declarative/items/qsgshadereffectnode_p.h
+++ b/src/declarative/items/qsgshadereffectnode_p.h
@@ -105,7 +105,7 @@ public:
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
diff --git a/src/declarative/items/qsgshadereffectsource.cpp b/src/declarative/items/qsgshadereffectsource.cpp
index 4803ca0a60..5114d8c042 100644
--- a/src/declarative/items/qsgshadereffectsource.cpp
+++ b/src/declarative/items/qsgshadereffectsource.cpp
@@ -380,7 +380,7 @@ void QSGShaderEffectTexture::grab()
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
@@ -472,7 +472,7 @@ QSGShaderEffectSource::~QSGShaderEffectSource()
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
@@ -581,7 +581,7 @@ void QSGShaderEffectSource::setTextureSize(const QSize &size)
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
diff --git a/src/declarative/particles/qsgcustomparticle.cpp b/src/declarative/particles/qsgcustomparticle.cpp
index 1ce8e43363..7397fc6b50 100644
--- a/src/declarative/particles/qsgcustomparticle.cpp
+++ b/src/declarative/particles/qsgcustomparticle.cpp
@@ -52,7 +52,7 @@ static const char qt_particles_default_vertex_code[] =
"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"
@@ -67,7 +67,7 @@ static const char qt_particles_default_vertex_code[] =
" - 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?
@@ -244,7 +244,7 @@ void QSGCustomParticle::setSource(const QVariant &var, int index)
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'.
@@ -272,12 +272,12 @@ void QSGCustomParticle::connectPropertySignals()
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) {
@@ -291,7 +291,7 @@ void QSGCustomParticle::connectPropertySignals()
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());
}
}
}
@@ -312,13 +312,13 @@ void QSGCustomParticle::updateProperties()
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);
@@ -350,7 +350,11 @@ void QSGCustomParticle::lookThroughShaderCode(const QByteArray &code)
} 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;
diff --git a/src/declarative/particles/qsgcustomparticle_p.h b/src/declarative/particles/qsgcustomparticle_p.h
index e7e8298cc1..1fec963d84 100644
--- a/src/declarative/particles/qsgcustomparticle_p.h
+++ b/src/declarative/particles/qsgcustomparticle_p.h
@@ -53,7 +53,7 @@ QT_MODULE(Declarative)
class QSGNode;
struct PlainVertices;
-//Genealogy: Hybrid of UltraParticle and ShaderEffectItem
+//Genealogy: Hybrid of UltraParticle and ShaderEffect
class QSGCustomParticle : public QSGParticlePainter
{
Q_OBJECT
diff --git a/src/declarative/scenegraph/util/qsgsimplematerial.h b/src/declarative/scenegraph/util/qsgsimplematerial.h
index 84d571b59a..b9e453abec 100644
--- a/src/declarative/scenegraph/util/qsgsimplematerial.h
+++ b/src/declarative/scenegraph/util/qsgsimplematerial.h
@@ -77,7 +77,7 @@ public:
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);