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
qsgopenvgspritenode.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 "qsgopenvgtexture.h"
6
8
10 : m_time(0.0f)
11{
12 // Set Dummy material and geometry to avoid asserts
13 setMaterial((QSGMaterial*)1);
14 setGeometry((QSGGeometry*)1);
15}
16
18{
19 delete m_texture;
20}
21
23{
24 m_texture = static_cast<QSGOpenVGTexture*>(texture);
25 markDirty(DirtyMaterial);
26}
27
29{
30 if (m_time != time) {
31 m_time = time;
32 markDirty(DirtyMaterial);
33 }
34}
35
37{
38 if (m_sourceA != source) {
39 m_sourceA = source;
40 markDirty(DirtyMaterial);
41 }
42}
43
45{
46 if (m_sourceB != source) {
47 m_sourceB = source;
48 markDirty(DirtyMaterial);
49 }
50}
51
53{
54 if (m_spriteSize != size) {
55 m_spriteSize = size;
56 markDirty(DirtyMaterial);
57 }
58}
59
61{
62 if (m_sheetSize != size) {
63 m_sheetSize = size;
64 markDirty(DirtyMaterial);
65 }
66}
67
69{
70 if (m_size != size) {
71 m_size = size;
72 markDirty(DirtyGeometry);
73 }
74}
75
79
83
85{
86 if (!m_texture)
87 return;
88
89 VGImage image = static_cast<VGImage>(m_texture->comparisonKey());
90
91 QRectF sourceRect(m_sourceA, m_spriteSize);
92 QRectF targetRect(0, 0, m_size.width(), m_size.height());
93
94 VGImage sourceImage = vgChildImage(image, sourceRect.x(), sourceRect.y(), sourceRect.width(), sourceRect.height());
95
96 // Set Draw Mode
97 if (opacity() < 1.0) {
98 //Transparent
99 vgSetPaint(opacityPaint(), VG_FILL_PATH);
100 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_MULTIPLY);
101 } else {
102 vgSeti(VG_IMAGE_MODE, VG_DRAW_IMAGE_NORMAL);
103 }
104
105 // Set Image Matrix
106 vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
107 vgLoadMatrix(transform().constData());
108
109 if (sourceRect != targetRect) {
110 // Scale
111 float scaleX = targetRect.width() / sourceRect.width();
112 float scaleY = targetRect.height() / sourceRect.height();
113 vgScale(scaleX, scaleY);
114 }
115
116 vgDrawImage(sourceImage);
117
118 vgDestroyImage(sourceImage);
119}
120
\inmodule QtCore\reentrant
Definition qpoint.h:25
\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
The QSGMaterial class encapsulates rendering state for a shader program.
Definition qsgmaterial.h:15
const QOpenVGMatrix & transform() const
void setTexture(QSGTexture *texture) override
void setSize(const QSizeF &size) override
void setSourceA(const QPoint &source) override
void setSheetSize(const QSize &size) override
void setSourceB(const QPoint &source) override
void setFiltering(QSGTexture::Filtering filtering) override
void setTime(float time) override
void setSpriteSize(const QSize &size) override
qint64 comparisonKey() const override
Returns a key suitable for comparing textures.
\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:208
constexpr qreal width() const noexcept
Returns the width.
Definition qsize.h:332
constexpr qreal height() const noexcept
Returns the height.
Definition qsize.h:335
\inmodule QtCore
Definition qsize.h:25
Combined button and popup list for selecting options.
Definition image.cpp:4
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint texture
GLsizei GLsizei GLchar * source