1/****************************************************************************
2**
3** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qabstracttextureimage.h"
41#include "qabstracttextureimage_p.h"
42#include <Qt3DRender/qtextureimagedatagenerator.h>
43
44QT_BEGIN_NAMESPACE
45
46using namespace Qt3DCore;
47
48namespace Qt3DRender {
49
50/*!
51 \class Qt3DRender::QTextureImageDataGenerator
52 \inmodule Qt3DRender
53 \since 5.7
54 \brief Provides texture image data for QAbstractTextureImage.
55
56 QTextureImageDataGenerator is a data provider for QAbstractTexture.
57 QTextureImageDataGenerator can be used to expand Qt3D with more ways to load
58 texture image data as well as support user-defined formats and formats Qt3D
59 does not natively support. The data is returned by the QTextureImageDataPtr
60 which contains the data that will be loaded to the texture.
61 QTextureImageDataGenerator is executed by Aspect jobs in the backend.
62 */
63/*!
64 \typedef Qt3DRender::QTextureImageDataPtr
65 \relates Qt3DRender::QTextureImageDataGenerator
66
67 Shared pointer to \l QTextureImageData.
68*/
69
70/*!
71 \fn Qt3DRender::QTextureImageDataPtr Qt3DRender::QTextureImageDataGenerator::operator()()
72
73 Implement the method to return the texture image data.
74*/
75
76/*!
77 \fn bool Qt3DRender::QTextureImageDataGenerator::operator ==(const QTextureImageDataGenerator &other) const
78
79 Implement the method to compare this texture data generator to \a other.
80 Returns a boolean that indicates whether the \l QAbstractTextureImage needs to reload
81 the \l QTextureImageData.
82*/
83
84QAbstractTextureImagePrivate::QAbstractTextureImagePrivate()
85 : QNodePrivate(),
86 m_mipLevel(0),
87 m_layer(0),
88 m_face(QAbstractTexture::CubeMapPositiveX)
89{
90}
91
92QAbstractTextureImagePrivate::~QAbstractTextureImagePrivate()
93{
94}
95
96QTextureImageDataGeneratorPtr QAbstractTextureImagePrivate::dataGenerator() const
97{
98 Q_Q(const QAbstractTextureImage);
99 return q->dataGenerator();
100}
101
102/*!
103 \qmltype AbstractTextureImage
104 \instantiates Qt3DRender::QAbstractTextureImage
105 \inherits Node
106 \inqmlmodule Qt3D.Render
107 \qmlabstract
108 \since 5.5
109 \brief Encapsulates the necessary information to create an OpenGL texture image.
110*/
111
112/*!
113 \class Qt3DRender::QAbstractTextureImage
114 \inmodule Qt3DRender
115 \since 5.5
116 \brief Encapsulates the necessary information to create an OpenGL texture image.
117
118 QAbstractTextureImage should be used as the means of providing image data to a
119 QAbstractTexture. It contains the necessary information: mipmap
120 level, layer, cube face load at the proper place data into an OpenGL texture.
121
122 The actual data is provided through a QTextureImageDataGenerator that will be
123 executed by Aspect jobs in the backend. QAbstractTextureImage should be
124 subclassed to provide a functor and eventual additional properties needed by
125 the functor to load actual data.
126
127 \note: QAbstractTextureImage should never be shared. Expect crashes, undefined
128 behavior at best if this rule is not respected.
129 */
130
131/*!
132 \fn Qt3DRender::QTextureImageDataGeneratorPtr Qt3DRender::QAbstractTextureImage::dataGenerator() const
133
134 Implement this method to return the QTextureImageDataGeneratorPtr instance,
135 which will provide the data for the texture image.
136*/
137
138/*!
139 Constructs a new QAbstractTextureImage instance with \a parent as parent.
140 */
141QAbstractTextureImage::QAbstractTextureImage(QNode *parent)
142 : QNode(*new QAbstractTextureImagePrivate, parent)
143{
144}
145
146/*! \internal */
147QAbstractTextureImage::~QAbstractTextureImage()
148{
149}
150
151
152/*!
153 \qmlproperty int Qt3D.Render::AbstractTextureImage::mipLevel
154
155 Holds the mipmap level of the texture image.
156 */
157
158/*!
159 \property Qt3DRender::QAbstractTextureImage::mipLevel
160
161 Holds the mipmap level of the texture image.
162 */
163int QAbstractTextureImage::mipLevel() const
164{
165 Q_D(const QAbstractTextureImage);
166 return d->m_mipLevel;
167}
168
169/*!
170 \qmlproperty int Qt3D.Render::AbstractTextureImage::layer
171
172 Holds the layer of the texture image.
173 */
174
175/*!
176 \property Qt3DRender::QAbstractTextureImage::layer
177
178 \return the layer of the texture image.
179 */
180int QAbstractTextureImage::layer() const
181{
182 Q_D(const QAbstractTextureImage);
183 return d->m_layer;
184}
185
186/*!
187 \qmlproperty enumeration Qt3D.Render::AbstractTextureImage::face
188
189 Holds the cube map face of the texture image.
190
191 \value CubeMapPositiveX 0x8515 GL_TEXTURE_CUBE_MAP_POSITIVE_X
192 \value CubeMapNegativeX 0x8516 GL_TEXTURE_CUBE_MAP_NEGATIVE_X
193 \value CubeMapPositiveY 0x8517 GL_TEXTURE_CUBE_MAP_POSITIVE_Y
194 \value CubeMapNegativeY 0x8518 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
195 \value CubeMapPositiveZ 0x8519 GL_TEXTURE_CUBE_MAP_POSITIVE_Z
196 \value CubeMapNegativeZ 0x851A GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
197
198 \note The cube map face has a meaning only for
199 \l [CPP] {Qt3DRender::QAbstractTexture::}{TargetCubeMap} and
200 \l [CPP] {Qt3DRender::QAbstractTexture::}{TargetCubeMapArray}.
201 */
202
203/*!
204 \property Qt3DRender::QAbstractTextureImage::face
205
206 Holds the cube map face of the texture image.
207
208 \note The cube map face has a meaning only for
209 \l {QAbstractTexture::}{TargetCubeMap} and
210 \l {QAbstractTexture::}{TargetCubeMapArray}.
211 */
212QAbstractTexture::CubeMapFace QAbstractTextureImage::face() const
213{
214 Q_D(const QAbstractTextureImage);
215 return d->m_face;
216}
217
218/*!
219 * Sets the mip level of a texture to \a level.
220 * \param level
221 */
222void QAbstractTextureImage::setMipLevel(int level)
223{
224 Q_D(QAbstractTextureImage);
225 if (level != d->m_mipLevel) {
226 d->m_mipLevel = level;
227 emit mipLevelChanged(mipLevel: level);
228 }
229}
230
231/*!
232 * Sets the layer of a texture to \a layer.
233 * \param layer
234 */
235void QAbstractTextureImage::setLayer(int layer)
236{
237 Q_D(QAbstractTextureImage);
238 if (layer != d->m_layer) {
239 d->m_layer = layer;
240 emit layerChanged(layer);
241 }
242}
243
244/*!
245 * Sets the texture image face to \a face.
246 * \param face
247 */
248void QAbstractTextureImage::setFace(QAbstractTexture::CubeMapFace face)
249{
250 Q_D(QAbstractTextureImage);
251 if (face != d->m_face) {
252 d->m_face = face;
253 emit faceChanged(face);
254 }
255}
256
257/*!
258 Triggers an update of the data generator that is sent to the backend.
259 */
260void QAbstractTextureImage::notifyDataGeneratorChanged()
261{
262 Q_D(QAbstractTextureImage);
263 d->update();
264}
265
266/*! \internal */
267QAbstractTextureImage::QAbstractTextureImage(QAbstractTextureImagePrivate &dd, QNode *parent)
268 : QNode(dd, parent)
269{
270}
271
272Qt3DCore::QNodeCreatedChangeBasePtr QAbstractTextureImage::createNodeCreationChange() const
273{
274 auto creationChange = Qt3DCore::QNodeCreatedChangePtr<QAbstractTextureImageData>::create(arguments: this);
275 auto &data = creationChange->data;
276 Q_D(const QAbstractTextureImage);
277 data.mipLevel = d->m_mipLevel;
278 data.layer = d->m_layer;
279 data.face = d->m_face;
280 data.generator = dataGenerator();
281 return creationChange;
282}
283
284} // namespace Qt3DRender
285
286QT_END_NAMESPACE
287

source code of qt3d/src/render/texture/qabstracttextureimage.cpp