Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickshadereffectmesh.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include <QtQuick/qsggeometry.h>
9#include <QtQuick/private/qsgbasicinternalimagenode_p.h>
10
12
13static const char qt_position_attribute_name[] = "qt_Vertex";
14static const char qt_texcoord_attribute_name[] = "qt_MultiTexCoord0";
15
17{
19}
20
22{
24}
25
30
35
51 , m_resolution(1, 1)
52{
53}
54
55bool QQuickGridMesh::validateAttributes(const QList<QByteArray> &attributes, int *posIndex)
56{
57 const int attrCount = attributes.size();
58 int positionIndex = attributes.indexOf(qtPositionAttributeName());
59 int texCoordIndex = attributes.indexOf(qtTexCoordAttributeName());
60
61 switch (attrCount) {
62 case 0:
63 m_log = QLatin1String("Error: No attributes specified.");
64 return false;
65 case 1:
66 if (positionIndex != 0) {
67 m_log = QLatin1String("Error: Missing \'") + QLatin1String(qtPositionAttributeName())
68 + QLatin1String("\' attribute.\n");
69 return false;
70 }
71 break;
72 case 2:
73 if (positionIndex == -1 || texCoordIndex == -1) {
74 m_log.clear();
75 if (positionIndex == -1) {
76 m_log = QLatin1String("Error: Missing \'") + QLatin1String(qtPositionAttributeName())
77 + QLatin1String("\' attribute.\n");
78 }
79 if (texCoordIndex == -1) {
80 m_log += QLatin1String("Error: Missing \'") + QLatin1String(qtTexCoordAttributeName())
81 + QLatin1String("\' attribute.\n");
82 }
83 return false;
84 }
85 break;
86 default:
87 m_log = QLatin1String("Error: Too many attributes specified.");
88 return false;
89 }
90
91 if (posIndex)
92 *posIndex = positionIndex;
93
94 return true;
95}
96
97QSGGeometry *QQuickGridMesh::updateGeometry(QSGGeometry *geometry, int attrCount, int posIndex,
98 const QRectF &srcRect, const QRectF &dstRect)
99{
100 int vmesh = m_resolution.height();
101 int hmesh = m_resolution.width();
102
103 if (!geometry) {
104 Q_ASSERT(attrCount == 1 || attrCount == 2);
105 geometry = new QSGGeometry(attrCount == 1
108 (vmesh + 1) * (hmesh + 1), vmesh * 2 * (hmesh + 2),
110
111 } else {
112 geometry->allocate((vmesh + 1) * (hmesh + 1), vmesh * 2 * (hmesh + 2));
113 }
114
115 QSGGeometry::Point2D *vdata = static_cast<QSGGeometry::Point2D *>(geometry->vertexData());
116
117 for (int iy = 0; iy <= vmesh; ++iy) {
118 float fy = iy / float(vmesh);
119 float y = float(dstRect.top()) + fy * float(dstRect.height());
120 float ty = float(srcRect.top()) + fy * float(srcRect.height());
121 for (int ix = 0; ix <= hmesh; ++ix) {
122 float fx = ix / float(hmesh);
123 for (int ia = 0; ia < attrCount; ++ia) {
124 if (ia == posIndex) {
125 vdata->x = float(dstRect.left()) + fx * float(dstRect.width());
126 vdata->y = y;
127 ++vdata;
128 } else {
129 vdata->x = float(srcRect.left()) + fx * float(srcRect.width());
130 vdata->y = ty;
131 ++vdata;
132 }
133 }
134 }
135 }
136
137 quint16 *indices = (quint16 *)geometry->indexDataAsUShort();
138 int i = 0;
139 for (int iy = 0; iy < vmesh; ++iy) {
140 *(indices++) = i + hmesh + 1;
141 for (int ix = 0; ix <= hmesh; ++ix, ++i) {
142 *(indices++) = i + hmesh + 1;
143 *(indices++) = i;
144 }
145 *(indices++) = i - 1;
146 }
147
148 return geometry;
149}
150
206{
207 if (res == m_resolution)
208 return;
209 if (res.width() < 1 || res.height() < 1) {
210 return;
211 }
212 m_resolution = res;
215}
216
218{
219 return m_resolution;
220}
221
281 : QQuickShaderEffectMesh(parent), m_border(new QQuickScaleGrid(this)),
282 m_horizontalTileMode(QQuickBorderImageMesh::Stretch),
283 m_verticalTileMode(QQuickBorderImageMesh::Stretch)
284{
285}
286
287bool QQuickBorderImageMesh::validateAttributes(const QList<QByteArray> &attributes, int *posIndex)
288{
289 Q_UNUSED(attributes);
290 Q_UNUSED(posIndex);
291 return true;
292}
293
294QSGGeometry *QQuickBorderImageMesh::updateGeometry(QSGGeometry *geometry, int attrCount, int posIndex,
295 const QRectF &srcRect, const QRectF &rect)
296{
297 Q_UNUSED(attrCount);
298 Q_UNUSED(posIndex);
299
300 QRectF innerSourceRect;
301 QRectF targetRect;
302 QRectF innerTargetRect;
303 QRectF subSourceRect;
304
305 QQuickBorderImagePrivate::calculateRects(m_border, m_size, rect.size(), m_horizontalTileMode, m_verticalTileMode,
306 1, &targetRect, &innerTargetRect, &innerSourceRect, &subSourceRect);
307
308 QRectF sourceRect = srcRect;
309 QRectF modifiedInnerSourceRect(sourceRect.x() + innerSourceRect.x() * sourceRect.width(),
310 sourceRect.y() + innerSourceRect.y() * sourceRect.height(),
311 innerSourceRect.width() * sourceRect.width(),
312 innerSourceRect.height() * sourceRect.height());
313
314 geometry = QSGBasicInternalImageNode::updateGeometry(targetRect, innerTargetRect, sourceRect,
315 modifiedInnerSourceRect, subSourceRect, geometry);
316
317 return geometry;
318}
319
347{
348 return m_border;
349}
350
358{
359 return m_size;
360}
361
363{
364 if (size == m_size)
365 return;
366 m_size = size;
369}
370
387{
388 return m_horizontalTileMode;
389}
390
392{
393 if (t == m_horizontalTileMode)
394 return;
395 m_horizontalTileMode = t;
398}
399
401{
402 return m_verticalTileMode;
403}
404
406{
407 if (t == m_verticalTileMode)
408 return;
409
410 m_verticalTileMode = t;
413}
414
416
417#include "moc_qquickshadereffectmesh_p.cpp"
\inmodule QtCore
Definition qobject.h:103
void setSize(const QSize &size)
bool validateAttributes(const QVector< QByteArray > &attributes, int *posIndex) override
void horizontalTileModeChanged()
QQuickBorderImageMesh(QObject *parent=nullptr)
\qmltype BorderImageMesh \instantiates QQuickBorderImageMesh \inqmlmodule QtQuick
QSGGeometry * updateGeometry(QSGGeometry *geometry, int attrCount, int posIndex, const QRectF &srcRect, const QRectF &rect) override
static void calculateRects(const QQuickScaleGrid *border, const QSize &sourceSize, const QSizeF &targetSize, int horizontalTileMode, int verticalTileMode, qreal devicePixelRatio, QRectF *targetRect, QRectF *innerTargetRect, QRectF *innerSourceRect, QRectF *subSourceRect)
QSGGeometry * updateGeometry(QSGGeometry *geometry, int attrCount, int posIndex, const QRectF &srcRect, const QRectF &rect) override
void resolutionChanged()
void setResolution(const QSize &res)
\qmlproperty size QtQuick::GridMesh::resolution
QQuickGridMesh(QObject *parent=nullptr)
\qmltype GridMesh \instantiates QQuickGridMesh \inqmlmodule QtQuick
bool validateAttributes(const QVector< QByteArray > &attributes, int *posIndex) override
The QQuickScaleGrid class allows you to specify a 3x3 grid to use in scaling an image.
QQuickShaderEffectMesh(QObject *parent=nullptr)
\inmodule QtCore\reentrant
Definition qrect.h:484
constexpr qreal y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:672
constexpr qreal height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:732
constexpr qreal width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:729
constexpr qreal x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:669
The QSGGeometry class provides low-level storage for graphics primitives in the \l{Qt Quick Scene Gra...
Definition qsggeometry.h:15
static const AttributeSet & defaultAttributes_Point2D()
Convenience function which returns attributes to be used for 2D solid color drawing.
static const AttributeSet & defaultAttributes_TexturedPoint2D()
Convenience function which returns attributes to be used for textured 2D drawing.
void allocate(int vertexCount, int indexCount=0)
Resizes the vertex and index data of this geometry object to fit vertexCount vertices and indexCount ...
void * vertexData()
Returns a pointer to the raw vertex data of this geometry object.
quint16 * indexDataAsUShort()
Convenience function to access the index data as a mutable array of 16-bit unsigned integers.
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
void clear()
Clears the contents of the string and makes it null.
Definition qstring.h:1252
#define this
Definition dialogs.cpp:9
rect
[4]
Combined button and popup list for selecting options.
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLsizei GLenum const void * indices
GLint y
GLuint res
GLdouble GLdouble t
Definition qopenglext.h:243
GLbyte ty
static QT_BEGIN_NAMESPACE const char qt_position_attribute_name[]
const char * qtTexCoordAttributeName()
static const char qt_texcoord_attribute_name[]
const char * qtPositionAttributeName()
QT_BEGIN_NAMESPACE Q_QUICK_EXPORT const char * qtPositionAttributeName()
Q_QUICK_EXPORT const char * qtTexCoordAttributeName()
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define Q_EMIT
#define emit
#define Q_UNUSED(x)
unsigned short quint16
Definition qtypes.h:48
The QSGGeometry::Point2D struct is a convenience struct for accessing 2D Points.
Definition qsggeometry.h:79