1 | // Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qabstracttextureimage.h" |
5 | #include "qabstracttextureimage_p.h" |
6 | #include <Qt3DRender/qtextureimagedatagenerator.h> |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | using namespace Qt3DCore; |
11 | |
12 | namespace Qt3DRender { |
13 | |
14 | QTextureImageDataGenerator::~QTextureImageDataGenerator() = default; |
15 | |
16 | /*! |
17 | \class Qt3DRender::QTextureImageDataGenerator |
18 | \inmodule Qt3DRender |
19 | \since 5.7 |
20 | \brief Provides texture image data for QAbstractTextureImage. |
21 | |
22 | QTextureImageDataGenerator is a data provider for QAbstractTexture. |
23 | QTextureImageDataGenerator can be used to expand Qt3D with more ways to load |
24 | texture image data as well as support user-defined formats and formats Qt3D |
25 | does not natively support. The data is returned by the QTextureImageDataPtr |
26 | which contains the data that will be loaded to the texture. |
27 | QTextureImageDataGenerator is executed by Aspect jobs in the backend. |
28 | */ |
29 | /*! |
30 | \typedef Qt3DRender::QTextureImageDataPtr |
31 | \relates Qt3DRender::QTextureImageDataGenerator |
32 | |
33 | Shared pointer to \l QTextureImageData. |
34 | */ |
35 | |
36 | /*! |
37 | \fn Qt3DRender::QTextureImageDataPtr Qt3DRender::QTextureImageDataGenerator::operator()() |
38 | |
39 | Implement the method to return the texture image data. |
40 | */ |
41 | |
42 | /*! |
43 | \fn bool Qt3DRender::QTextureImageDataGenerator::operator ==(const QTextureImageDataGenerator &other) const |
44 | |
45 | Implement the method to compare this texture data generator to \a other. |
46 | Returns a boolean that indicates whether the \l QAbstractTextureImage needs to reload |
47 | the \l QTextureImageData. |
48 | */ |
49 | |
50 | QAbstractTextureImagePrivate::QAbstractTextureImagePrivate() |
51 | : QNodePrivate(), |
52 | m_mipLevel(0), |
53 | m_layer(0), |
54 | m_face(QAbstractTexture::CubeMapPositiveX) |
55 | { |
56 | } |
57 | |
58 | QAbstractTextureImagePrivate::~QAbstractTextureImagePrivate() |
59 | { |
60 | } |
61 | |
62 | QTextureImageDataGeneratorPtr QAbstractTextureImagePrivate::dataGenerator() const |
63 | { |
64 | Q_Q(const QAbstractTextureImage); |
65 | return q->dataGenerator(); |
66 | } |
67 | |
68 | /*! |
69 | \qmltype AbstractTextureImage |
70 | \instantiates Qt3DRender::QAbstractTextureImage |
71 | \inherits Node |
72 | \inqmlmodule Qt3D.Render |
73 | \qmlabstract |
74 | \since 5.5 |
75 | \brief Encapsulates the necessary information to create an OpenGL texture image. |
76 | */ |
77 | |
78 | /*! |
79 | \class Qt3DRender::QAbstractTextureImage |
80 | \inmodule Qt3DRender |
81 | \since 5.5 |
82 | \brief Encapsulates the necessary information to create an OpenGL texture image. |
83 | |
84 | QAbstractTextureImage should be used as the means of providing image data to a |
85 | QAbstractTexture. It contains the necessary information: mipmap |
86 | level, layer, cube face load at the proper place data into an OpenGL texture. |
87 | |
88 | The actual data is provided through a QTextureImageDataGenerator that will be |
89 | executed by Aspect jobs in the backend. QAbstractTextureImage should be |
90 | subclassed to provide a functor and eventual additional properties needed by |
91 | the functor to load actual data. |
92 | |
93 | \note: QAbstractTextureImage should never be shared. Expect crashes, undefined |
94 | behavior at best if this rule is not respected. |
95 | */ |
96 | |
97 | /*! |
98 | \fn Qt3DRender::QTextureImageDataGeneratorPtr Qt3DRender::QAbstractTextureImage::dataGenerator() const |
99 | |
100 | Implement this method to return the QTextureImageDataGeneratorPtr instance, |
101 | which will provide the data for the texture image. |
102 | */ |
103 | |
104 | /*! |
105 | Constructs a new QAbstractTextureImage instance with \a parent as parent. |
106 | */ |
107 | QAbstractTextureImage::QAbstractTextureImage(QNode *parent) |
108 | : QNode(*new QAbstractTextureImagePrivate, parent) |
109 | { |
110 | } |
111 | |
112 | /*! \internal */ |
113 | QAbstractTextureImage::~QAbstractTextureImage() |
114 | { |
115 | } |
116 | |
117 | |
118 | /*! |
119 | \qmlproperty int Qt3D.Render::AbstractTextureImage::mipLevel |
120 | |
121 | Holds the mipmap level of the texture image. |
122 | */ |
123 | |
124 | /*! |
125 | \property Qt3DRender::QAbstractTextureImage::mipLevel |
126 | |
127 | Holds the mipmap level of the texture image. |
128 | */ |
129 | int QAbstractTextureImage::mipLevel() const |
130 | { |
131 | Q_D(const QAbstractTextureImage); |
132 | return d->m_mipLevel; |
133 | } |
134 | |
135 | /*! |
136 | \qmlproperty int Qt3D.Render::AbstractTextureImage::layer |
137 | |
138 | Holds the layer of the texture image. |
139 | */ |
140 | |
141 | /*! |
142 | \property Qt3DRender::QAbstractTextureImage::layer |
143 | |
144 | \return the layer of the texture image. |
145 | */ |
146 | int QAbstractTextureImage::layer() const |
147 | { |
148 | Q_D(const QAbstractTextureImage); |
149 | return d->m_layer; |
150 | } |
151 | |
152 | /*! |
153 | \qmlproperty enumeration Qt3D.Render::AbstractTextureImage::face |
154 | |
155 | Holds the cube map face of the texture image. |
156 | |
157 | \value CubeMapPositiveX 0x8515 GL_TEXTURE_CUBE_MAP_POSITIVE_X |
158 | \value CubeMapNegativeX 0x8516 GL_TEXTURE_CUBE_MAP_NEGATIVE_X |
159 | \value CubeMapPositiveY 0x8517 GL_TEXTURE_CUBE_MAP_POSITIVE_Y |
160 | \value CubeMapNegativeY 0x8518 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y |
161 | \value CubeMapPositiveZ 0x8519 GL_TEXTURE_CUBE_MAP_POSITIVE_Z |
162 | \value CubeMapNegativeZ 0x851A GL_TEXTURE_CUBE_MAP_NEGATIVE_Z |
163 | |
164 | \note The cube map face has a meaning only for |
165 | \l [CPP] {Qt3DRender::QAbstractTexture::}{TargetCubeMap} and |
166 | \l [CPP] {Qt3DRender::QAbstractTexture::}{TargetCubeMapArray}. |
167 | */ |
168 | |
169 | /*! |
170 | \property Qt3DRender::QAbstractTextureImage::face |
171 | |
172 | Holds the cube map face of the texture image. |
173 | |
174 | \note The cube map face has a meaning only for |
175 | \l {QAbstractTexture::}{TargetCubeMap} and |
176 | \l {QAbstractTexture::}{TargetCubeMapArray}. |
177 | */ |
178 | QAbstractTexture::CubeMapFace QAbstractTextureImage::face() const |
179 | { |
180 | Q_D(const QAbstractTextureImage); |
181 | return d->m_face; |
182 | } |
183 | |
184 | /*! |
185 | * Sets the mip level of a texture to \a level. |
186 | * \param level |
187 | */ |
188 | void QAbstractTextureImage::setMipLevel(int level) |
189 | { |
190 | Q_D(QAbstractTextureImage); |
191 | if (level != d->m_mipLevel) { |
192 | d->m_mipLevel = level; |
193 | emit mipLevelChanged(mipLevel: level); |
194 | } |
195 | } |
196 | |
197 | /*! |
198 | * Sets the layer of a texture to \a layer. |
199 | * \param layer |
200 | */ |
201 | void QAbstractTextureImage::setLayer(int layer) |
202 | { |
203 | Q_D(QAbstractTextureImage); |
204 | if (layer != d->m_layer) { |
205 | d->m_layer = layer; |
206 | emit layerChanged(layer); |
207 | } |
208 | } |
209 | |
210 | /*! |
211 | * Sets the texture image face to \a face. |
212 | * \param face |
213 | */ |
214 | void QAbstractTextureImage::setFace(QAbstractTexture::CubeMapFace face) |
215 | { |
216 | Q_D(QAbstractTextureImage); |
217 | if (face != d->m_face) { |
218 | d->m_face = face; |
219 | emit faceChanged(face); |
220 | } |
221 | } |
222 | |
223 | /*! |
224 | Triggers an update of the data generator that is sent to the backend. |
225 | */ |
226 | void QAbstractTextureImage::notifyDataGeneratorChanged() |
227 | { |
228 | Q_D(QAbstractTextureImage); |
229 | d->update(); |
230 | } |
231 | |
232 | /*! \internal */ |
233 | QAbstractTextureImage::QAbstractTextureImage(QAbstractTextureImagePrivate &dd, QNode *parent) |
234 | : QNode(dd, parent) |
235 | { |
236 | } |
237 | |
238 | } // namespace Qt3DRender |
239 | |
240 | QT_END_NAMESPACE |
241 | |
242 | #include "moc_qabstracttextureimage.cpp" |
243 | |