6#include <QtQuick/QSGMaterial>
76 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
83 const int shaderMatrixCount = newMaterial->viewCount();
84 const int matrixCount =
qMin(
state.projectionMatrixCount(), shaderMatrixCount);
85 for (
int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
86 if (
state.isMatrixDirty()) {
88 memcpy(
buf->data() + 64 * viewIndex,
m.constData(), 64);
93 float animPosAndData[7] = { mat->animX1, mat->animY1, mat->animX2, mat->animY2,
94 mat->animW, mat->animH, mat->animT };
95 memcpy(
buf->data() + 64 * shaderMatrixCount, animPosAndData, 28);
98 if (
state.isOpacityDirty()) {
99 const float opacity =
state.opacity();
100 memcpy(
buf->data() + 64 * shaderMatrixCount + 16 + 12, &opacity, 4);
116 Q_ASSERT(oldMaterial ==
nullptr || newMaterial->type() == oldMaterial->type());
138 (2+2) *
sizeof(
float),
144 , m_geometryDirty(true)
145 , m_sheetSize(
QSize(64, 64))
158 setGeometry(m_geometry);
159 setMaterial(m_material);
160 setFlag(OwnsGeometry,
true);
161 setFlag(OwnsMaterial,
true);
167 m_geometryDirty =
true;
168 markDirty(DirtyMaterial);
174 markDirty(DirtyMaterial);
179 if (m_sourceA !=
source) {
183 markDirty(DirtyMaterial);
189 if (m_sourceB !=
source) {
193 markDirty(DirtyMaterial);
199 if (m_spriteSize !=
size) {
201 m_material->
animW =
static_cast<float>(
size.width()) / m_sheetSize.
width();
202 m_material->
animH =
static_cast<float>(
size.height()) / m_sheetSize.
height();
203 markDirty(DirtyMaterial);
210 if (m_sheetSize !=
size) {
214 m_material->
animX1 =
static_cast<float>(m_sourceA.
x()) / m_sheetSize.
width();
215 m_material->
animY1 =
static_cast<float>(m_sourceA.
y()) / m_sheetSize.
height();
216 m_material->
animX2 =
static_cast<float>(m_sourceB.
x()) / m_sheetSize.
width();
217 m_material->
animY2 =
static_cast<float>(m_sourceB.
y()) / m_sheetSize.
height();
218 m_material->
animW =
static_cast<float>(m_spriteSize.
width()) / m_sheetSize.
width();
219 m_material->
animH =
static_cast<float>(m_spriteSize.
height()) / m_sheetSize.
height();
220 markDirty(DirtyMaterial);
226 if (m_size !=
size) {
228 m_geometryDirty =
true;
235 markDirty(DirtyMaterial);
240 if (m_geometryDirty) {
242 m_geometryDirty =
false;
246void QSGDefaultSpriteNode::updateGeometry()
255 p->v1.tx = texRect.topLeft().x();
256 p->v1.ty = texRect.topLeft().y();
258 p->v2.tx = texRect.topRight().x();
259 p->v2.ty = texRect.topRight().y();
261 p->v3.tx = texRect.bottomLeft().x();
262 p->v3.ty = texRect.bottomLeft().y();
264 p->v4.tx = texRect.bottomRight().x();
265 p->v4.ty = texRect.bottomRight().y();
278 markDirty(DirtyGeometry);
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
\inmodule QtCore\reentrant
constexpr int x() const noexcept
Returns the x coordinate of this point.
constexpr int y() const noexcept
Returns the y coordinate of this point.
QSGMaterialShader * createShader(QSGRendererInterface::RenderMode renderMode) const override
This function returns a new instance of a the QSGMaterialShader implementation used to render geometr...
QSGMaterialType * type() const override
This function is called by the scene graph to query an identifier that is unique to the QSGMaterialSh...
\inmodule QtCore\reentrant
void setTexture(QSGTexture *texture) override
void setSheetSize(const QSize &size) override
void setSourceA(const QPoint &source) override
void setSize(const QSizeF &size) override
void setSpriteSize(const QSize &size) override
void setSourceB(const QPoint &source) override
void setTime(float time) override
void setFiltering(QSGTexture::Filtering filtering) override
The QSGGeometry class provides low-level storage for graphics primitives in the \l{Qt Quick Scene Gra...
void setDrawingMode(unsigned int mode)
Sets the mode to be used for drawing this geometry.
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.
Encapsulates the current rendering state during a call to QSGMaterialShader::updateUniformData() and ...
The QSGMaterialShader class represents a graphics API independent shader program.
void setShaderFileName(Stage stage, const QString &filename)
Sets the filename for the shader for the specified stage.
The QSGMaterial class encapsulates rendering state for a shader program.
void setFlag(Flags flags, bool on=true)
Sets the flags flags on this material if on is true; otherwise clears the attribute.
RenderMode
\value RenderMode2D Normal 2D rendering \value RenderMode2DNoDepthBuffer Normal 2D rendering with dep...
virtual void commitTextureOperations(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates)
Call this function to enqueue image upload operations to resourceUpdates, in case there are any pendi...
virtual QRectF normalizedTextureSubRect() const
Returns the rectangle inside textureSize() that this texture represents in normalized coordinates.
void setFiltering(Filtering filter)
Sets the sampling mode to filter.
Filtering
Specifies how sampling of texels should filter when texture coordinates are not pixel aligned.
constexpr qreal width() const noexcept
Returns the width.
constexpr qreal height() const noexcept
Returns the height.
constexpr int height() const noexcept
Returns the height.
constexpr int width() const noexcept
Returns the width.
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
SpriteMaterialRhiShader(int viewCount)
void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to prepare use of sampled images in the shader,...
Combined button and popup list for selecting options.
constexpr const T & qMin(const T &a, const T &b)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei const GLchar * buf
GLsizei GLenum const void * indices
GLsizei GLsizei GLchar * source
static QSGGeometry::Attribute Sprite_Attributes[]
static QSGGeometry::AttributeSet Sprite_AttributeSet
#define QStringLiteral(str)
The QSGGeometry::AttributeSet describes how the vertices in a QSGGeometry are built up.
The QSGGeometry::Attribute describes a single vertex attribute in a QSGGeometry.
static Attribute create(int pos, int tupleSize, int primitiveType, bool isPosition=false)
Creates a new QSGGeometry::Attribute for attribute register pos with tupleSize.
The QSGMaterialType class is used as a unique type token in combination with QSGMaterial.