50 "uniform highp mat4 qt_ModelViewProjectionMatrix;\n" 51 "attribute highp vec4 qt_Vertex;\n" 52 "attribute highp vec2 qt_MultiTexCoord0;\n" 53 "varying highp vec2 qt_TexCoord0;\n" 56 "qt_TexCoord0 = qt_MultiTexCoord0;\n" 57 "gl_Position = qt_ModelViewProjectionMatrix * qt_Vertex;\n" 61 "varying highp vec2 qt_TexCoord0;\n" 62 "uniform lowp sampler2D source;\n" 65 "gl_FragColor = texture2D(source, qt_TexCoord0.st);\n" 208 , m_meshResolution(1, 1)
209 , m_geometry(
QSGGeometry::defaultAttributes_TexturedPoint2D(), 4)
211 , m_program_dirty(true)
213 , m_respectsMatrix(false)
214 , m_respectsOpacity(false)
215 , m_checkedViewportUpdateMode(false)
216 , m_checkedOpenGL(false)
217 , m_checkedShaderPrograms(false)
218 , m_hasShaderPrograms(false)
220 , m_defaultVertexShader(true)
370 for (
int i = 0; i < views.
count(); i++) {
372 qWarning() <<
"ShaderEffectItem::checkViewportUpdateMode - consider setting QGraphicsView::FullViewportUpdate mode with OpenGL!";
392 qWarning() <<
"ShaderEffectItem::paint - Shader programs are not supported";
407 qWarning() <<
"ShaderEffectItem::paint - OpenGL not available";
415 if (!painter || !painter->
device())
425 qWarning() <<
"ShaderEffectItem::renderEffect - Creating QGLShaderProgram failed!";
456 #if defined(QT_OPENGL_ES) 461 glClearColor(0, 0, 0, 0);
489 for (
int i =
m_sources.size() - 1; i >= 0; --i) {
552 static int sizes[] = {
554 sizeof(
unsigned char),
556 sizeof(
unsigned short),
558 sizeof(
unsigned int),
580 Q_ASSERT_X(j == a.position,
"ShaderEffectItem::bindGeometry()",
"Geometry does not have continuous attribute positions");
581 #if defined(QT_OPENGL_ES_2) 587 qWarning() <<
"ShaderEffectItem::bindGeometry() - non supported attribute type!";
597 QRectF srcRect(0, 1, 1, -1);
600 srcRect =
QRectF(0, 0, 1, 1);
608 if (vmesh == 1 && hmesh == 1) {
615 g->
allocate((vmesh + 1) * (hmesh + 1), vmesh * 2 * (hmesh + 2));
619 for (
int iy = 0; iy <= vmesh; ++iy) {
620 float fy = iy / float(vmesh);
621 float y = float(dstRect.
top()) + fy *
float(dstRect.
height());
622 float ty = float(srcRect.
top()) + fy *
float(srcRect.
height());
623 for (
int ix = 0; ix <= hmesh; ++ix) {
624 float fx = ix / float(hmesh);
625 vdata->
x = float(dstRect.
left()) + fx *
float(dstRect.
width());
627 vdata->
tx = float(srcRect.
left()) + fx *
float(srcRect.
width());
635 for (
int iy = 0; iy < vmesh; ++iy) {
636 *(indices++) = i + hmesh + 1;
637 for (
int ix = 0; ix <= hmesh; ++ix, ++i) {
638 *(indices++) = i + hmesh + 1;
641 *(indices++) = i - 1;
651 for (
int i = 0; i <
m_sources.size(); ++i) {
663 for (
int i = 0; i <
m_sources.size(); ++i) {
684 for (
int i = 0; i <
m_sources.size(); ++i) {
693 if (newGeometry.
size() != oldGeometry.
size())
719 }
else if (!qVariantCanConvert<QObject *>(var)) {
720 qWarning(
"Could not assign source of type '%s' to property '%s'.", var.
typeName(), source.name.constData());
724 QObject *obj = qVariantValue<QObject *>(var);
730 qWarning(
"Could not assign property '%s', did not implement QDeclarativeItem.", source.name.constData());
733 qWarning(
"Could not assign property '%s', did not implement ShaderEffectSource.", source.name.constData());
739 if (source.item && source.item->parentItem() == 0) {
740 source.item->setParentItem(
this);
746 source.source->refFromEffectItem();
754 for (
int i = 0; i <
m_sources.size(); ++i) {
769 qWarning(
"ShaderEffectItem: property '%s' does not have notification method!", it->constData());
774 qWarning(
"ShaderEffectItem: '%s' does not have a matching property!", it->constData());
777 for (
int i = 0; i <
m_sources.size(); ++i) {
802 for (
int i = 0; i <
m_sources.size(); ++i) {
832 qWarning(
"ShaderEffectItem: Missing reference to \'qt_ModelViewProjectionMatrix\'.");
834 for (
int i = 0; i <
m_sources.size(); ++i) {
864 qWarning(
"ShaderEffectItem: Shader compilation failed:");
869 qWarning(
"ShaderEffectItem: Missing reference to \'qt_Vertex\'.");
871 qWarning(
"ShaderEffectItem: Missing reference to \'qt_MultiTexCoord0\'.");
873 qWarning(
"ShaderEffectItem: Missing reference to \'qt_ModelViewProjectionMatrix\'.");
877 for (
int i = 0; i <
m_sources.size(); ++i)
888 static QRegExp re(
QLatin1String(
"\\b(attribute|uniform)\\b\\s*\\b(?:lowp|mediump|highp)?\\b\\s*\\b(\\w+)\\b\\s*\\b(\\w+)"));
896 while ((pos = re.
indexIn(wideCode, pos + 1)) != -1) {
901 if (decl ==
"attribute") {
904 }
else if (name ==
"qt_MultiTexCoord0") {
911 qWarning(
"ShaderEffectItem: Attribute \'%s\' not recognized.", name.
constData());
916 if (name ==
"qt_ModelViewProjectionMatrix") {
918 }
else if (name ==
"qt_Opacity") {
922 if (type ==
"sampler2D") {
The QVariant class acts like a union for the most common Qt data types.
void lookThroughShaderCode(const QString &code)
void translate(const QVector3D &vector)
Multiplies this matrix by another that translates coordinates by the components of vector...
#define GL_ONE_MINUS_SRC_ALPHA
The QPainter class performs low-level painting on widgets and other paint devices.
QPaintDevice * device() const
Returns the paint device on which this painter is currently painting, or 0 if the painter is not acti...
The QColor class provides colors based on RGB, HSV or CMYK values.
void setMeshResolution(const QSize &size)
void bindAttributeLocation(const char *name, int location)
Binds the attribute name to the specified location.
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
void disableAttributeArray(int location)
Disables the vertex array at location in this shader program that was enabled by a previous call to e...
qreal y() const
Returns the y-coordinate of the rectangle's top edge.
The QVector3D class represents a vector or vertex in 3D space.
GLenum drawingMode() const
void visibleChanged()
This signal gets emitted whenever the visibility of the item changes.
TexturedPoint2D * vertexDataAsTexturedPoint2D()
void meshResolutionChanged()
static int size_of_type(GLenum type)
const QTransform & transform() const
Returns the world transformation matrix.
QString cap(int nth=0) const
Returns the text captured by the nth subexpression.
void removeAllShaders()
Removes all of the shaders that were added to this program previously.
void changeSource(int index)
QPointF toPointF() const
Returns the variant as a QPointF if the variant has type() Point or PointF ; otherwise returns a null...
QDeclarativeParserStatus ** d
bool m_defaultVertexShader
void setSource(const QVariant &var, int index)
void setFragmentShader(const QString &code)
QVector< const char * > m_attributeNames
bool m_checkedViewportUpdateMode
void setAttributeArray(int location, const GLfloat *values, int tupleSize, int stride=0)
Sets an array of vertex values on the attribute at location in this shader program.
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
This function is called to handle this item's changes in geometry from oldGeometry to newGeometry...
GLuint programId() const
Returns the OpenGL identifier associated with this shader program.
The QRegExp class provides pattern matching using regular expressions.
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
#define it(className, varName)
QByteArray & append(char c)
Appends the character ch to this byte array.
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
void disconnectPropertySignals()
static void updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &sourceRect)
The QByteArray class provides an array of bytes.
qreal left() const
Returns the x-coordinate of the rectangle's left edge.
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
void restore()
Restores the current painter state (pops a saved state off the stack).
void setVertexShader(const QString &code)
void connectPropertySignals()
void vertexShaderChanged()
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool toBool() const
Returns the variant as a bool if the variant has type() Bool.
The QSignalMapper class bundles signals from identifiable senders.
void handleVisibilityChange()
QPointF pos() const
Returns the position of the item in parent coordinates.
long ASN1_INTEGER_get ASN1_INTEGER * a
int count(const T &t) const
Returns the number of occurrences of value in the list.
QString log() const
Returns the errors and warnings that occurred during the last link() or addShader() with explicitly s...
virtual void componentComplete()
void setBlending(bool enable)
The QString class provides a Unicode character string.
T * qobject_cast(QObject *object)
QRectF toRectF() const
Returns the variant as a QRectF if the variant has type() Rect or RectF ; otherwise returns an invali...
void updateShaderProgram()
void update(const QRectF &rect=QRectF())
Schedules a redraw of the area covered by rect in this item.
qreal effectiveOpacity() const
Returns this item's effective opacity, which is between 0.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
The QObject class is the base class of all Qt objects.
static const char qt_emptyAttributeName[]
void save()
Saves the current painter state (pushes the state onto a stack).
static const QGLContext * currentContext()
Returns the current context, i.e.
bool addShaderFromSourceCode(QGLShader::ShaderType type, const char *source)
Compiles source as a shader of the specified type and adds it to this shader program.
bool isValid() const
Returns true if the regular expression is valid; otherwise returns false.
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
QFuture< T > mapped(const Sequence &sequence, MapFunction function)
static const char qt_default_vertex_code[]
void setMapping(QObject *sender, int id)
Adds a mapping so that when map() is signalled from the given sender, the signal mapped(id) is emitte...
QMatrix matrix() const
Returns the item's affine transformation matrix.
int width() const
Returns the width.
void renderEffect(QPainter *painter, const QMatrix4x4 &matrix)
QFuture< void > map(Sequence &sequence, MapFunction function)
bool m_checkedShaderPrograms
The QRectF class defines a rectangle in the plane using floating point precision. ...
int indexIn(const QString &str, int offset=0, CaretMode caretMode=CaretAtZero) const
Attempts to find a match in str from position offset (0 by default).
QList< QGraphicsView * > views() const
Returns a list of all the views that display this scene.
The QDeclarativeItem class provides the most basic of all visual items in QML.
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
The QGLContext class encapsulates an OpenGL rendering context.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
void beginNativePainting()
Flushes the painting pipeline and prepares for the user issuing commands directly to the underlying g...
qreal height() const
Returns the height of the rectangle.
virtual int type() const
Returns the type of an item as an int.
static const char qt_postion_attribute_name[]
Q_CORE_EXPORT void qWarning(const char *,...)
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
const_iterator insert(const T &value)
qreal width() const
Returns the width of the rectangle.
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
const char * typeName() const
Returns the name of the type stored in the variant.
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
This function is called to handle this item's changes in geometry from oldGeometry to newGeometry...
The ShaderEffectSource object encapsulates the source content for the ShaderEffectItem.
void derefFromEffectItem()
const T & at(int i) const
Returns the item at index position i in the vector.
#define GL_DEPTH_BUFFER_BIT
QPointer< ShaderEffectSource > source
static const char qt_default_fragment_code[]
QSizeF toSizeF() const
Returns the variant as a QSizeF if the variant has type() SizeF ; otherwise returns an invalid QSizeF...
const char * constData() const
Returns a pointer to the data stored in the byte array.
virtual bool link()
Links together the shaders that were added to this program with addShader().
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
void insert(int i, const T &t)
Inserts value at index position i in the vector.
static const char qt_texcoord_attribute_name[]
#define Q_ASSERT_X(cond, where, what)
quint16 * indexDataAsUShort()
qreal y() const
This convenience function is equivalent to calling pos().
void setUniformValue(int location, GLfloat value)
Sets the uniform variable at location in the current context to value.
qreal x() const
Returns the x-coordinate of the rectangle's left edge.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Type type() const
Returns the storage type of the value stored in the variant.
ShaderEffectItem(QDeclarativeItem *parent=0)
QGLShaderProgram * m_program
virtual void componentComplete()
int height() const
Returns the height.
T qvariant_cast(const QVariant &)
void checkViewportUpdateMode()
QSizeF size() const
Returns the size of the rectangle.
bool contains(const T &t) const
Returns true if the vector contains an occurrence of value; otherwise returns false.
void scale(const QVector3D &vector)
Multiplies this matrix by another that scales coordinates by the components of vector.
QVariant property(const char *name) const
Returns the value of the object's name property.
qreal top() const
Returns the y-coordinate of the rectangle's top edge.
const Attribute * attributes() const
void updateEffectState(const QMatrix4x4 &matrix)
The QSize class defines the size of a two-dimensional object using integer point precision.
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
const T * constData() const
Returns a const pointer to the data stored in the vector.
QVector< SourceData > m_sources
bool bind()
Binds this shader program to the active QGLContext and makes it the current shader program...
void setFlag(GraphicsItemFlag flag, bool enabled=true)
If enabled is true, the item flag flag is enabled; otherwise, it is disabled.
void enableAttributeArray(int location)
Enables the vertex array at location in this shader program so that the value set by setAttributeArra...
void endNativePainting()
Restores the painter after manually issuing native painting commands.
static void normalize(double &x, double &y)
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem...
The QGLShaderProgram class allows OpenGL shader programs to be linked and used.
QPointer< QDeclarativeItem > item
void allocate(int vertexCount, int indexCount=0)
int size() const
Returns the number of items in the vector.
static bool hasOpenGLShaderPrograms(const QGLContext *context=0)
Returns true if shader programs written in the OpenGL Shading Language (GLSL) are supported on this s...
void fragmentShaderChanged()
const QChar * constData() const
Returns a pointer to the data stored in the QString.
void setActive(bool enable)
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
bool isLinked() const
Returns true if this shader program has been linked; false otherwise.
The QList class is a template class that provides lists.
int attributeCount() const
QSet< QByteArray > m_uniformNames