Kstars

dashedshader.h
1/*
2 SPDX-FileCopyrightText: 2015 The Qt Company Ltd. <https://www.qt.io/licensing/>
3
4 This file is part of the demonstration applications of the Qt Toolkit.
5
6 $QT_BEGIN_LICENSE:LGPL21$
7 Commercial License Usage
8 Licensees holding valid commercial Qt licenses may use this file in
9 accordance with the commercial license agreement provided with the
10 Software or, alternatively, in accordance with the terms contained in
11 a written agreement between you and The Qt Company. For licensing terms
12 and conditions see https://www.qt.io/terms-conditions. For further
13 information use the contact form at https://www.qt.io/contact-us.
14
15 GNU Lesser General Public License Usage
16 Alternatively, this file may be used under the terms of the GNU Lesser
17 General Public License version 2.1 or version 3 as published by the Free
18 Software Foundation and appearing in the file LICENSE.LGPLv21 and
19 LICENSE.LGPLv3 included in the packaging of this file. Please review the
20 following information to ensure the GNU Lesser General Public License
21 requirements will be met: https://www.gnu.org/licenses/lgpl.html and
22 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
24 As a special exception, The Qt Company gives you certain additional
25 rights. These rights are described in The Qt Company LGPL Exception
26 version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27
28 $QT_END_LICENSE$
29
30*/
31
32#pragma once
33
34#include <qguiapplication.h>
35
36#include <qsgmaterial.h>
37#include <qsgnode.h>
38
39#include <qquickitem.h>
40#include <qquickview.h>
41
42#include <qsgsimplerectnode.h>
43
44#include <qsgsimplematerial.h>
45
46//! [1]
47struct State
48{
49 QColor color;
50
51 int compare(const State *other) const
52 {
53 uint rgb = color.rgba();
54 uint otherRgb = other->color.rgba();
55
56 if (rgb == otherRgb)
57 {
58 return 0;
59 }
60 else if (rgb < otherRgb)
61 {
62 return -1;
63 }
64 else
65 {
66 return 1;
67 }
68 }
69};
70//! [1]
71
72//! [2]
73class Shader : public QSGSimpleMaterialShader<State>
74{
76 //! [2] //! [3]
77 public:
78 const char *vertexShader() const
79 {
80 return "attribute highp vec4 aVertex; \n"
81 "attribute highp vec2 aTexCoord; \n"
82 "uniform highp mat4 qt_Matrix; \n"
83 "uniform highp mat4 mvp_matrix; \n"
84 "varying highp vec2 texCoord; \n"
85 "void main() { \n"
86 " gl_Position = qt_Matrix * aVertex; \n"
87 " texCoord = aTexCoord; \n"
88 "}";
89 }
90
91 const char *fragmentShader() const
92 {
93 return "uniform lowp float qt_Opacity; \n"
94 "uniform lowp vec4 color; \n"
95 "varying highp vec2 texCoord; \n"
96 "void main () \n"
97 "{ \n"
98 //"if (cos(0.1*abs(distance(vec2(100.0,100.0).xy, texCoord.xy))) + 0.5 > 0.0) { \n"
99 "if(texCoord.x < 0.1 || texCoord.x > 0.2 && texCoord.x < 0.3) { \n"
100 " gl_FragColor = vec4(0.0,0.0,0.0,0.0) * qt_Opacity; \n"
101 " } else {\n"
102 " gl_FragColor = texCoord.y * texCoord.x * color * qt_Opacity; \n"
103 " }\n"
104 "}";
105 }
106 //! [3] //! [4]
108 {
109 return QList<QByteArray>() << "aVertex"
110 << "aTexCoord";
111 }
112 //! [4] //! [5]
113 void updateState(const State *state, const State *) { program()->setUniformValue(id_color, state->color); }
114 //! [5] //! [6]
115 void resolveUniforms() { id_color = program()->uniformLocation("color"); }
116
117 private:
118 int id_color;
119 //! [6]
120};
121
122//! [7]
124{
125 public:
127 {
128 setGeometry(&m_geometry);
129
130 QSGSimpleMaterial<State> *material = Shader::createMaterial();
134 }
135
136 QSGGeometry m_geometry;
137};
138//! [7]
139
140//! [8]
141class Item : public QQuickItem
142{
144
145 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
146
147 public:
148 Item() { setFlag(ItemHasContents, true); }
149
150 void setColor(const QColor &color)
151 {
152 if (m_color != color)
153 {
154 m_color = color;
155 emit colorChanged();
156 update();
157 }
158 }
159 QColor color() const { return m_color; }
160
161 signals:
162 void colorChanged();
163
164 private:
165 QColor m_color;
166
167 //! [8] //! [9]
168 public:
170 {
171 ColorNode *n = static_cast<ColorNode *>(node);
172 if (!node)
173 n = new ColorNode();
174
176 static_cast<QSGSimpleMaterial<State> *>(n->material())->state()->color = m_color;
177
179
180 return n;
181 }
182};
183
184//#include "simplematerial.moc"
185//! [11]
QSGNode * updatePaintNode(QSGNode *node, UpdatePaintNodeData *)
[8] //! [9]
void resolveUniforms()
[5] //! [6]
QList< QByteArray > attributes() const
[3] //! [4]
const char * vertexShader() const
[2] //! [3]
void updateState(const State *state, const State *)
[4] //! [5]
QRgb rgba() const const
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
virtual QRectF boundingRect() const const
void setFlag(Flag flag, bool enabled)
void update()
QSGGeometry * geometry()
void setGeometry(QSGGeometry *geometry)
const AttributeSet & defaultAttributes_TexturedPoint2D()
void updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &textureRect)
QSGMaterial * material() const const
void setMaterial(QSGMaterial *material)
void setFlag(Flags flags, bool on)
void markDirty(DirtyState bits)
void setFlag(Flag f, bool enabled)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:49:22 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.