1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
4 ** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies).
5 ** Contact: https://www.qt.io/licensing/
6 **
7 ** This file is part of the Qt3D module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see https://www.qt.io/terms-conditions. For further
16 ** information use the contact form at https://www.qt.io/contact-us.
17 **
18 ** GNU Lesser General Public License Usage
19 ** Alternatively, this file may be used under the terms of the GNU Lesser
20 ** General Public License version 3 as published by the Free Software
21 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
22 ** packaging of this file. Please review the following information to
23 ** ensure the GNU Lesser General Public License version 3 requirements
24 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25 **
26 ** GNU General Public License Usage
27 ** Alternatively, this file may be used under the terms of the GNU
28 ** General Public License version 2.0 or (at your option) the GNU General
29 ** Public license version 3 or any later version approved by the KDE Free
30 ** Qt Foundation. The licenses are as published by the Free Software
31 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32 ** included in the packaging of this file. Please review the following
33 ** information to ensure the GNU General Public License requirements will
34 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35 ** https://www.gnu.org/licenses/gpl-3.0.html.
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40 
41 #include "qblendequationarguments.h"
42 #include "qblendequationarguments_p.h"
43 #include <Qt3DRender/private/qrenderstatecreatedchange_p.h>
44 
45 QT_BEGIN_NAMESPACE
46 
47 namespace Qt3DRender {
48 
49 /*!
50     \class Qt3DRender::QBlendEquationArguments
51     \inmodule Qt3DRender
52     \since 5.5
53     \brief Encapsulates blending information: specifies how the incoming values (what's going to be drawn)
54     are going to affect the existing values (what is already drawn).
55 
56     OpenGL pre-3.0:     Set the same blend state for all draw buffers
57                         (one QBlendEquationArguments)
58     OpenGL 3.0-pre4.0:  Set the same blend state for all draw buffers,
59                         but can disable blending for particular buffers
60                         (one QBlendEquationArguments for setting glBlendFunc, n QBlendEquationArgumentss
61                          for enabling/disabling Draw Buffers)
62     OpenGL 4.0+:        Can set blend state individually for each draw buffer.
63  */
64 
65 /*!
66     \qmltype BlendEquationArguments
67     \instantiates Qt3DRender::QBlendEquationArguments
68     \inherits RenderState
69     \inqmlmodule Qt3D.Render
70     \since 5.5
71     \brief Encapsulates blending information: specifies how the incoming values (what's going to be drawn)
72     are going to affect the existing values (what is already drawn).
73 
74     OpenGL pre-3.0:     Set the same blend state for all draw buffers
75     OpenGL 3.0-pre4.0:  Set the same blend state for all draw buffers,
76                         but can disable blending for particular buffers
77     OpenGL 4.0+:        Can set blend state individually for each draw buffer.
78 */
79 
80 /*!
81   The constructor creates a new blend state object with the specified \a parent.
82  */
QBlendEquationArguments(QNode * parent)83 QBlendEquationArguments::QBlendEquationArguments(QNode *parent)
84     : QRenderState(*new QBlendEquationArgumentsPrivate, parent)
85 {
86 }
87 
88 /*!
89   \internal
90 */
~QBlendEquationArguments()91 QBlendEquationArguments::~QBlendEquationArguments()
92 {
93 }
94 
95 /*!
96   \internal
97 */
QBlendEquationArguments(QBlendEquationArgumentsPrivate & dd,QNode * parent)98 QBlendEquationArguments::QBlendEquationArguments(QBlendEquationArgumentsPrivate &dd, QNode *parent)
99     : QRenderState(dd, parent)
100 {
101 }
102 
103 /*!
104   \enum Qt3DRender::QBlendEquationArguments::Blending
105 
106   \value Zero GL_ZERO
107   \value One GL_ONE
108   \value SourceColor GL_SRC_COLOR
109   \value SourceAlpha GL_SRC_ALPHA
110   \value Source1Alpha GL_SRC1_ALPHA
111   \value Source1Color GL_SRC1_COLOR
112   \value DestinationColor GL_DST_COLOR
113   \value DestinationAlpha GL_DST_ALPHA
114   \value SourceAlphaSaturate GL_SRC_ALPHA_SATURATE
115   \value ConstantColor 0GL_CONSTANT_COLOR
116   \value ConstantAlpha GL_CONSTANT_ALPHA
117   \value OneMinusSourceColor GL_ONE_MINUS_SRC_COLOR
118   \value OneMinusSourceAlpha GL_ONE_MINUS_SRC_ALPHA
119   \value OneMinusDestinationAlpha GL_ONE_MINUS_DST_ALPHA
120   \value OneMinusDestinationColor GL_ONE_MINUS_DST_COLOR
121   \value OneMinusConstantColor GL_ONE_MINUS_CONSTANT_COLOR
122   \value OneMinusConstantAlpha GL_ONE_MINUS_CONSTANT_ALPHA
123   \value OneMinusSource1Alpha GL_ONE_MINUS_SRC1_ALPHA
124   \value OneMinusSource1Color GL_ONE_MINUS_SRC1_COLOR
125   \value OneMinusSource1Color0 GL_ONE_MINUS_SRC1_COLOR (deprecated)
126 */
127 
128 /*!
129     \qmlproperty enumeration BlendEquationArguments::sourceRgb
130 
131  */
132 
133 /*!
134     \property QBlendEquationArguments::sourceRgb
135 
136  */
sourceRgb() const137 QBlendEquationArguments::Blending QBlendEquationArguments::sourceRgb() const
138 {
139     Q_D(const QBlendEquationArguments);
140     return d->m_sourceRgb;
141 }
142 
setSourceRgb(QBlendEquationArguments::Blending sourceRgb)143 void QBlendEquationArguments::setSourceRgb(QBlendEquationArguments::Blending sourceRgb)
144 {
145     Q_D(QBlendEquationArguments);
146     if (d->m_sourceRgb != sourceRgb) {
147         d->m_sourceRgb = sourceRgb;
148         emit sourceRgbChanged(sourceRgb);
149 
150         if (d->m_sourceAlpha == sourceRgb)
151             emit sourceRgbaChanged(sourceRgb);
152     }
153 }
154 
155 /*!
156     \qmlproperty enumeration BlendEquationArguments::destinationRgb
157 
158  */
159 
160 /*!
161     \property QBlendEquationArguments::destinationRgb
162 
163  */
destinationRgb() const164 QBlendEquationArguments::Blending QBlendEquationArguments::destinationRgb() const
165 {
166     Q_D(const QBlendEquationArguments);
167     return d->m_destinationRgb;
168 }
169 
setDestinationRgb(QBlendEquationArguments::Blending destinationRgb)170 void QBlendEquationArguments::setDestinationRgb(QBlendEquationArguments::Blending destinationRgb)
171 {
172     Q_D(QBlendEquationArguments);
173     if (d->m_destinationRgb != destinationRgb) {
174         d->m_destinationRgb = destinationRgb;
175         emit destinationRgbChanged(destinationRgb);
176 
177         if (d->m_destinationAlpha == destinationRgb)
178             emit destinationRgbaChanged(destinationRgb);
179     }
180 }
181 
182 /*!
183     \qmlproperty enumeration BlendEquationArguments::sourceAlpha
184 
185  */
186 
187 /*!
188     \property QBlendEquationArguments::sourceAlpha
189 
190  */
sourceAlpha() const191 QBlendEquationArguments::Blending QBlendEquationArguments::sourceAlpha() const
192 {
193     Q_D(const QBlendEquationArguments);
194     return d->m_sourceAlpha;
195 }
196 
setSourceAlpha(QBlendEquationArguments::Blending sourceAlpha)197 void QBlendEquationArguments::setSourceAlpha(QBlendEquationArguments::Blending sourceAlpha)
198 {
199     Q_D(QBlendEquationArguments);
200     if (d->m_sourceAlpha != sourceAlpha) {
201         d->m_sourceAlpha = sourceAlpha;
202         emit sourceAlphaChanged(sourceAlpha);
203 
204         if (d->m_sourceRgb == sourceAlpha)
205             emit sourceRgbaChanged(sourceAlpha);
206     }
207 }
208 
209 /*!
210     \qmlproperty enumeration BlendEquationArguments::DestinationAlpha
211 
212  */
213 
214 /*!
215     \property QBlendEquationArguments::destinationAlpha
216 
217  */
destinationAlpha() const218 QBlendEquationArguments::Blending QBlendEquationArguments::destinationAlpha() const
219 {
220     Q_D(const QBlendEquationArguments);
221     return d->m_destinationAlpha;
222 }
223 
setDestinationAlpha(QBlendEquationArguments::Blending destinationAlpha)224 void QBlendEquationArguments::setDestinationAlpha(QBlendEquationArguments::Blending destinationAlpha)
225 {
226     Q_D(QBlendEquationArguments);
227     if (d->m_destinationAlpha != destinationAlpha) {
228         d->m_destinationAlpha = destinationAlpha;
229         emit destinationAlphaChanged(destinationAlpha);
230 
231         if (d->m_destinationRgb == destinationAlpha)
232             emit destinationRgbaChanged(destinationAlpha);
233     }
234 }
235 
236 /*!
237     \fn Qt3DRender::QBlendEquationArguments::sourceRgbaChanged(Blending sourceRgba)
238 
239     Notify that both sourceRgb and sourceAlpha properties have changed to \a sourceRgba.
240 */
241 /*!
242     \fn Qt3DRender::QBlendEquationArguments::destinationRgbaChanged(Blending destinationRgba)
243 
244     Notify that both destinationRgb and destinationAlpha properties have changed to
245     \a destinationRgba.
246 */
247 
248 /*!
249     Change both sourceRgb and sourceAlpha properties to \a sourceRgba.
250 */
setSourceRgba(Blending sourceRgba)251 void QBlendEquationArguments::setSourceRgba(Blending sourceRgba)
252 {
253     setSourceRgb(sourceRgba);
254     setSourceAlpha(sourceRgba);
255 }
256 
257 /*!
258     Change both destinationRgb and destinationAlpha properties to \a destinationRgba.
259 */
setDestinationRgba(Blending destinationRgba)260 void QBlendEquationArguments::setDestinationRgba(Blending destinationRgba)
261 {
262     setDestinationRgb(destinationRgba);
263     setDestinationAlpha(destinationRgba);
264 }
265 
266 /*!
267     \qmlproperty int BlendEquationArguments::bufferIndex
268 
269     Specifies the index of the Draw Buffer that this BlendEquationArguments applies to.
270     If negative, this will apply to all Draw Buffers.
271  */
272 
273 /*!
274     \property QBlendEquationArguments::bufferIndex
275 
276     Specifies the index of the Draw Buffer that this BlendEquationArguments applies to.
277     If negative, this will apply to all Draw Buffers.
278  */
bufferIndex() const279 int QBlendEquationArguments::bufferIndex() const
280 {
281     Q_D(const QBlendEquationArguments);
282     return d->m_bufferIndex;
283 }
284 
setBufferIndex(int bufferIndex)285 void QBlendEquationArguments::setBufferIndex(int bufferIndex)
286 {
287     Q_D(QBlendEquationArguments);
288     if (d->m_bufferIndex != bufferIndex) {
289         d->m_bufferIndex = bufferIndex;
290         emit bufferIndexChanged(bufferIndex);
291     }
292 }
293 
createNodeCreationChange() const294 Qt3DCore::QNodeCreatedChangeBasePtr QBlendEquationArguments::createNodeCreationChange() const
295 {
296     auto creationChange = QRenderStateCreatedChangePtr<QBlendEquationArgumentsData>::create(this);
297     auto &data = creationChange->data;
298     Q_D(const QBlendEquationArguments);
299     data.sourceRgb = d->m_sourceRgb;
300     data.sourceAlpha = d->m_sourceAlpha;
301     data.destinationRgb = d->m_destinationRgb;
302     data.destinationAlpha = d->m_destinationAlpha;
303     data.bufferIndex = d->m_bufferIndex;
304     return creationChange;
305 }
306 
307 } // namespace Qt3DRender
308 
309 QT_END_NAMESPACE
310