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
qsgsimpletexturenode.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
4
6#include <private/qsgnode_p.h>
7
9
11{
12public:
18
20 QSGSimpleTextureNode::TextureCoordinatesTransformMode texCoordMode;
23};
24
27 const QRectF &rect,
28 QRectF sourceRect,
29 QSGSimpleTextureNode::TextureCoordinatesTransformMode texCoordMode)
30{
31 if (!texture)
32 return;
33
34 if (!sourceRect.width() || !sourceRect.height()) {
35 QSize ts = texture->textureSize();
36 sourceRect = QRectF(0, 0, ts.width(), ts.height());
37 }
38
39 // Maybe transform the texture coordinates
40 if (texCoordMode.testFlag(QSGSimpleTextureNode::MirrorHorizontally)) {
41 float tmp = sourceRect.left();
42 sourceRect.setLeft(sourceRect.right());
43 sourceRect.setRight(tmp);
44 }
45 if (texCoordMode.testFlag(QSGSimpleTextureNode::MirrorVertically)) {
46 float tmp = sourceRect.top();
47 sourceRect.setTop(sourceRect.bottom());
48 sourceRect.setBottom(tmp);
49 }
50
51 QSGGeometry::updateTexturedRectGeometry(g, rect, texture->convertToNormalizedSourceRect(sourceRect));
52}
53
76 , m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4)
77{
78 setGeometry(&m_geometry);
79 setMaterial(&m_material);
80 setOpaqueMaterial(&m_opaque_material);
82 m_opaque_material.setMipmapFiltering(QSGTexture::None);
83#ifdef QSG_RUNTIME_DESCRIPTION
84 qsgnode_set_description(this, QLatin1String("simpletexture"));
85#endif
86}
87
92{
94 if (d->ownsTexture)
95 delete m_material.texture();
96}
97
105{
106 if (m_material.filtering() == filtering)
107 return;
108
109 m_material.setFiltering(filtering);
110 m_opaque_material.setFiltering(filtering);
112}
113
114
119{
120 return m_material.filtering();
121}
122
123
128{
129 if (m_rect == r)
130 return;
131 m_rect = r;
133 qsgsimpletexturenode_update(&m_geometry, texture(), m_rect, d->sourceRect, d->texCoordMode);
135}
136
149{
150 return m_rect;
151}
152
159{
161 if (d->sourceRect == r)
162 return;
163 d->sourceRect = r;
164 qsgsimpletexturenode_update(&m_geometry, texture(), m_rect, d->sourceRect, d->texCoordMode);
166}
167
183{
184 Q_D(const QSGSimpleTextureNode);
185 return d->sourceRect;
186}
187
199{
202 if (d->ownsTexture)
203 delete m_material.texture();
204 m_material.setTexture(texture);
205 m_opaque_material.setTexture(texture);
206 qsgsimpletexturenode_update(&m_geometry, texture, m_rect, d->sourceRect, d->texCoordMode);
207
208 DirtyState dirty = DirtyMaterial;
209 // It would be tempting to skip the extra bit here and instead use
210 // m_material.texture to get the old state, but that texture could
211 // have been deleted in the mean time.
212 bool wasAtlas = d->isAtlasTexture;
213 d->isAtlasTexture = texture->isAtlasTexture();
214 if (wasAtlas || d->isAtlasTexture)
215 dirty |= DirtyGeometry;
216 markDirty(dirty);
217}
218
219
220
225{
226 return m_material.texture();
227}
228
252void QSGSimpleTextureNode::setTextureCoordinatesTransform(QSGSimpleTextureNode::TextureCoordinatesTransformMode mode)
253{
255 if (d->texCoordMode == mode)
256 return;
257 d->texCoordMode = mode;
258 qsgsimpletexturenode_update(&m_geometry, texture(), m_rect, d->sourceRect, d->texCoordMode);
260}
261
267QSGSimpleTextureNode::TextureCoordinatesTransformMode QSGSimpleTextureNode::textureCoordinatesTransform() const
268{
269 Q_D(const QSGSimpleTextureNode);
270 return d->texCoordMode;
271}
272
283{
285 d->ownsTexture = owns;
286}
287
294{
295 Q_D(const QSGSimpleTextureNode);
296 return d->ownsTexture;
297}
298
\inmodule QtCore\reentrant
Definition qrect.h:484
constexpr qreal bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:500
constexpr void setBottom(qreal pos) noexcept
Sets the bottom edge of the rectangle to the given finite y coordinate.
Definition qrect.h:684
constexpr void setRight(qreal pos) noexcept
Sets the right edge of the rectangle to the given finite x coordinate.
Definition qrect.h:678
constexpr void setLeft(qreal pos) noexcept
Sets the left edge of the rectangle to the given finite x coordinate.
Definition qrect.h:675
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 void setTop(qreal pos) noexcept
Sets the top edge of the rectangle to the given finite y coordinate.
Definition qrect.h:681
constexpr qreal left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:497
constexpr qreal top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:498
constexpr qreal right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
Definition qrect.h:499
void setGeometry(QSGGeometry *geometry)
Sets the geometry of this node to geometry.
Definition qsgnode.cpp:764
The QSGGeometryNode class is used for all rendered content in the scene graph.
Definition qsgnode.h:188
void setMaterial(QSGMaterial *material)
Sets the material of this geometry node to material.
Definition qsgnode.cpp:927
void setOpaqueMaterial(QSGMaterial *material)
Sets the opaque material of this geometry to material.
Definition qsgnode.cpp:958
The QSGGeometry class provides low-level storage for graphics primitives in the \l{Qt Quick Scene Gra...
Definition qsggeometry.h:15
static void updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &sourceRect)
Updates the geometry g with the coordinates in rect and texture coordinates from textureRect.
@ DirtyMaterial
Definition qsgnode.h:75
@ DirtyGeometry
Definition qsgnode.h:74
void markDirty(DirtyState bits)
Notifies all connected renderers that the node has dirty bits.
Definition qsgnode.cpp:624
void setFiltering(QSGTexture::Filtering filteringType)
Sets the filtering to filtering.
QSGTexture::Filtering filtering() const
Returns this material's filtering mode.
void setMipmapFiltering(QSGTexture::Filtering filteringType)
Sets the mipmap mode to filtering.
void setTexture(QSGTexture *texture)
Sets the texture of this material to texture.
QSGTexture * texture() const
Returns this texture material's texture.
QSGSimpleTextureNode::TextureCoordinatesTransformMode texCoordMode
The QSGSimpleTextureNode class is provided for convenience to easily draw textured content using the ...
void setTextureCoordinatesTransform(TextureCoordinatesTransformMode mode)
Sets the method used to generate texture coordinates to mode.
void setRect(const QRectF &rect)
Sets the target rect of this texture node to r.
void setFiltering(QSGTexture::Filtering filtering)
Sets the filtering to be used for this texture node to filtering.
QSGTexture::Filtering filtering() const
Returns the filtering currently set on this texture node.
QSGSimpleTextureNode()
Constructs a new simple texture node.
bool ownsTexture() const
Returns true if the node takes ownership of the texture; otherwise returns false.
void setTexture(QSGTexture *texture)
Sets the texture of this texture node to texture.
QSGTexture * texture() const
Returns the texture for this texture node.
TextureCoordinatesTransformMode textureCoordinatesTransform() const
Returns the mode used to generate texture coordinates for this node.
void setSourceRect(const QRectF &r)
Sets the source rect of this texture node to r.
QRectF rect() const
Returns the target rect of this texture node.
void setOwnsTexture(bool owns)
Sets whether the node takes ownership of the texture to owns.
~QSGSimpleTextureNode() override
Destroys the texture node.
QRectF sourceRect() const
Returns the source rect of this texture node.
\inmodule QtQuick
Definition qsgtexture.h:20
Filtering
Specifies how sampling of texels should filter when texture coordinates are not pixel aligned.
Definition qsgtexture.h:34
\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
rect
[4]
Combined button and popup list for selecting options.
GLenum mode
GLboolean r
[2]
GLenum GLuint texture
GLboolean GLboolean g
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
void qsgnode_set_description(QSGNode *node, const QString &description)
Definition qsgnode.cpp:641
static void qsgsimpletexturenode_update(QSGGeometry *g, QSGTexture *texture, const QRectF &rect, QRectF sourceRect, QSGSimpleTextureNode::TextureCoordinatesTransformMode texCoordMode)
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
unsigned int uint
Definition qtypes.h:34