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
qsgopenvginternalimagenode.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 "qsgopenvghelpers.h"
6
7#include <VG/openvg.h>
8
10
12{
13 // Set Dummy material and geometry to avoid asserts
16}
17
19{
20 if (m_subSourceRectImage != 0)
21 vgDestroyImage(m_subSourceRectImage);
22}
23
25{
26 if (!m_texture) {
27 return;
28 }
29
30 // Set Draw Mode
31 if (opacity() < 1.0) {
32 //Transparent
33 vgSetPaint(opacityPaint(), VG_FILL_PATH);
34 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY);
35 } else {
36 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
37 }
38
39 // Set Transform
40 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
41 vgLoadMatrix(transform().constData());
42
43 VGImage image = static_cast<VGImage>(m_texture->comparisonKey());
44 QSize textureSize = m_texture->textureSize();
45
46 if (image == VG_INVALID_HANDLE || !textureSize.isValid())
47 return;
48
49
50 // If Mirrored
51 if (m_mirror) {
52 vgTranslate(m_targetRect.width(), 0.0f);
53 vgScale(-1.0, 1.0);
54 }
55
56 if (m_smooth)
57 vgSeti(VG_IMAGE_QUALITY, VG_IMAGE_QUALITY_BETTER);
58 else
59 vgSeti(VG_IMAGE_QUALITY, VG_IMAGE_QUALITY_NONANTIALIASED);
60
61
62 if (m_innerTargetRect != m_targetRect) {
63 // border image
64 QSGOpenVGHelpers::qDrawBorderImage(image, textureSize, m_targetRect, m_innerTargetRect, m_subSourceRect);
65 } else if (m_tileHorizontal || m_tileVertical) {
66 // Tilled Image
67
68 float sx = m_targetRect.width() / (m_subSourceRect.width() * textureSize.width());
69 float sy = m_targetRect.height() / (m_subSourceRect.height() * textureSize.height());
70 QPointF offset(m_subSourceRect.left() * textureSize.width(), m_subSourceRect.top() * textureSize.height());
71
72 QSGOpenVGHelpers::qDrawTiled(image, textureSize, m_targetRect, offset, sx, sy);
73
74 } else {
75 // Regular BLIT
76
77 QRectF sr(m_subSourceRect.left() * textureSize.width(), m_subSourceRect.top() * textureSize.height(),
78 m_subSourceRect.width() * textureSize.width(), m_subSourceRect.height() * textureSize.height());
79
80 if (m_subSourceRectImageDirty) {
81 if (m_subSourceRectImage != 0)
82 vgDestroyImage(m_subSourceRectImage);
83 m_subSourceRectImage = vgChildImage(image, sr.x(), sr.y(), sr.width(), sr.height());
84 m_subSourceRectImageDirty = false;
85 }
86
87 // If the the source rect is the same as the target rect
88 if (sr == m_targetRect) {
89 vgDrawImage(image);
90 } else {
91 // Scale
92 float scaleX = m_targetRect.width() / sr.width();
93 float scaleY = m_targetRect.height() / sr.height();
94 vgTranslate(m_targetRect.x(), m_targetRect.y());
95 vgScale(scaleX, scaleY);
96 vgDrawImage(m_subSourceRectImage);
97 }
98 }
99}
100
102{
103 if (rect == m_targetRect)
104 return;
105 m_targetRect = rect;
107}
108
110{
111 if (rect == m_innerTargetRect)
112 return;
113 m_innerTargetRect = rect;
115}
116
118{
119 if (rect == m_innerSourceRect)
120 return;
121 m_innerSourceRect = rect;
123}
124
126{
127 if (rect == m_subSourceRect)
128 return;
129 m_subSourceRect = rect;
130 m_subSourceRectImageDirty = true;
132}
133
135{
136 m_texture = texture;
137 m_subSourceRectImageDirty = true;
139}
140
142{
143 if (m_mirror != mirror) {
144 m_mirror = mirror;
146 }
147}
148
152
154{
155 bool smooth = (filtering == QSGTexture::Linear);
156 if (smooth == m_smooth)
157 return;
158
159 m_smooth = smooth;
161}
162
164{
165 bool tileHorizontal = (wrapMode == QSGTexture::Repeat);
166 if (tileHorizontal == m_tileHorizontal)
167 return;
168
169 m_tileHorizontal = tileHorizontal;
171}
172
174{
175 bool tileVertical = (wrapMode == QSGTexture::Repeat);
176 if (tileVertical == m_tileVertical)
177 return;
178
179 m_tileVertical = (wrapMode == QSGTexture::Repeat);
181}
182
186
188{
189 bool doDirty = false;
190 QSGLayer *t = qobject_cast<QSGLayer *>(m_texture);
191 if (t) {
192 doDirty = t->updateTexture();
194 }
195 if (doDirty)
197}
198
200
201
202
203
\inmodule QtCore\reentrant
Definition qpoint.h:217
\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
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
void setGeometry(QSGGeometry *geometry)
Sets the geometry of this node to geometry.
Definition qsgnode.cpp:764
void setMaterial(QSGMaterial *material)
Sets the material of this geometry node to material.
Definition qsgnode.cpp:927
The QSGGeometry class provides low-level storage for graphics primitives in the \l{Qt Quick Scene Gra...
Definition qsggeometry.h:15
The QSGMaterial class encapsulates rendering state for a shader program.
Definition qsgmaterial.h:15
@ 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 setInnerTargetRect(const QRectF &rect) override
void setSubSourceRect(const QRectF &rect) override
void setVerticalWrapMode(QSGTexture::WrapMode wrapMode) override
void setHorizontalWrapMode(QSGTexture::WrapMode wrapMode) override
void setTexture(QSGTexture *texture) override
void setMipmapFiltering(QSGTexture::Filtering filtering) override
void setFiltering(QSGTexture::Filtering filtering) override
void setTargetRect(const QRectF &rect) override
void setInnerSourceRect(const QRectF &rect) override
void preprocess() override
Override this function to do processing on the node before it is rendered.
const QOpenVGMatrix & transform() const
\inmodule QtQuick
Definition qsgtexture.h:20
virtual QSize textureSize() const =0
Returns the size of the texture in pixels.
Filtering
Specifies how sampling of texels should filter when texture coordinates are not pixel aligned.
Definition qsgtexture.h:34
WrapMode
Specifies how the sampler should treat texture coordinates.
Definition qsgtexture.h:28
virtual qint64 comparisonKey() const =0
Returns a key suitable for comparing textures.
\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
constexpr bool isValid() const noexcept
Returns true if both the width and height is equal to or greater than 0; otherwise returns false.
Definition qsize.h:127
rect
[4]
void qDrawBorderImage(VGImage image, const QSizeF &textureSize, const QRectF &targetRect, const QRectF &innerTargetRect, const QRectF &subSourceRect)
void qDrawTiled(VGImage image, const QSize imageSize, const QRectF &targetRect, const QPointF offset, float scaleX, float scaleY)
Combined button and popup list for selecting options.
Definition image.cpp:4
GLenum GLuint texture
GLenum GLuint GLintptr offset
GLdouble GLdouble t
Definition qopenglext.h:243