Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/opengl/qopengltexture.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB). | - | ||||||||||||
4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the QtGui 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 "qopengltexture.h" | - | ||||||||||||
41 | #include "qopengltexture_p.h" | - | ||||||||||||
42 | #include "qopengltexturehelper_p.h" | - | ||||||||||||
43 | #include "qopenglfunctions.h" | - | ||||||||||||
44 | #include <QtGui/qcolor.h> | - | ||||||||||||
45 | #include <QtGui/qopenglcontext.h> | - | ||||||||||||
46 | #include <private/qobject_p.h> | - | ||||||||||||
47 | #include <private/qopenglcontext_p.h> | - | ||||||||||||
48 | - | |||||||||||||
49 | QT_BEGIN_NAMESPACE | - | ||||||||||||
50 | - | |||||||||||||
51 | //this is to work around GL_TEXTURE_WRAP_R_OES which also has 0x8072 as value | - | ||||||||||||
52 | #if !defined(GL_TEXTURE_WRAP_R) | - | ||||||||||||
53 | #define GL_TEXTURE_WRAP_R 0x8072 | - | ||||||||||||
54 | #endif | - | ||||||||||||
55 | - | |||||||||||||
56 | QOpenGLTexturePrivate::QOpenGLTexturePrivate(QOpenGLTexture::Target textureTarget, | - | ||||||||||||
57 | QOpenGLTexture *qq) | - | ||||||||||||
58 | : q_ptr(qq), | - | ||||||||||||
59 | context(0), | - | ||||||||||||
60 | target(textureTarget), | - | ||||||||||||
61 | textureId(0), | - | ||||||||||||
62 | format(QOpenGLTexture::NoFormat), | - | ||||||||||||
63 | formatClass(QOpenGLTexture::NoFormatClass), | - | ||||||||||||
64 | requestedMipLevels(1), | - | ||||||||||||
65 | mipLevels(-1), | - | ||||||||||||
66 | layers(1), | - | ||||||||||||
67 | faces(1), | - | ||||||||||||
68 | samples(0), | - | ||||||||||||
69 | fixedSamplePositions(true), | - | ||||||||||||
70 | baseLevel(0), | - | ||||||||||||
71 | maxLevel(1000), | - | ||||||||||||
72 | depthStencilMode(QOpenGLTexture::DepthMode), | - | ||||||||||||
73 | comparisonFunction(QOpenGLTexture::CompareLessEqual), | - | ||||||||||||
74 | comparisonMode(QOpenGLTexture::CompareNone), | - | ||||||||||||
75 | minFilter(QOpenGLTexture::Nearest), | - | ||||||||||||
76 | magFilter(QOpenGLTexture::Nearest), | - | ||||||||||||
77 | maxAnisotropy(1.0f), | - | ||||||||||||
78 | minLevelOfDetail(-1000.0f), | - | ||||||||||||
79 | maxLevelOfDetail(1000.0f), | - | ||||||||||||
80 | levelOfDetailBias(0.0f), | - | ||||||||||||
81 | textureView(false), | - | ||||||||||||
82 | autoGenerateMipMaps(true), | - | ||||||||||||
83 | storageAllocated(false), | - | ||||||||||||
84 | texFuncs(0), | - | ||||||||||||
85 | functions(0) | - | ||||||||||||
86 | { | - | ||||||||||||
87 | dimensions[0] = dimensions[1] = dimensions[2] = 1; | - | ||||||||||||
88 | - | |||||||||||||
89 | switch (target) { | - | ||||||||||||
90 | case QOpenGLTexture::Target1D: never executed: case QOpenGLTexture::Target1D: | 0 | ||||||||||||
91 | bindingTarget = QOpenGLTexture::BindingTarget1D; | - | ||||||||||||
92 | break; never executed: break; | 0 | ||||||||||||
93 | case QOpenGLTexture::Target1DArray: never executed: case QOpenGLTexture::Target1DArray: | 0 | ||||||||||||
94 | bindingTarget = QOpenGLTexture::BindingTarget1DArray; | - | ||||||||||||
95 | break; never executed: break; | 0 | ||||||||||||
96 | case QOpenGLTexture::Target2D: never executed: case QOpenGLTexture::Target2D: | 0 | ||||||||||||
97 | bindingTarget = QOpenGLTexture::BindingTarget2D; | - | ||||||||||||
98 | break; never executed: break; | 0 | ||||||||||||
99 | case QOpenGLTexture::Target2DArray: never executed: case QOpenGLTexture::Target2DArray: | 0 | ||||||||||||
100 | bindingTarget = QOpenGLTexture::BindingTarget2DArray; | - | ||||||||||||
101 | break; never executed: break; | 0 | ||||||||||||
102 | case QOpenGLTexture::Target3D: never executed: case QOpenGLTexture::Target3D: | 0 | ||||||||||||
103 | bindingTarget = QOpenGLTexture::BindingTarget3D; | - | ||||||||||||
104 | break; never executed: break; | 0 | ||||||||||||
105 | case QOpenGLTexture::TargetCubeMap: never executed: case QOpenGLTexture::TargetCubeMap: | 0 | ||||||||||||
106 | bindingTarget = QOpenGLTexture::BindingTargetCubeMap; | - | ||||||||||||
107 | faces = 6; | - | ||||||||||||
108 | break; never executed: break; | 0 | ||||||||||||
109 | case QOpenGLTexture::TargetCubeMapArray: never executed: case QOpenGLTexture::TargetCubeMapArray: | 0 | ||||||||||||
110 | bindingTarget = QOpenGLTexture::BindingTargetCubeMapArray; | - | ||||||||||||
111 | faces = 6; | - | ||||||||||||
112 | break; never executed: break; | 0 | ||||||||||||
113 | case QOpenGLTexture::Target2DMultisample: never executed: case QOpenGLTexture::Target2DMultisample: | 0 | ||||||||||||
114 | bindingTarget = QOpenGLTexture::BindingTarget2DMultisample; | - | ||||||||||||
115 | break; never executed: break; | 0 | ||||||||||||
116 | case QOpenGLTexture::Target2DMultisampleArray: never executed: case QOpenGLTexture::Target2DMultisampleArray: | 0 | ||||||||||||
117 | bindingTarget = QOpenGLTexture::BindingTarget2DMultisampleArray; | - | ||||||||||||
118 | break; never executed: break; | 0 | ||||||||||||
119 | case QOpenGLTexture::TargetRectangle: never executed: case QOpenGLTexture::TargetRectangle: | 0 | ||||||||||||
120 | bindingTarget = QOpenGLTexture::BindingTargetRectangle; | - | ||||||||||||
121 | break; never executed: break; | 0 | ||||||||||||
122 | case QOpenGLTexture::TargetBuffer: never executed: case QOpenGLTexture::TargetBuffer: | 0 | ||||||||||||
123 | bindingTarget = QOpenGLTexture::BindingTargetBuffer; | - | ||||||||||||
124 | break; never executed: break; | 0 | ||||||||||||
125 | } | - | ||||||||||||
126 | - | |||||||||||||
127 | swizzleMask[0] = QOpenGLTexture::RedValue; | - | ||||||||||||
128 | swizzleMask[1] = QOpenGLTexture::GreenValue; | - | ||||||||||||
129 | swizzleMask[2] = QOpenGLTexture::BlueValue; | - | ||||||||||||
130 | swizzleMask[3] = QOpenGLTexture::AlphaValue; | - | ||||||||||||
131 | - | |||||||||||||
132 | wrapModes[0] = wrapModes[1] = wrapModes[2] = target == QOpenGLTexture::TargetRectangle
| 0 | ||||||||||||
133 | ? QOpenGLTexture::ClampToEdge : QOpenGLTexture::Repeat; | - | ||||||||||||
134 | } never executed: end of block | 0 | ||||||||||||
135 | - | |||||||||||||
136 | QOpenGLTexturePrivate::~QOpenGLTexturePrivate() | - | ||||||||||||
137 | { | - | ||||||||||||
138 | destroy(); | - | ||||||||||||
139 | } | - | ||||||||||||
140 | - | |||||||||||||
141 | void QOpenGLTexturePrivate::initializeOpenGLFunctions() | - | ||||||||||||
142 | { | - | ||||||||||||
143 | // If we already have a functions object, there is nothing to do | - | ||||||||||||
144 | if (texFuncs) | - | ||||||||||||
145 | return; | - | ||||||||||||
146 | - | |||||||||||||
147 | // See if the context already has a suitable resource we can use. | - | ||||||||||||
148 | // If not create a functions object and add it to the context in case | - | ||||||||||||
149 | // others wish to use it too | - | ||||||||||||
150 | texFuncs = context->textureFunctions(); | - | ||||||||||||
151 | if (!texFuncs) { | - | ||||||||||||
152 | texFuncs = new QOpenGLTextureHelper(context); | - | ||||||||||||
153 | context->setTextureFunctions(texFuncs); | - | ||||||||||||
154 | } | - | ||||||||||||
155 | } | - | ||||||||||||
156 | - | |||||||||||||
157 | bool QOpenGLTexturePrivate::create() | - | ||||||||||||
158 | { | - | ||||||||||||
159 | if (textureId != 0)
| 0 | ||||||||||||
160 | return true; never executed: return true; | 0 | ||||||||||||
161 | - | |||||||||||||
162 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - | ||||||||||||
163 | if (!ctx) {
| 0 | ||||||||||||
164 | qWarning("Requires a valid current OpenGL context.\n" | - | ||||||||||||
165 | "Texture has not been created"); | - | ||||||||||||
166 | return false; never executed: return false; | 0 | ||||||||||||
167 | } | - | ||||||||||||
168 | context = ctx; | - | ||||||||||||
169 | functions = ctx->functions(); | - | ||||||||||||
170 | - | |||||||||||||
171 | // Resolve any functions we will need based upon context version and create the texture | - | ||||||||||||
172 | initializeOpenGLFunctions(); | - | ||||||||||||
173 | - | |||||||||||||
174 | // What features do we have? | - | ||||||||||||
175 | QOpenGLTexture::Feature feature = QOpenGLTexture::ImmutableStorage; | - | ||||||||||||
176 | while (feature != QOpenGLTexture::MaxFeatureFlag) {
| 0 | ||||||||||||
177 | if (QOpenGLTexture::hasFeature(feature))
| 0 | ||||||||||||
178 | features |= feature; never executed: features |= feature; | 0 | ||||||||||||
179 | feature = static_cast<QOpenGLTexture::Feature>(feature << 1); | - | ||||||||||||
180 | } never executed: end of block | 0 | ||||||||||||
181 | - | |||||||||||||
182 | texFuncsfunctions->glGenTextures(1, &textureId); | - | ||||||||||||
183 | return textureId != 0; never executed: return textureId != 0; | 0 | ||||||||||||
184 | } | - | ||||||||||||
185 | - | |||||||||||||
186 | void QOpenGLTexturePrivate::destroy() | - | ||||||||||||
187 | { | - | ||||||||||||
188 | if (!textureId) {
| 0 | ||||||||||||
189 | // not created or already destroyed | - | ||||||||||||
190 | return; never executed: return; | 0 | ||||||||||||
191 | } | - | ||||||||||||
192 | QOpenGLContext *currentContext = QOpenGLContext::currentContext(); | - | ||||||||||||
193 | if (!currentContext || !QOpenGLContext::areSharing(currentContext, context)) {
| 0 | ||||||||||||
194 | qWarning("Texture is not valid in the current context.\n" | - | ||||||||||||
195 | "Texture has not been destroyed"); | - | ||||||||||||
196 | return; never executed: return; | 0 | ||||||||||||
197 | } | - | ||||||||||||
198 | - | |||||||||||||
199 | texFuncsfunctions->glDeleteTextures(1, &textureId); | - | ||||||||||||
200 | - | |||||||||||||
201 | context = 0; | - | ||||||||||||
202 | functions = 0; | - | ||||||||||||
203 | textureId = 0; | - | ||||||||||||
204 | format = QOpenGLTexture::NoFormat; | - | ||||||||||||
205 | formatClass = QOpenGLTexture::NoFormatClass; | - | ||||||||||||
206 | requestedMipLevels = 1; | - | ||||||||||||
207 | mipLevels = -1; | - | ||||||||||||
208 | layers = 1; | - | ||||||||||||
209 | faces = 1; | - | ||||||||||||
210 | samples = 0; | - | ||||||||||||
211 | fixedSamplePositions = true, | - | ||||||||||||
212 | baseLevel = 0; | - | ||||||||||||
213 | maxLevel = 1000; | - | ||||||||||||
214 | depthStencilMode = QOpenGLTexture::DepthMode; | - | ||||||||||||
215 | minFilter = QOpenGLTexture::Nearest; | - | ||||||||||||
216 | magFilter = QOpenGLTexture::Nearest; | - | ||||||||||||
217 | maxAnisotropy = 1.0f; | - | ||||||||||||
218 | minLevelOfDetail = -1000.0f; | - | ||||||||||||
219 | maxLevelOfDetail = 1000.0f; | - | ||||||||||||
220 | levelOfDetailBias = 0.0f; | - | ||||||||||||
221 | textureView = false; | - | ||||||||||||
222 | autoGenerateMipMaps = true; | - | ||||||||||||
223 | storageAllocated = false; | - | ||||||||||||
224 | texFuncs = 0; | - | ||||||||||||
225 | - | |||||||||||||
226 | swizzleMask[0] = QOpenGLTexture::RedValue; | - | ||||||||||||
227 | swizzleMask[1] = QOpenGLTexture::GreenValue; | - | ||||||||||||
228 | swizzleMask[2] = QOpenGLTexture::BlueValue; | - | ||||||||||||
229 | swizzleMask[3] = QOpenGLTexture::AlphaValue; | - | ||||||||||||
230 | - | |||||||||||||
231 | wrapModes[0] = wrapModes[1] = wrapModes[2] = target == QOpenGLTexture::TargetRectangle
| 0 | ||||||||||||
232 | ? QOpenGLTexture::ClampToEdge : QOpenGLTexture::Repeat; | - | ||||||||||||
233 | } never executed: end of block | 0 | ||||||||||||
234 | - | |||||||||||||
235 | void QOpenGLTexturePrivate::bind() | - | ||||||||||||
236 | { | - | ||||||||||||
237 | texFuncsfunctions->glBindTexture(target, textureId); | - | ||||||||||||
238 | } never executed: end of block | 0 | ||||||||||||
239 | - | |||||||||||||
240 | void QOpenGLTexturePrivate::bind(uint unit, QOpenGLTexture::TextureUnitReset reset) | - | ||||||||||||
241 | { | - | ||||||||||||
242 | GLint oldTextureUnit = 0; | - | ||||||||||||
243 | if (reset == QOpenGLTexture::ResetTextureUnit)
| 0 | ||||||||||||
244 | texFuncsfunctions->glGetIntegerv(GL_ACTIVE_TEXTURE, &oldTextureUnit); never executed: functions->glGetIntegerv(0x84E0, &oldTextureUnit); | 0 | ||||||||||||
245 | - | |||||||||||||
246 | texFuncs->glActiveTexture(GL_TEXTURE0 + unit); | - | ||||||||||||
247 | texFuncsfunctions->glBindTexture(target, textureId); | - | ||||||||||||
248 | - | |||||||||||||
249 | if (reset == QOpenGLTexture::ResetTextureUnit)
| 0 | ||||||||||||
250 | texFuncs->glActiveTexture(GL_TEXTURE0 + oldTextureUnit); never executed: texFuncs->glActiveTexture(0x84C0 + oldTextureUnit); | 0 | ||||||||||||
251 | } never executed: end of block | 0 | ||||||||||||
252 | - | |||||||||||||
253 | void QOpenGLTexturePrivate::release() | - | ||||||||||||
254 | { | - | ||||||||||||
255 | texFuncsfunctions->glBindTexture(target, 0); | - | ||||||||||||
256 | } never executed: end of block | 0 | ||||||||||||
257 | - | |||||||||||||
258 | void QOpenGLTexturePrivate::release(uint unit, QOpenGLTexture::TextureUnitReset reset) | - | ||||||||||||
259 | { | - | ||||||||||||
260 | GLint oldTextureUnit = 0; | - | ||||||||||||
261 | if (reset == QOpenGLTexture::ResetTextureUnit)
| 0 | ||||||||||||
262 | texFuncsfunctions->glGetIntegerv(GL_ACTIVE_TEXTURE, &oldTextureUnit); never executed: functions->glGetIntegerv(0x84E0, &oldTextureUnit); | 0 | ||||||||||||
263 | - | |||||||||||||
264 | texFuncs->glActiveTexture(GL_TEXTURE0 + unit); | - | ||||||||||||
265 | texFuncsfunctions->glBindTexture(target, 0); | - | ||||||||||||
266 | - | |||||||||||||
267 | if (reset == QOpenGLTexture::ResetTextureUnit)
| 0 | ||||||||||||
268 | texFuncs->glActiveTexture(GL_TEXTURE0 + oldTextureUnit); never executed: texFuncs->glActiveTexture(0x84C0 + oldTextureUnit); | 0 | ||||||||||||
269 | } never executed: end of block | 0 | ||||||||||||
270 | - | |||||||||||||
271 | bool QOpenGLTexturePrivate::isBound() const | - | ||||||||||||
272 | { | - | ||||||||||||
273 | GLint boundTextureId = 0; | - | ||||||||||||
274 | texFuncsfunctions->glGetIntegerv(bindingTarget, &boundTextureId); | - | ||||||||||||
275 | return (static_cast<GLuint>(boundTextureId) == textureId); never executed: return (static_cast<GLuint>(boundTextureId) == textureId); | 0 | ||||||||||||
276 | } | - | ||||||||||||
277 | - | |||||||||||||
278 | bool QOpenGLTexturePrivate::isBound(uint unit) const | - | ||||||||||||
279 | { | - | ||||||||||||
280 | GLint oldTextureUnit = 0; | - | ||||||||||||
281 | texFuncsfunctions->glGetIntegerv(GL_ACTIVE_TEXTURE, &oldTextureUnit); | - | ||||||||||||
282 | - | |||||||||||||
283 | GLint boundTextureId = 0; | - | ||||||||||||
284 | texFuncs->glActiveTexture(GL_TEXTURE0 + unit); | - | ||||||||||||
285 | texFuncsfunctions->glGetIntegerv(bindingTarget, &boundTextureId); | - | ||||||||||||
286 | bool result = (static_cast<GLuint>(boundTextureId) == textureId); | - | ||||||||||||
287 | - | |||||||||||||
288 | texFuncs->glActiveTexture(GL_TEXTURE0 + oldTextureUnit); | - | ||||||||||||
289 | return result; never executed: return result; | 0 | ||||||||||||
290 | } | - | ||||||||||||
291 | - | |||||||||||||
292 | int QOpenGLTexturePrivate::evaluateMipLevels() const | - | ||||||||||||
293 | { | - | ||||||||||||
294 | switch (target) { | - | ||||||||||||
295 | case QOpenGLTexture::Target1D: | - | ||||||||||||
296 | case QOpenGLTexture::Target1DArray: | - | ||||||||||||
297 | case QOpenGLTexture::Target2D: | - | ||||||||||||
298 | case QOpenGLTexture::Target2DArray: | - | ||||||||||||
299 | case QOpenGLTexture::Target3D: | - | ||||||||||||
300 | case QOpenGLTexture::TargetCubeMap: | - | ||||||||||||
301 | case QOpenGLTexture::TargetCubeMapArray: | - | ||||||||||||
302 | return qMin(maximumMipLevelCount(), qMax(1, requestedMipLevels)); | - | ||||||||||||
303 | - | |||||||||||||
304 | case QOpenGLTexture::TargetRectangle: | - | ||||||||||||
305 | case QOpenGLTexture::Target2DMultisample: | - | ||||||||||||
306 | case QOpenGLTexture::Target2DMultisampleArray: | - | ||||||||||||
307 | case QOpenGLTexture::TargetBuffer: | - | ||||||||||||
308 | default: | - | ||||||||||||
309 | return 1; | - | ||||||||||||
310 | } | - | ||||||||||||
311 | } | - | ||||||||||||
312 | - | |||||||||||||
313 | static bool isSizedTextureFormat(QOpenGLTexture::TextureFormat internalFormat) | - | ||||||||||||
314 | { | - | ||||||||||||
315 | switch (internalFormat) { | - | ||||||||||||
316 | case QOpenGLTexture::NoFormat: | - | ||||||||||||
317 | return false; | - | ||||||||||||
318 | - | |||||||||||||
319 | case QOpenGLTexture::R8_UNorm: | - | ||||||||||||
320 | case QOpenGLTexture::RG8_UNorm: | - | ||||||||||||
321 | case QOpenGLTexture::RGB8_UNorm: | - | ||||||||||||
322 | case QOpenGLTexture::RGBA8_UNorm: | - | ||||||||||||
323 | case QOpenGLTexture::R16_UNorm: | - | ||||||||||||
324 | case QOpenGLTexture::RG16_UNorm: | - | ||||||||||||
325 | case QOpenGLTexture::RGB16_UNorm: | - | ||||||||||||
326 | case QOpenGLTexture::RGBA16_UNorm: | - | ||||||||||||
327 | case QOpenGLTexture::R8_SNorm: | - | ||||||||||||
328 | case QOpenGLTexture::RG8_SNorm: | - | ||||||||||||
329 | case QOpenGLTexture::RGB8_SNorm: | - | ||||||||||||
330 | case QOpenGLTexture::RGBA8_SNorm: | - | ||||||||||||
331 | case QOpenGLTexture::R16_SNorm: | - | ||||||||||||
332 | case QOpenGLTexture::RG16_SNorm: | - | ||||||||||||
333 | case QOpenGLTexture::RGB16_SNorm: | - | ||||||||||||
334 | case QOpenGLTexture::RGBA16_SNorm: | - | ||||||||||||
335 | case QOpenGLTexture::R8U: | - | ||||||||||||
336 | case QOpenGLTexture::RG8U: | - | ||||||||||||
337 | case QOpenGLTexture::RGB8U: | - | ||||||||||||
338 | case QOpenGLTexture::RGBA8U: | - | ||||||||||||
339 | case QOpenGLTexture::R16U: | - | ||||||||||||
340 | case QOpenGLTexture::RG16U: | - | ||||||||||||
341 | case QOpenGLTexture::RGB16U: | - | ||||||||||||
342 | case QOpenGLTexture::RGBA16U: | - | ||||||||||||
343 | case QOpenGLTexture::R32U: | - | ||||||||||||
344 | case QOpenGLTexture::RG32U: | - | ||||||||||||
345 | case QOpenGLTexture::RGB32U: | - | ||||||||||||
346 | case QOpenGLTexture::RGBA32U: | - | ||||||||||||
347 | case QOpenGLTexture::R8I: | - | ||||||||||||
348 | case QOpenGLTexture::RG8I: | - | ||||||||||||
349 | case QOpenGLTexture::RGB8I: | - | ||||||||||||
350 | case QOpenGLTexture::RGBA8I: | - | ||||||||||||
351 | case QOpenGLTexture::R16I: | - | ||||||||||||
352 | case QOpenGLTexture::RG16I: | - | ||||||||||||
353 | case QOpenGLTexture::RGB16I: | - | ||||||||||||
354 | case QOpenGLTexture::RGBA16I: | - | ||||||||||||
355 | case QOpenGLTexture::R32I: | - | ||||||||||||
356 | case QOpenGLTexture::RG32I: | - | ||||||||||||
357 | case QOpenGLTexture::RGB32I: | - | ||||||||||||
358 | case QOpenGLTexture::RGBA32I: | - | ||||||||||||
359 | case QOpenGLTexture::R16F: | - | ||||||||||||
360 | case QOpenGLTexture::RG16F: | - | ||||||||||||
361 | case QOpenGLTexture::RGB16F: | - | ||||||||||||
362 | case QOpenGLTexture::RGBA16F: | - | ||||||||||||
363 | case QOpenGLTexture::R32F: | - | ||||||||||||
364 | case QOpenGLTexture::RG32F: | - | ||||||||||||
365 | case QOpenGLTexture::RGB32F: | - | ||||||||||||
366 | case QOpenGLTexture::RGBA32F: | - | ||||||||||||
367 | case QOpenGLTexture::RGB9E5: | - | ||||||||||||
368 | case QOpenGLTexture::RG11B10F: | - | ||||||||||||
369 | case QOpenGLTexture::RG3B2: | - | ||||||||||||
370 | case QOpenGLTexture::R5G6B5: | - | ||||||||||||
371 | case QOpenGLTexture::RGB5A1: | - | ||||||||||||
372 | case QOpenGLTexture::RGBA4: | - | ||||||||||||
373 | case QOpenGLTexture::RGB10A2: | - | ||||||||||||
374 | - | |||||||||||||
375 | case QOpenGLTexture::D16: | - | ||||||||||||
376 | case QOpenGLTexture::D24: | - | ||||||||||||
377 | case QOpenGLTexture::D32: | - | ||||||||||||
378 | case QOpenGLTexture::D32F: | - | ||||||||||||
379 | - | |||||||||||||
380 | case QOpenGLTexture::D24S8: | - | ||||||||||||
381 | case QOpenGLTexture::D32FS8X24: | - | ||||||||||||
382 | - | |||||||||||||
383 | case QOpenGLTexture::S8: | - | ||||||||||||
384 | - | |||||||||||||
385 | case QOpenGLTexture::RGB_DXT1: | - | ||||||||||||
386 | case QOpenGLTexture::RGBA_DXT1: | - | ||||||||||||
387 | case QOpenGLTexture::RGBA_DXT3: | - | ||||||||||||
388 | case QOpenGLTexture::RGBA_DXT5: | - | ||||||||||||
389 | case QOpenGLTexture::R_ATI1N_UNorm: | - | ||||||||||||
390 | case QOpenGLTexture::R_ATI1N_SNorm: | - | ||||||||||||
391 | case QOpenGLTexture::RG_ATI2N_UNorm: | - | ||||||||||||
392 | case QOpenGLTexture::RG_ATI2N_SNorm: | - | ||||||||||||
393 | case QOpenGLTexture::RGB_BP_UNSIGNED_FLOAT: | - | ||||||||||||
394 | case QOpenGLTexture::RGB_BP_SIGNED_FLOAT: | - | ||||||||||||
395 | case QOpenGLTexture::RGB_BP_UNorm: | - | ||||||||||||
396 | case QOpenGLTexture::SRGB8: | - | ||||||||||||
397 | case QOpenGLTexture::SRGB8_Alpha8: | - | ||||||||||||
398 | case QOpenGLTexture::SRGB_DXT1: | - | ||||||||||||
399 | case QOpenGLTexture::SRGB_Alpha_DXT1: | - | ||||||||||||
400 | case QOpenGLTexture::SRGB_Alpha_DXT3: | - | ||||||||||||
401 | case QOpenGLTexture::SRGB_Alpha_DXT5: | - | ||||||||||||
402 | case QOpenGLTexture::SRGB_BP_UNorm: | - | ||||||||||||
403 | case QOpenGLTexture::R11_EAC_UNorm: | - | ||||||||||||
404 | case QOpenGLTexture::R11_EAC_SNorm: | - | ||||||||||||
405 | case QOpenGLTexture::RG11_EAC_UNorm: | - | ||||||||||||
406 | case QOpenGLTexture::RG11_EAC_SNorm: | - | ||||||||||||
407 | case QOpenGLTexture::RGB8_ETC2: | - | ||||||||||||
408 | case QOpenGLTexture::SRGB8_ETC2: | - | ||||||||||||
409 | case QOpenGLTexture::RGB8_PunchThrough_Alpha1_ETC2: | - | ||||||||||||
410 | case QOpenGLTexture::SRGB8_PunchThrough_Alpha1_ETC2: | - | ||||||||||||
411 | case QOpenGLTexture::RGBA8_ETC2_EAC: | - | ||||||||||||
412 | case QOpenGLTexture::SRGB8_Alpha8_ETC2_EAC: | - | ||||||||||||
413 | return true; | - | ||||||||||||
414 | - | |||||||||||||
415 | case QOpenGLTexture::RGB8_ETC1: | - | ||||||||||||
416 | return false; | - | ||||||||||||
417 | - | |||||||||||||
418 | case QOpenGLTexture::DepthFormat: | - | ||||||||||||
419 | case QOpenGLTexture::AlphaFormat: | - | ||||||||||||
420 | - | |||||||||||||
421 | case QOpenGLTexture::RGBFormat: | - | ||||||||||||
422 | case QOpenGLTexture::RGBAFormat: | - | ||||||||||||
423 | - | |||||||||||||
424 | case QOpenGLTexture::LuminanceFormat: | - | ||||||||||||
425 | - | |||||||||||||
426 | case QOpenGLTexture::LuminanceAlphaFormat: | - | ||||||||||||
427 | return false; | - | ||||||||||||
428 | } | - | ||||||||||||
429 | - | |||||||||||||
430 | Q_UNREACHABLE(); | - | ||||||||||||
431 | return false; | - | ||||||||||||
432 | } | - | ||||||||||||
433 | - | |||||||||||||
434 | static bool isTextureTargetMultisample(QOpenGLTexture::Target target) | - | ||||||||||||
435 | { | - | ||||||||||||
436 | switch (target) { | - | ||||||||||||
437 | case QOpenGLTexture::Target1D: | - | ||||||||||||
438 | case QOpenGLTexture::Target1DArray: | - | ||||||||||||
439 | case QOpenGLTexture::Target2D: | - | ||||||||||||
440 | case QOpenGLTexture::Target2DArray: | - | ||||||||||||
441 | case QOpenGLTexture::Target3D: | - | ||||||||||||
442 | case QOpenGLTexture::TargetCubeMap: | - | ||||||||||||
443 | case QOpenGLTexture::TargetCubeMapArray: | - | ||||||||||||
444 | return false; | - | ||||||||||||
445 | - | |||||||||||||
446 | case QOpenGLTexture::Target2DMultisample: | - | ||||||||||||
447 | case QOpenGLTexture::Target2DMultisampleArray: | - | ||||||||||||
448 | return true; | - | ||||||||||||
449 | - | |||||||||||||
450 | case QOpenGLTexture::TargetRectangle: | - | ||||||||||||
451 | case QOpenGLTexture::TargetBuffer: | - | ||||||||||||
452 | return false; | - | ||||||||||||
453 | } | - | ||||||||||||
454 | - | |||||||||||||
455 | Q_UNREACHABLE(); | - | ||||||||||||
456 | return false; | - | ||||||||||||
457 | } | - | ||||||||||||
458 | - | |||||||||||||
459 | bool QOpenGLTexturePrivate::isUsingImmutableStorage() const | - | ||||||||||||
460 | { | - | ||||||||||||
461 | // Use immutable storage whenever possible, falling back to mutable | - | ||||||||||||
462 | // Note that if multisample textures are not supported at all, we'll still fail into | - | ||||||||||||
463 | // the mutable storage allocation | - | ||||||||||||
464 | return isSizedTextureFormat(format) | - | ||||||||||||
465 | && (isTextureTargetMultisample(target) | - | ||||||||||||
466 | ? features.testFlag(QOpenGLTexture::ImmutableMultisampleStorage) | - | ||||||||||||
467 | : features.testFlag(QOpenGLTexture::ImmutableStorage)); | - | ||||||||||||
468 | } | - | ||||||||||||
469 | - | |||||||||||||
470 | void QOpenGLTexturePrivate::allocateStorage(QOpenGLTexture::PixelFormat pixelFormat, QOpenGLTexture::PixelType pixelType) | - | ||||||||||||
471 | { | - | ||||||||||||
472 | // Resolve the actual number of mipmap levels we can use | - | ||||||||||||
473 | mipLevels = evaluateMipLevels(); | - | ||||||||||||
474 | - | |||||||||||||
475 | if (isUsingImmutableStorage()) | - | ||||||||||||
476 | allocateImmutableStorage(); | - | ||||||||||||
477 | else | - | ||||||||||||
478 | allocateMutableStorage(pixelFormat, pixelType); | - | ||||||||||||
479 | } | - | ||||||||||||
480 | - | |||||||||||||
481 | static QOpenGLTexture::PixelFormat pixelFormatCompatibleWithInternalFormat(QOpenGLTexture::TextureFormat internalFormat) | - | ||||||||||||
482 | { | - | ||||||||||||
483 | switch (internalFormat) { | - | ||||||||||||
484 | case QOpenGLTexture::NoFormat: | - | ||||||||||||
485 | return QOpenGLTexture::NoSourceFormat; | - | ||||||||||||
486 | - | |||||||||||||
487 | case QOpenGLTexture::R8_UNorm: | - | ||||||||||||
488 | return QOpenGLTexture::Red; | - | ||||||||||||
489 | - | |||||||||||||
490 | case QOpenGLTexture::RG8_UNorm: | - | ||||||||||||
491 | return QOpenGLTexture::RG; | - | ||||||||||||
492 | - | |||||||||||||
493 | case QOpenGLTexture::RGB8_UNorm: | - | ||||||||||||
494 | return QOpenGLTexture::RGB; | - | ||||||||||||
495 | - | |||||||||||||
496 | case QOpenGLTexture::RGBA8_UNorm: | - | ||||||||||||
497 | return QOpenGLTexture::RGBA; | - | ||||||||||||
498 | - | |||||||||||||
499 | case QOpenGLTexture::R16_UNorm: | - | ||||||||||||
500 | return QOpenGLTexture::Red; | - | ||||||||||||
501 | - | |||||||||||||
502 | case QOpenGLTexture::RG16_UNorm: | - | ||||||||||||
503 | return QOpenGLTexture::RG; | - | ||||||||||||
504 | - | |||||||||||||
505 | case QOpenGLTexture::RGB16_UNorm: | - | ||||||||||||
506 | return QOpenGLTexture::RGB; | - | ||||||||||||
507 | - | |||||||||||||
508 | case QOpenGLTexture::RGBA16_UNorm: | - | ||||||||||||
509 | return QOpenGLTexture::RGBA; | - | ||||||||||||
510 | - | |||||||||||||
511 | case QOpenGLTexture::R8_SNorm: | - | ||||||||||||
512 | return QOpenGLTexture::Red; | - | ||||||||||||
513 | - | |||||||||||||
514 | case QOpenGLTexture::RG8_SNorm: | - | ||||||||||||
515 | return QOpenGLTexture::RG; | - | ||||||||||||
516 | - | |||||||||||||
517 | case QOpenGLTexture::RGB8_SNorm: | - | ||||||||||||
518 | return QOpenGLTexture::RGB; | - | ||||||||||||
519 | - | |||||||||||||
520 | case QOpenGLTexture::RGBA8_SNorm: | - | ||||||||||||
521 | return QOpenGLTexture::RGBA; | - | ||||||||||||
522 | - | |||||||||||||
523 | case QOpenGLTexture::R16_SNorm: | - | ||||||||||||
524 | return QOpenGLTexture::Red; | - | ||||||||||||
525 | - | |||||||||||||
526 | case QOpenGLTexture::RG16_SNorm: | - | ||||||||||||
527 | return QOpenGLTexture::RG; | - | ||||||||||||
528 | - | |||||||||||||
529 | case QOpenGLTexture::RGB16_SNorm: | - | ||||||||||||
530 | return QOpenGLTexture::RGB; | - | ||||||||||||
531 | - | |||||||||||||
532 | case QOpenGLTexture::RGBA16_SNorm: | - | ||||||||||||
533 | return QOpenGLTexture::RGBA; | - | ||||||||||||
534 | - | |||||||||||||
535 | case QOpenGLTexture::R8U: | - | ||||||||||||
536 | return QOpenGLTexture::Red_Integer; | - | ||||||||||||
537 | - | |||||||||||||
538 | case QOpenGLTexture::RG8U: | - | ||||||||||||
539 | return QOpenGLTexture::RG_Integer; | - | ||||||||||||
540 | - | |||||||||||||
541 | case QOpenGLTexture::RGB8U: | - | ||||||||||||
542 | return QOpenGLTexture::RGB_Integer; | - | ||||||||||||
543 | - | |||||||||||||
544 | case QOpenGLTexture::RGBA8U: | - | ||||||||||||
545 | return QOpenGLTexture::RGBA_Integer; | - | ||||||||||||
546 | - | |||||||||||||
547 | case QOpenGLTexture::R16U: | - | ||||||||||||
548 | return QOpenGLTexture::Red_Integer; | - | ||||||||||||
549 | - | |||||||||||||
550 | case QOpenGLTexture::RG16U: | - | ||||||||||||
551 | return QOpenGLTexture::RG_Integer; | - | ||||||||||||
552 | - | |||||||||||||
553 | case QOpenGLTexture::RGB16U: | - | ||||||||||||
554 | return QOpenGLTexture::RGB_Integer; | - | ||||||||||||
555 | - | |||||||||||||
556 | case QOpenGLTexture::RGBA16U: | - | ||||||||||||
557 | return QOpenGLTexture::RGBA_Integer; | - | ||||||||||||
558 | - | |||||||||||||
559 | case QOpenGLTexture::R32U: | - | ||||||||||||
560 | return QOpenGLTexture::Red_Integer; | - | ||||||||||||
561 | - | |||||||||||||
562 | case QOpenGLTexture::RG32U: | - | ||||||||||||
563 | return QOpenGLTexture::RG_Integer; | - | ||||||||||||
564 | - | |||||||||||||
565 | case QOpenGLTexture::RGB32U: | - | ||||||||||||
566 | return QOpenGLTexture::RGB_Integer; | - | ||||||||||||
567 | - | |||||||||||||
568 | case QOpenGLTexture::RGBA32U: | - | ||||||||||||
569 | return QOpenGLTexture::RGBA_Integer; | - | ||||||||||||
570 | - | |||||||||||||
571 | case QOpenGLTexture::R8I: | - | ||||||||||||
572 | return QOpenGLTexture::Red_Integer; | - | ||||||||||||
573 | - | |||||||||||||
574 | case QOpenGLTexture::RG8I: | - | ||||||||||||
575 | return QOpenGLTexture::RG_Integer; | - | ||||||||||||
576 | - | |||||||||||||
577 | case QOpenGLTexture::RGB8I: | - | ||||||||||||
578 | return QOpenGLTexture::RGB_Integer; | - | ||||||||||||
579 | - | |||||||||||||
580 | case QOpenGLTexture::RGBA8I: | - | ||||||||||||
581 | return QOpenGLTexture::RGBA_Integer; | - | ||||||||||||
582 | - | |||||||||||||
583 | case QOpenGLTexture::R16I: | - | ||||||||||||
584 | return QOpenGLTexture::Red_Integer; | - | ||||||||||||
585 | - | |||||||||||||
586 | case QOpenGLTexture::RG16I: | - | ||||||||||||
587 | return QOpenGLTexture::RG_Integer; | - | ||||||||||||
588 | - | |||||||||||||
589 | case QOpenGLTexture::RGB16I: | - | ||||||||||||
590 | return QOpenGLTexture::RGB_Integer; | - | ||||||||||||
591 | - | |||||||||||||
592 | case QOpenGLTexture::RGBA16I: | - | ||||||||||||
593 | return QOpenGLTexture::RGBA_Integer; | - | ||||||||||||
594 | - | |||||||||||||
595 | case QOpenGLTexture::R32I: | - | ||||||||||||
596 | return QOpenGLTexture::Red_Integer; | - | ||||||||||||
597 | - | |||||||||||||
598 | case QOpenGLTexture::RG32I: | - | ||||||||||||
599 | return QOpenGLTexture::RG_Integer; | - | ||||||||||||
600 | - | |||||||||||||
601 | case QOpenGLTexture::RGB32I: | - | ||||||||||||
602 | return QOpenGLTexture::RGB_Integer; | - | ||||||||||||
603 | - | |||||||||||||
604 | case QOpenGLTexture::RGBA32I: | - | ||||||||||||
605 | return QOpenGLTexture::RGBA_Integer; | - | ||||||||||||
606 | - | |||||||||||||
607 | case QOpenGLTexture::R16F: | - | ||||||||||||
608 | return QOpenGLTexture::Red; | - | ||||||||||||
609 | - | |||||||||||||
610 | case QOpenGLTexture::RG16F: | - | ||||||||||||
611 | return QOpenGLTexture::RG; | - | ||||||||||||
612 | - | |||||||||||||
613 | case QOpenGLTexture::RGB16F: | - | ||||||||||||
614 | return QOpenGLTexture::RGB; | - | ||||||||||||
615 | - | |||||||||||||
616 | case QOpenGLTexture::RGBA16F: | - | ||||||||||||
617 | return QOpenGLTexture::RGBA; | - | ||||||||||||
618 | - | |||||||||||||
619 | case QOpenGLTexture::R32F: | - | ||||||||||||
620 | return QOpenGLTexture::Red; | - | ||||||||||||
621 | - | |||||||||||||
622 | case QOpenGLTexture::RG32F: | - | ||||||||||||
623 | return QOpenGLTexture::RG; | - | ||||||||||||
624 | - | |||||||||||||
625 | case QOpenGLTexture::RGB32F: | - | ||||||||||||
626 | return QOpenGLTexture::RGB; | - | ||||||||||||
627 | - | |||||||||||||
628 | case QOpenGLTexture::RGBA32F: | - | ||||||||||||
629 | return QOpenGLTexture::RGBA; | - | ||||||||||||
630 | - | |||||||||||||
631 | case QOpenGLTexture::RGB9E5: | - | ||||||||||||
632 | return QOpenGLTexture::RGB; | - | ||||||||||||
633 | - | |||||||||||||
634 | case QOpenGLTexture::RG11B10F: | - | ||||||||||||
635 | return QOpenGLTexture::RGB; | - | ||||||||||||
636 | - | |||||||||||||
637 | case QOpenGLTexture::RG3B2: | - | ||||||||||||
638 | return QOpenGLTexture::RGB; | - | ||||||||||||
639 | - | |||||||||||||
640 | case QOpenGLTexture::R5G6B5: | - | ||||||||||||
641 | return QOpenGLTexture::RGB; | - | ||||||||||||
642 | - | |||||||||||||
643 | case QOpenGLTexture::RGB5A1: | - | ||||||||||||
644 | return QOpenGLTexture::RGBA; | - | ||||||||||||
645 | - | |||||||||||||
646 | case QOpenGLTexture::RGBA4: | - | ||||||||||||
647 | return QOpenGLTexture::RGBA; | - | ||||||||||||
648 | - | |||||||||||||
649 | case QOpenGLTexture::RGB10A2: | - | ||||||||||||
650 | return QOpenGLTexture::RGBA; | - | ||||||||||||
651 | - | |||||||||||||
652 | case QOpenGLTexture::D16: | - | ||||||||||||
653 | case QOpenGLTexture::D24: | - | ||||||||||||
654 | case QOpenGLTexture::D32: | - | ||||||||||||
655 | case QOpenGLTexture::D32F: | - | ||||||||||||
656 | return QOpenGLTexture::Depth; | - | ||||||||||||
657 | - | |||||||||||||
658 | case QOpenGLTexture::D24S8: | - | ||||||||||||
659 | case QOpenGLTexture::D32FS8X24: | - | ||||||||||||
660 | return QOpenGLTexture::DepthStencil; | - | ||||||||||||
661 | - | |||||||||||||
662 | case QOpenGLTexture::S8: | - | ||||||||||||
663 | return QOpenGLTexture::Stencil; | - | ||||||||||||
664 | - | |||||||||||||
665 | case QOpenGLTexture::RGB_DXT1: | - | ||||||||||||
666 | case QOpenGLTexture::RGBA_DXT1: | - | ||||||||||||
667 | case QOpenGLTexture::RGBA_DXT3: | - | ||||||||||||
668 | case QOpenGLTexture::RGBA_DXT5: | - | ||||||||||||
669 | case QOpenGLTexture::R_ATI1N_UNorm: | - | ||||||||||||
670 | case QOpenGLTexture::R_ATI1N_SNorm: | - | ||||||||||||
671 | case QOpenGLTexture::RG_ATI2N_UNorm: | - | ||||||||||||
672 | case QOpenGLTexture::RG_ATI2N_SNorm: | - | ||||||||||||
673 | case QOpenGLTexture::RGB_BP_UNSIGNED_FLOAT: | - | ||||||||||||
674 | case QOpenGLTexture::RGB_BP_SIGNED_FLOAT: | - | ||||||||||||
675 | case QOpenGLTexture::RGB_BP_UNorm: | - | ||||||||||||
676 | case QOpenGLTexture::SRGB8: | - | ||||||||||||
677 | case QOpenGLTexture::SRGB8_Alpha8: | - | ||||||||||||
678 | case QOpenGLTexture::SRGB_DXT1: | - | ||||||||||||
679 | case QOpenGLTexture::SRGB_Alpha_DXT1: | - | ||||||||||||
680 | case QOpenGLTexture::SRGB_Alpha_DXT3: | - | ||||||||||||
681 | case QOpenGLTexture::SRGB_Alpha_DXT5: | - | ||||||||||||
682 | case QOpenGLTexture::SRGB_BP_UNorm: | - | ||||||||||||
683 | case QOpenGLTexture::RGB8_ETC1: | - | ||||||||||||
684 | return QOpenGLTexture::RGBA; | - | ||||||||||||
685 | - | |||||||||||||
686 | case QOpenGLTexture::R11_EAC_UNorm: | - | ||||||||||||
687 | case QOpenGLTexture::R11_EAC_SNorm: | - | ||||||||||||
688 | return QOpenGLTexture::Red; | - | ||||||||||||
689 | - | |||||||||||||
690 | case QOpenGLTexture::RG11_EAC_UNorm: | - | ||||||||||||
691 | case QOpenGLTexture::RG11_EAC_SNorm: | - | ||||||||||||
692 | return QOpenGLTexture::RG; | - | ||||||||||||
693 | - | |||||||||||||
694 | case QOpenGLTexture::RGB8_ETC2: | - | ||||||||||||
695 | case QOpenGLTexture::SRGB8_ETC2: | - | ||||||||||||
696 | return QOpenGLTexture::RGB; | - | ||||||||||||
697 | - | |||||||||||||
698 | case QOpenGLTexture::RGB8_PunchThrough_Alpha1_ETC2: | - | ||||||||||||
699 | case QOpenGLTexture::SRGB8_PunchThrough_Alpha1_ETC2: | - | ||||||||||||
700 | return QOpenGLTexture::RGBA; | - | ||||||||||||
701 | - | |||||||||||||
702 | case QOpenGLTexture::RGBA8_ETC2_EAC: | - | ||||||||||||
703 | case QOpenGLTexture::SRGB8_Alpha8_ETC2_EAC: | - | ||||||||||||
704 | return QOpenGLTexture::RGBA; | - | ||||||||||||
705 | - | |||||||||||||
706 | case QOpenGLTexture::DepthFormat: | - | ||||||||||||
707 | return QOpenGLTexture::Depth; | - | ||||||||||||
708 | - | |||||||||||||
709 | case QOpenGLTexture::AlphaFormat: | - | ||||||||||||
710 | return QOpenGLTexture::Alpha; | - | ||||||||||||
711 | - | |||||||||||||
712 | case QOpenGLTexture::RGBFormat: | - | ||||||||||||
713 | case QOpenGLTexture::RGBAFormat: | - | ||||||||||||
714 | return QOpenGLTexture::RGBA; | - | ||||||||||||
715 | - | |||||||||||||
716 | case QOpenGLTexture::LuminanceFormat: | - | ||||||||||||
717 | return QOpenGLTexture::Luminance; | - | ||||||||||||
718 | - | |||||||||||||
719 | case QOpenGLTexture::LuminanceAlphaFormat: | - | ||||||||||||
720 | return QOpenGLTexture::LuminanceAlpha; | - | ||||||||||||
721 | } | - | ||||||||||||
722 | - | |||||||||||||
723 | Q_UNREACHABLE(); | - | ||||||||||||
724 | return QOpenGLTexture::NoSourceFormat; | - | ||||||||||||
725 | } | - | ||||||||||||
726 | - | |||||||||||||
727 | static QOpenGLTexture::PixelType pixelTypeCompatibleWithInternalFormat(QOpenGLTexture::TextureFormat internalFormat) | - | ||||||||||||
728 | { | - | ||||||||||||
729 | switch (internalFormat) { | - | ||||||||||||
730 | case QOpenGLTexture::NoFormat: | - | ||||||||||||
731 | return QOpenGLTexture::NoPixelType; | - | ||||||||||||
732 | - | |||||||||||||
733 | case QOpenGLTexture::R8_UNorm: | - | ||||||||||||
734 | case QOpenGLTexture::RG8_UNorm: | - | ||||||||||||
735 | case QOpenGLTexture::RGB8_UNorm: | - | ||||||||||||
736 | case QOpenGLTexture::RGBA8_UNorm: | - | ||||||||||||
737 | case QOpenGLTexture::R16_UNorm: | - | ||||||||||||
738 | case QOpenGLTexture::RG16_UNorm: | - | ||||||||||||
739 | case QOpenGLTexture::RGB16_UNorm: | - | ||||||||||||
740 | case QOpenGLTexture::RGBA16_UNorm: | - | ||||||||||||
741 | return QOpenGLTexture::UInt8; | - | ||||||||||||
742 | - | |||||||||||||
743 | case QOpenGLTexture::R8_SNorm: | - | ||||||||||||
744 | case QOpenGLTexture::RG8_SNorm: | - | ||||||||||||
745 | case QOpenGLTexture::RGB8_SNorm: | - | ||||||||||||
746 | case QOpenGLTexture::RGBA8_SNorm: | - | ||||||||||||
747 | case QOpenGLTexture::R16_SNorm: | - | ||||||||||||
748 | case QOpenGLTexture::RG16_SNorm: | - | ||||||||||||
749 | case QOpenGLTexture::RGB16_SNorm: | - | ||||||||||||
750 | case QOpenGLTexture::RGBA16_SNorm: | - | ||||||||||||
751 | return QOpenGLTexture::Int8; | - | ||||||||||||
752 | - | |||||||||||||
753 | case QOpenGLTexture::R8U: | - | ||||||||||||
754 | case QOpenGLTexture::RG8U: | - | ||||||||||||
755 | case QOpenGLTexture::RGB8U: | - | ||||||||||||
756 | case QOpenGLTexture::RGBA8U: | - | ||||||||||||
757 | case QOpenGLTexture::R16U: | - | ||||||||||||
758 | case QOpenGLTexture::RG16U: | - | ||||||||||||
759 | case QOpenGLTexture::RGB16U: | - | ||||||||||||
760 | case QOpenGLTexture::RGBA16U: | - | ||||||||||||
761 | case QOpenGLTexture::R32U: | - | ||||||||||||
762 | case QOpenGLTexture::RG32U: | - | ||||||||||||
763 | case QOpenGLTexture::RGB32U: | - | ||||||||||||
764 | case QOpenGLTexture::RGBA32U: | - | ||||||||||||
765 | return QOpenGLTexture::UInt8; | - | ||||||||||||
766 | - | |||||||||||||
767 | case QOpenGLTexture::R8I: | - | ||||||||||||
768 | case QOpenGLTexture::RG8I: | - | ||||||||||||
769 | case QOpenGLTexture::RGB8I: | - | ||||||||||||
770 | case QOpenGLTexture::RGBA8I: | - | ||||||||||||
771 | case QOpenGLTexture::R16I: | - | ||||||||||||
772 | case QOpenGLTexture::RG16I: | - | ||||||||||||
773 | case QOpenGLTexture::RGB16I: | - | ||||||||||||
774 | case QOpenGLTexture::RGBA16I: | - | ||||||||||||
775 | case QOpenGLTexture::R32I: | - | ||||||||||||
776 | case QOpenGLTexture::RG32I: | - | ||||||||||||
777 | case QOpenGLTexture::RGB32I: | - | ||||||||||||
778 | case QOpenGLTexture::RGBA32I: | - | ||||||||||||
779 | return QOpenGLTexture::Int8; | - | ||||||||||||
780 | - | |||||||||||||
781 | case QOpenGLTexture::R16F: | - | ||||||||||||
782 | case QOpenGLTexture::RG16F: | - | ||||||||||||
783 | case QOpenGLTexture::RGB16F: | - | ||||||||||||
784 | case QOpenGLTexture::RGBA16F: | - | ||||||||||||
785 | return QOpenGLTexture::Float16; | - | ||||||||||||
786 | - | |||||||||||||
787 | case QOpenGLTexture::R32F: | - | ||||||||||||
788 | case QOpenGLTexture::RG32F: | - | ||||||||||||
789 | case QOpenGLTexture::RGB32F: | - | ||||||||||||
790 | case QOpenGLTexture::RGBA32F: | - | ||||||||||||
791 | return QOpenGLTexture::Float32; | - | ||||||||||||
792 | - | |||||||||||||
793 | case QOpenGLTexture::RGB9E5: | - | ||||||||||||
794 | return QOpenGLTexture::UInt16_RGB5A1_Rev; | - | ||||||||||||
795 | - | |||||||||||||
796 | case QOpenGLTexture::RG11B10F: | - | ||||||||||||
797 | return QOpenGLTexture::UInt32_RG11B10F; | - | ||||||||||||
798 | - | |||||||||||||
799 | case QOpenGLTexture::RG3B2: | - | ||||||||||||
800 | return QOpenGLTexture::UInt8_RG3B2; | - | ||||||||||||
801 | - | |||||||||||||
802 | case QOpenGLTexture::R5G6B5: | - | ||||||||||||
803 | return QOpenGLTexture::UInt16_R5G6B5; | - | ||||||||||||
804 | - | |||||||||||||
805 | case QOpenGLTexture::RGB5A1: | - | ||||||||||||
806 | return QOpenGLTexture::UInt16_RGB5A1; | - | ||||||||||||
807 | - | |||||||||||||
808 | case QOpenGLTexture::RGBA4: | - | ||||||||||||
809 | return QOpenGLTexture::UInt16_RGBA4; | - | ||||||||||||
810 | - | |||||||||||||
811 | case QOpenGLTexture::RGB10A2: | - | ||||||||||||
812 | return QOpenGLTexture::UInt32_RGB10A2; | - | ||||||||||||
813 | - | |||||||||||||
814 | case QOpenGLTexture::D16: | - | ||||||||||||
815 | return QOpenGLTexture::UInt16; | - | ||||||||||||
816 | - | |||||||||||||
817 | case QOpenGLTexture::D24: | - | ||||||||||||
818 | case QOpenGLTexture::D32: | - | ||||||||||||
819 | return QOpenGLTexture::UInt32; | - | ||||||||||||
820 | - | |||||||||||||
821 | case QOpenGLTexture::D32F: | - | ||||||||||||
822 | return QOpenGLTexture::Float32; | - | ||||||||||||
823 | - | |||||||||||||
824 | case QOpenGLTexture::D24S8: | - | ||||||||||||
825 | return QOpenGLTexture::UInt32_D24S8; | - | ||||||||||||
826 | - | |||||||||||||
827 | case QOpenGLTexture::D32FS8X24: | - | ||||||||||||
828 | return QOpenGLTexture::Float32_D32_UInt32_S8_X24; | - | ||||||||||||
829 | - | |||||||||||||
830 | case QOpenGLTexture::S8: | - | ||||||||||||
831 | return QOpenGLTexture::UInt8; | - | ||||||||||||
832 | - | |||||||||||||
833 | case QOpenGLTexture::RGB_DXT1: | - | ||||||||||||
834 | case QOpenGLTexture::RGBA_DXT1: | - | ||||||||||||
835 | case QOpenGLTexture::RGBA_DXT3: | - | ||||||||||||
836 | case QOpenGLTexture::RGBA_DXT5: | - | ||||||||||||
837 | case QOpenGLTexture::R_ATI1N_UNorm: | - | ||||||||||||
838 | case QOpenGLTexture::R_ATI1N_SNorm: | - | ||||||||||||
839 | case QOpenGLTexture::RG_ATI2N_UNorm: | - | ||||||||||||
840 | case QOpenGLTexture::RG_ATI2N_SNorm: | - | ||||||||||||
841 | case QOpenGLTexture::RGB_BP_UNSIGNED_FLOAT: | - | ||||||||||||
842 | case QOpenGLTexture::RGB_BP_SIGNED_FLOAT: | - | ||||||||||||
843 | case QOpenGLTexture::RGB_BP_UNorm: | - | ||||||||||||
844 | case QOpenGLTexture::SRGB8: | - | ||||||||||||
845 | case QOpenGLTexture::SRGB8_Alpha8: | - | ||||||||||||
846 | case QOpenGLTexture::SRGB_DXT1: | - | ||||||||||||
847 | case QOpenGLTexture::SRGB_Alpha_DXT1: | - | ||||||||||||
848 | case QOpenGLTexture::SRGB_Alpha_DXT3: | - | ||||||||||||
849 | case QOpenGLTexture::SRGB_Alpha_DXT5: | - | ||||||||||||
850 | case QOpenGLTexture::SRGB_BP_UNorm: | - | ||||||||||||
851 | case QOpenGLTexture::R11_EAC_UNorm: | - | ||||||||||||
852 | case QOpenGLTexture::R11_EAC_SNorm: | - | ||||||||||||
853 | case QOpenGLTexture::RG11_EAC_UNorm: | - | ||||||||||||
854 | case QOpenGLTexture::RG11_EAC_SNorm: | - | ||||||||||||
855 | case QOpenGLTexture::RGB8_ETC2: | - | ||||||||||||
856 | case QOpenGLTexture::SRGB8_ETC2: | - | ||||||||||||
857 | case QOpenGLTexture::RGB8_PunchThrough_Alpha1_ETC2: | - | ||||||||||||
858 | case QOpenGLTexture::SRGB8_PunchThrough_Alpha1_ETC2: | - | ||||||||||||
859 | case QOpenGLTexture::RGBA8_ETC2_EAC: | - | ||||||||||||
860 | case QOpenGLTexture::SRGB8_Alpha8_ETC2_EAC: | - | ||||||||||||
861 | case QOpenGLTexture::RGB8_ETC1: | - | ||||||||||||
862 | return QOpenGLTexture::UInt8; | - | ||||||||||||
863 | - | |||||||||||||
864 | case QOpenGLTexture::DepthFormat: | - | ||||||||||||
865 | return QOpenGLTexture::UInt32; | - | ||||||||||||
866 | - | |||||||||||||
867 | case QOpenGLTexture::AlphaFormat: | - | ||||||||||||
868 | case QOpenGLTexture::RGBFormat: | - | ||||||||||||
869 | case QOpenGLTexture::RGBAFormat: | - | ||||||||||||
870 | case QOpenGLTexture::LuminanceFormat: | - | ||||||||||||
871 | case QOpenGLTexture::LuminanceAlphaFormat: | - | ||||||||||||
872 | return QOpenGLTexture::UInt8; | - | ||||||||||||
873 | } | - | ||||||||||||
874 | - | |||||||||||||
875 | Q_UNREACHABLE(); | - | ||||||||||||
876 | return QOpenGLTexture::NoPixelType; | - | ||||||||||||
877 | } | - | ||||||||||||
878 | - | |||||||||||||
879 | static bool isCompressedFormat(QOpenGLTexture::TextureFormat internalFormat) | - | ||||||||||||
880 | { | - | ||||||||||||
881 | switch (internalFormat) { | - | ||||||||||||
882 | case QOpenGLTexture::NoFormat: | - | ||||||||||||
883 | - | |||||||||||||
884 | case QOpenGLTexture::R8_UNorm: | - | ||||||||||||
885 | case QOpenGLTexture::RG8_UNorm: | - | ||||||||||||
886 | case QOpenGLTexture::RGB8_UNorm: | - | ||||||||||||
887 | case QOpenGLTexture::RGBA8_UNorm: | - | ||||||||||||
888 | case QOpenGLTexture::R16_UNorm: | - | ||||||||||||
889 | case QOpenGLTexture::RG16_UNorm: | - | ||||||||||||
890 | case QOpenGLTexture::RGB16_UNorm: | - | ||||||||||||
891 | case QOpenGLTexture::RGBA16_UNorm: | - | ||||||||||||
892 | case QOpenGLTexture::R8_SNorm: | - | ||||||||||||
893 | case QOpenGLTexture::RG8_SNorm: | - | ||||||||||||
894 | case QOpenGLTexture::RGB8_SNorm: | - | ||||||||||||
895 | case QOpenGLTexture::RGBA8_SNorm: | - | ||||||||||||
896 | case QOpenGLTexture::R16_SNorm: | - | ||||||||||||
897 | case QOpenGLTexture::RG16_SNorm: | - | ||||||||||||
898 | case QOpenGLTexture::RGB16_SNorm: | - | ||||||||||||
899 | case QOpenGLTexture::RGBA16_SNorm: | - | ||||||||||||
900 | case QOpenGLTexture::R8U: | - | ||||||||||||
901 | case QOpenGLTexture::RG8U: | - | ||||||||||||
902 | case QOpenGLTexture::RGB8U: | - | ||||||||||||
903 | case QOpenGLTexture::RGBA8U: | - | ||||||||||||
904 | case QOpenGLTexture::R16U: | - | ||||||||||||
905 | case QOpenGLTexture::RG16U: | - | ||||||||||||
906 | case QOpenGLTexture::RGB16U: | - | ||||||||||||
907 | case QOpenGLTexture::RGBA16U: | - | ||||||||||||
908 | case QOpenGLTexture::R32U: | - | ||||||||||||
909 | case QOpenGLTexture::RG32U: | - | ||||||||||||
910 | case QOpenGLTexture::RGB32U: | - | ||||||||||||
911 | case QOpenGLTexture::RGBA32U: | - | ||||||||||||
912 | case QOpenGLTexture::R8I: | - | ||||||||||||
913 | case QOpenGLTexture::RG8I: | - | ||||||||||||
914 | case QOpenGLTexture::RGB8I: | - | ||||||||||||
915 | case QOpenGLTexture::RGBA8I: | - | ||||||||||||
916 | case QOpenGLTexture::R16I: | - | ||||||||||||
917 | case QOpenGLTexture::RG16I: | - | ||||||||||||
918 | case QOpenGLTexture::RGB16I: | - | ||||||||||||
919 | case QOpenGLTexture::RGBA16I: | - | ||||||||||||
920 | case QOpenGLTexture::R32I: | - | ||||||||||||
921 | case QOpenGLTexture::RG32I: | - | ||||||||||||
922 | case QOpenGLTexture::RGB32I: | - | ||||||||||||
923 | case QOpenGLTexture::RGBA32I: | - | ||||||||||||
924 | case QOpenGLTexture::R16F: | - | ||||||||||||
925 | case QOpenGLTexture::RG16F: | - | ||||||||||||
926 | case QOpenGLTexture::RGB16F: | - | ||||||||||||
927 | case QOpenGLTexture::RGBA16F: | - | ||||||||||||
928 | case QOpenGLTexture::R32F: | - | ||||||||||||
929 | case QOpenGLTexture::RG32F: | - | ||||||||||||
930 | case QOpenGLTexture::RGB32F: | - | ||||||||||||
931 | case QOpenGLTexture::RGBA32F: | - | ||||||||||||
932 | case QOpenGLTexture::RGB9E5: | - | ||||||||||||
933 | case QOpenGLTexture::RG11B10F: | - | ||||||||||||
934 | case QOpenGLTexture::RG3B2: | - | ||||||||||||
935 | case QOpenGLTexture::R5G6B5: | - | ||||||||||||
936 | case QOpenGLTexture::RGB5A1: | - | ||||||||||||
937 | case QOpenGLTexture::RGBA4: | - | ||||||||||||
938 | case QOpenGLTexture::RGB10A2: | - | ||||||||||||
939 | - | |||||||||||||
940 | case QOpenGLTexture::D16: | - | ||||||||||||
941 | case QOpenGLTexture::D24: | - | ||||||||||||
942 | case QOpenGLTexture::D32: | - | ||||||||||||
943 | case QOpenGLTexture::D32F: | - | ||||||||||||
944 | - | |||||||||||||
945 | case QOpenGLTexture::D24S8: | - | ||||||||||||
946 | case QOpenGLTexture::D32FS8X24: | - | ||||||||||||
947 | - | |||||||||||||
948 | case QOpenGLTexture::S8: | - | ||||||||||||
949 | return false; | - | ||||||||||||
950 | - | |||||||||||||
951 | case QOpenGLTexture::RGB_DXT1: | - | ||||||||||||
952 | case QOpenGLTexture::RGBA_DXT1: | - | ||||||||||||
953 | case QOpenGLTexture::RGBA_DXT3: | - | ||||||||||||
954 | case QOpenGLTexture::RGBA_DXT5: | - | ||||||||||||
955 | case QOpenGLTexture::R_ATI1N_UNorm: | - | ||||||||||||
956 | case QOpenGLTexture::R_ATI1N_SNorm: | - | ||||||||||||
957 | case QOpenGLTexture::RG_ATI2N_UNorm: | - | ||||||||||||
958 | case QOpenGLTexture::RG_ATI2N_SNorm: | - | ||||||||||||
959 | case QOpenGLTexture::RGB_BP_UNSIGNED_FLOAT: | - | ||||||||||||
960 | case QOpenGLTexture::RGB_BP_SIGNED_FLOAT: | - | ||||||||||||
961 | case QOpenGLTexture::RGB_BP_UNorm: | - | ||||||||||||
962 | case QOpenGLTexture::SRGB8: | - | ||||||||||||
963 | case QOpenGLTexture::SRGB8_Alpha8: | - | ||||||||||||
964 | case QOpenGLTexture::SRGB_DXT1: | - | ||||||||||||
965 | case QOpenGLTexture::SRGB_Alpha_DXT1: | - | ||||||||||||
966 | case QOpenGLTexture::SRGB_Alpha_DXT3: | - | ||||||||||||
967 | case QOpenGLTexture::SRGB_Alpha_DXT5: | - | ||||||||||||
968 | case QOpenGLTexture::SRGB_BP_UNorm: | - | ||||||||||||
969 | case QOpenGLTexture::R11_EAC_UNorm: | - | ||||||||||||
970 | case QOpenGLTexture::R11_EAC_SNorm: | - | ||||||||||||
971 | case QOpenGLTexture::RG11_EAC_UNorm: | - | ||||||||||||
972 | case QOpenGLTexture::RG11_EAC_SNorm: | - | ||||||||||||
973 | case QOpenGLTexture::RGB8_ETC2: | - | ||||||||||||
974 | case QOpenGLTexture::SRGB8_ETC2: | - | ||||||||||||
975 | case QOpenGLTexture::RGB8_PunchThrough_Alpha1_ETC2: | - | ||||||||||||
976 | case QOpenGLTexture::SRGB8_PunchThrough_Alpha1_ETC2: | - | ||||||||||||
977 | case QOpenGLTexture::RGBA8_ETC2_EAC: | - | ||||||||||||
978 | case QOpenGLTexture::SRGB8_Alpha8_ETC2_EAC: | - | ||||||||||||
979 | case QOpenGLTexture::RGB8_ETC1: | - | ||||||||||||
980 | return true; | - | ||||||||||||
981 | - | |||||||||||||
982 | case QOpenGLTexture::DepthFormat: | - | ||||||||||||
983 | case QOpenGLTexture::AlphaFormat: | - | ||||||||||||
984 | case QOpenGLTexture::RGBFormat: | - | ||||||||||||
985 | case QOpenGLTexture::RGBAFormat: | - | ||||||||||||
986 | case QOpenGLTexture::LuminanceFormat: | - | ||||||||||||
987 | case QOpenGLTexture::LuminanceAlphaFormat: | - | ||||||||||||
988 | return false; | - | ||||||||||||
989 | } | - | ||||||||||||
990 | - | |||||||||||||
991 | Q_UNREACHABLE(); | - | ||||||||||||
992 | return false; | - | ||||||||||||
993 | } | - | ||||||||||||
994 | - | |||||||||||||
995 | void QOpenGLTexturePrivate::allocateMutableStorage(QOpenGLTexture::PixelFormat pixelFormat, QOpenGLTexture::PixelType pixelType) | - | ||||||||||||
996 | { | - | ||||||||||||
997 | // There is no way to allocate mutable storage for compressed textures in in | - | ||||||||||||
998 | // versions older than OpenGL 3.1 and OpenGL ES 3.0, because the older specs | - | ||||||||||||
999 | // do not mandate accepting null data pointers for glCompressedTexImage*D, | - | ||||||||||||
1000 | // unlike glTexImage*D (which in turn does not accept compressed formats). | - | ||||||||||||
1001 | if (isCompressedFormat(format)) { | - | ||||||||||||
1002 | storageAllocated = true; | - | ||||||||||||
1003 | return; | - | ||||||||||||
1004 | } | - | ||||||||||||
1005 | - | |||||||||||||
1006 | switch (target) { | - | ||||||||||||
1007 | case QOpenGLTexture::TargetBuffer: | - | ||||||||||||
1008 | // Buffer textures get their storage from an external OpenGL buffer | - | ||||||||||||
1009 | qWarning("Buffer textures do not allocate storage"); | - | ||||||||||||
1010 | return; | - | ||||||||||||
1011 | - | |||||||||||||
1012 | case QOpenGLTexture::Target1D: | - | ||||||||||||
1013 | if (features.testFlag(QOpenGLTexture::Texture1D)) { | - | ||||||||||||
1014 | for (int level = 0; level < mipLevels; ++level) | - | ||||||||||||
1015 | texFuncs->glTextureImage1D(textureId, target, bindingTarget, level, format, | - | ||||||||||||
1016 | mipLevelSize(level, dimensions[0]), | - | ||||||||||||
1017 | 0, | - | ||||||||||||
1018 | pixelFormat, pixelType, 0); | - | ||||||||||||
1019 | } else { | - | ||||||||||||
1020 | qWarning("1D textures are not supported"); | - | ||||||||||||
1021 | return; | - | ||||||||||||
1022 | } | - | ||||||||||||
1023 | break; | - | ||||||||||||
1024 | - | |||||||||||||
1025 | case QOpenGLTexture::Target1DArray: | - | ||||||||||||
1026 | if (features.testFlag(QOpenGLTexture::Texture1D) | - | ||||||||||||
1027 | && features.testFlag(QOpenGLTexture::TextureArrays)) { | - | ||||||||||||
1028 | for (int level = 0; level < mipLevels; ++level) | - | ||||||||||||
1029 | texFuncs->glTextureImage2D(textureId, target, bindingTarget, level, format, | - | ||||||||||||
1030 | mipLevelSize(level, dimensions[0]), | - | ||||||||||||
1031 | layers, | - | ||||||||||||
1032 | 0, | - | ||||||||||||
1033 | pixelFormat, pixelType, 0); | - | ||||||||||||
1034 | } else { | - | ||||||||||||
1035 | qWarning("1D array textures are not supported"); | - | ||||||||||||
1036 | return; | - | ||||||||||||
1037 | } | - | ||||||||||||
1038 | break; | - | ||||||||||||
1039 | - | |||||||||||||
1040 | case QOpenGLTexture::Target2D: | - | ||||||||||||
1041 | case QOpenGLTexture::TargetRectangle: | - | ||||||||||||
1042 | for (int level = 0; level < mipLevels; ++level) | - | ||||||||||||
1043 | texFuncs->glTextureImage2D(textureId, target, bindingTarget, level, format, | - | ||||||||||||
1044 | mipLevelSize(level, dimensions[0]), | - | ||||||||||||
1045 | mipLevelSize(level, dimensions[1]), | - | ||||||||||||
1046 | 0, | - | ||||||||||||
1047 | pixelFormat, pixelType, 0); | - | ||||||||||||
1048 | break; | - | ||||||||||||
1049 | - | |||||||||||||
1050 | case QOpenGLTexture::TargetCubeMap: { | - | ||||||||||||
1051 | // Cubemaps are the odd one out. We have to allocate storage for each | - | ||||||||||||
1052 | // face and miplevel using the special cubemap face targets rather than | - | ||||||||||||
1053 | // GL_TARGET_CUBEMAP. | - | ||||||||||||
1054 | const QOpenGLTexture::CubeMapFace faceTargets[] = { | - | ||||||||||||
1055 | QOpenGLTexture::CubeMapPositiveX, QOpenGLTexture::CubeMapNegativeX, | - | ||||||||||||
1056 | QOpenGLTexture::CubeMapPositiveY, QOpenGLTexture::CubeMapNegativeY, | - | ||||||||||||
1057 | QOpenGLTexture::CubeMapPositiveZ, QOpenGLTexture::CubeMapNegativeZ | - | ||||||||||||
1058 | }; | - | ||||||||||||
1059 | - | |||||||||||||
1060 | for (int faceTarget = 0; faceTarget < 6; ++faceTarget) { | - | ||||||||||||
1061 | for (int level = 0; level < mipLevels; ++level) { | - | ||||||||||||
1062 | texFuncs->glTextureImage2D(textureId, faceTargets[faceTarget], bindingTarget, | - | ||||||||||||
1063 | level, format, | - | ||||||||||||
1064 | mipLevelSize(level, dimensions[0]), | - | ||||||||||||
1065 | mipLevelSize(level, dimensions[1]), | - | ||||||||||||
1066 | 0, | - | ||||||||||||
1067 | pixelFormat, pixelType, 0); | - | ||||||||||||
1068 | } | - | ||||||||||||
1069 | } | - | ||||||||||||
1070 | break; | - | ||||||||||||
1071 | } | - | ||||||||||||
1072 | - | |||||||||||||
1073 | case QOpenGLTexture::Target2DArray: | - | ||||||||||||
1074 | if (features.testFlag(QOpenGLTexture::TextureArrays)) { | - | ||||||||||||
1075 | for (int level = 0; level < mipLevels; ++level) | - | ||||||||||||
1076 | texFuncs->glTextureImage3D(textureId, target, bindingTarget, level, format, | - | ||||||||||||
1077 | mipLevelSize(level, dimensions[0]), | - | ||||||||||||
1078 | mipLevelSize(level, dimensions[1]), | - | ||||||||||||
1079 | layers, | - | ||||||||||||
1080 | 0, | - | ||||||||||||
1081 | pixelFormat, pixelType, 0); | - | ||||||||||||
1082 | } else { | - | ||||||||||||
1083 | qWarning("Array textures are not supported"); | - | ||||||||||||
1084 | return; | - | ||||||||||||
1085 | } | - | ||||||||||||
1086 | break; | - | ||||||||||||
1087 | - | |||||||||||||
1088 | case QOpenGLTexture::TargetCubeMapArray: | - | ||||||||||||
1089 | // Cubemap arrays must specify number of layer-faces (6 * layers) as depth parameter | - | ||||||||||||
1090 | if (features.testFlag(QOpenGLTexture::TextureCubeMapArrays)) { | - | ||||||||||||
1091 | for (int level = 0; level < mipLevels; ++level) | - | ||||||||||||
1092 | texFuncs->glTextureImage3D(textureId, target, bindingTarget, level, format, | - | ||||||||||||
1093 | mipLevelSize(level, dimensions[0]), | - | ||||||||||||
1094 | mipLevelSize(level, dimensions[1]), | - | ||||||||||||
1095 | 6 * layers, | - | ||||||||||||
1096 | 0, | - | ||||||||||||
1097 | pixelFormat, pixelType, 0); | - | ||||||||||||
1098 | } else { | - | ||||||||||||
1099 | qWarning("Cubemap Array textures are not supported"); | - | ||||||||||||
1100 | return; | - | ||||||||||||
1101 | } | - | ||||||||||||
1102 | break; | - | ||||||||||||
1103 | - | |||||||||||||
1104 | case QOpenGLTexture::Target3D: | - | ||||||||||||
1105 | if (features.testFlag(QOpenGLTexture::Texture3D)) { | - | ||||||||||||
1106 | for (int level = 0; level < mipLevels; ++level) | - | ||||||||||||
1107 | texFuncs->glTextureImage3D(textureId, target, bindingTarget, level, format, | - | ||||||||||||
1108 | mipLevelSize(level, dimensions[0]), | - | ||||||||||||
1109 | mipLevelSize(level, dimensions[1]), | - | ||||||||||||
1110 | mipLevelSize(level, dimensions[2]), | - | ||||||||||||
1111 | 0, | - | ||||||||||||
1112 | pixelFormat, pixelType, 0); | - | ||||||||||||
1113 | } else { | - | ||||||||||||
1114 | qWarning("3D textures are not supported"); | - | ||||||||||||
1115 | return; | - | ||||||||||||
1116 | } | - | ||||||||||||
1117 | break; | - | ||||||||||||
1118 | - | |||||||||||||
1119 | case QOpenGLTexture::Target2DMultisample: | - | ||||||||||||
1120 | if (features.testFlag(QOpenGLTexture::TextureMultisample)) { | - | ||||||||||||
1121 | texFuncs->glTextureImage2DMultisample(textureId, target, bindingTarget, samples, format, | - | ||||||||||||
1122 | dimensions[0], dimensions[1], | - | ||||||||||||
1123 | fixedSamplePositions); | - | ||||||||||||
1124 | } else { | - | ||||||||||||
1125 | qWarning("Multisample textures are not supported"); | - | ||||||||||||
1126 | return; | - | ||||||||||||
1127 | } | - | ||||||||||||
1128 | break; | - | ||||||||||||
1129 | - | |||||||||||||
1130 | case QOpenGLTexture::Target2DMultisampleArray: | - | ||||||||||||
1131 | if (features.testFlag(QOpenGLTexture::TextureMultisample) | - | ||||||||||||
1132 | && features.testFlag(QOpenGLTexture::TextureArrays)) { | - | ||||||||||||
1133 | texFuncs->glTextureImage3DMultisample(textureId, target, bindingTarget, samples, format, | - | ||||||||||||
1134 | dimensions[0], dimensions[1], layers, | - | ||||||||||||
1135 | fixedSamplePositions); | - | ||||||||||||
1136 | } else { | - | ||||||||||||
1137 | qWarning("Multisample array textures are not supported"); | - | ||||||||||||
1138 | return; | - | ||||||||||||
1139 | } | - | ||||||||||||
1140 | break; | - | ||||||||||||
1141 | } | - | ||||||||||||
1142 | - | |||||||||||||
1143 | storageAllocated = true; | - | ||||||||||||
1144 | } | - | ||||||||||||
1145 | - | |||||||||||||
1146 | void QOpenGLTexturePrivate::allocateImmutableStorage() | - | ||||||||||||
1147 | { | - | ||||||||||||
1148 | switch (target) { | - | ||||||||||||
1149 | case QOpenGLTexture::TargetBuffer: | - | ||||||||||||
1150 | // Buffer textures get their storage from an external OpenGL buffer | - | ||||||||||||
1151 | qWarning("Buffer textures do not allocate storage"); | - | ||||||||||||
1152 | return; | - | ||||||||||||
1153 | - | |||||||||||||
1154 | case QOpenGLTexture::Target1D: | - | ||||||||||||
1155 | if (features.testFlag(QOpenGLTexture::Texture1D)) { | - | ||||||||||||
1156 | texFuncs->glTextureStorage1D(textureId, target, bindingTarget, mipLevels, format, | - | ||||||||||||
1157 | dimensions[0]); | - | ||||||||||||
1158 | } else { | - | ||||||||||||
1159 | qWarning("1D textures are not supported"); | - | ||||||||||||
1160 | return; | - | ||||||||||||
1161 | } | - | ||||||||||||
1162 | break; | - | ||||||||||||
1163 | - | |||||||||||||
1164 | case QOpenGLTexture::Target1DArray: | - | ||||||||||||
1165 | if (features.testFlag(QOpenGLTexture::Texture1D) | - | ||||||||||||
1166 | && features.testFlag(QOpenGLTexture::TextureArrays)) { | - | ||||||||||||
1167 | texFuncs->glTextureStorage2D(textureId, target, bindingTarget, mipLevels, format, | - | ||||||||||||
1168 | dimensions[0], layers); | - | ||||||||||||
1169 | } else { | - | ||||||||||||
1170 | qWarning("1D array textures are not supported"); | - | ||||||||||||
1171 | return; | - | ||||||||||||
1172 | } | - | ||||||||||||
1173 | break; | - | ||||||||||||
1174 | - | |||||||||||||
1175 | case QOpenGLTexture::Target2D: | - | ||||||||||||
1176 | case QOpenGLTexture::TargetCubeMap: | - | ||||||||||||
1177 | case QOpenGLTexture::TargetRectangle: | - | ||||||||||||
1178 | texFuncs->glTextureStorage2D(textureId, target, bindingTarget, mipLevels, format, | - | ||||||||||||
1179 | dimensions[0], dimensions[1]); | - | ||||||||||||
1180 | break; | - | ||||||||||||
1181 | - | |||||||||||||
1182 | case QOpenGLTexture::Target2DArray: | - | ||||||||||||
1183 | if (features.testFlag(QOpenGLTexture::TextureArrays)) { | - | ||||||||||||
1184 | texFuncs->glTextureStorage3D(textureId, target, bindingTarget, mipLevels, format, | - | ||||||||||||
1185 | dimensions[0], dimensions[1], layers); | - | ||||||||||||
1186 | } else { | - | ||||||||||||
1187 | qWarning("Array textures are not supported"); | - | ||||||||||||
1188 | return; | - | ||||||||||||
1189 | } | - | ||||||||||||
1190 | break; | - | ||||||||||||
1191 | - | |||||||||||||
1192 | case QOpenGLTexture::TargetCubeMapArray: | - | ||||||||||||
1193 | // Cubemap arrays must specify number of layer-faces (6 * layers) as depth parameter | - | ||||||||||||
1194 | if (features.testFlag(QOpenGLTexture::TextureCubeMapArrays)) { | - | ||||||||||||
1195 | texFuncs->glTextureStorage3D(textureId, target, bindingTarget, mipLevels, format, | - | ||||||||||||
1196 | dimensions[0], dimensions[1], 6 * layers); | - | ||||||||||||
1197 | } else { | - | ||||||||||||
1198 | qWarning("Cubemap Array textures are not supported"); | - | ||||||||||||
1199 | return; | - | ||||||||||||
1200 | } | - | ||||||||||||
1201 | break; | - | ||||||||||||
1202 | - | |||||||||||||
1203 | case QOpenGLTexture::Target3D: | - | ||||||||||||
1204 | if (features.testFlag(QOpenGLTexture::Texture3D)) { | - | ||||||||||||
1205 | texFuncs->glTextureStorage3D(textureId, target, bindingTarget, mipLevels, format, | - | ||||||||||||
1206 | dimensions[0], dimensions[1], dimensions[2]); | - | ||||||||||||
1207 | } else { | - | ||||||||||||
1208 | qWarning("3D textures are not supported"); | - | ||||||||||||
1209 | return; | - | ||||||||||||
1210 | } | - | ||||||||||||
1211 | break; | - | ||||||||||||
1212 | - | |||||||||||||
1213 | case QOpenGLTexture::Target2DMultisample: | - | ||||||||||||
1214 | if (features.testFlag(QOpenGLTexture::ImmutableMultisampleStorage)) { | - | ||||||||||||
1215 | texFuncs->glTextureStorage2DMultisample(textureId, target, bindingTarget, samples, format, | - | ||||||||||||
1216 | dimensions[0], dimensions[1], | - | ||||||||||||
1217 | fixedSamplePositions); | - | ||||||||||||
1218 | } else { | - | ||||||||||||
1219 | qWarning("Multisample textures are not supported"); | - | ||||||||||||
1220 | return; | - | ||||||||||||
1221 | } | - | ||||||||||||
1222 | break; | - | ||||||||||||
1223 | - | |||||||||||||
1224 | case QOpenGLTexture::Target2DMultisampleArray: | - | ||||||||||||
1225 | if (features.testFlag(QOpenGLTexture::ImmutableMultisampleStorage) | - | ||||||||||||
1226 | && features.testFlag(QOpenGLTexture::TextureArrays)) { | - | ||||||||||||
1227 | texFuncs->glTextureStorage3DMultisample(textureId, target, bindingTarget, samples, format, | - | ||||||||||||
1228 | dimensions[0], dimensions[1], layers, | - | ||||||||||||
1229 | fixedSamplePositions); | - | ||||||||||||
1230 | } else { | - | ||||||||||||
1231 | qWarning("Multisample array textures are not supported"); | - | ||||||||||||
1232 | return; | - | ||||||||||||
1233 | } | - | ||||||||||||
1234 | break; | - | ||||||||||||
1235 | } | - | ||||||||||||
1236 | - | |||||||||||||
1237 | storageAllocated = true; | - | ||||||||||||
1238 | } | - | ||||||||||||
1239 | - | |||||||||||||
1240 | void QOpenGLTexturePrivate::setData(int mipLevel, int layer, QOpenGLTexture::CubeMapFace cubeFace, | - | ||||||||||||
1241 | QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, | - | ||||||||||||
1242 | const void *data, const QOpenGLPixelTransferOptions * const options) | - | ||||||||||||
1243 | { | - | ||||||||||||
1244 | switch (target) { | - | ||||||||||||
1245 | case QOpenGLTexture::Target1D: | - | ||||||||||||
1246 | Q_UNUSED(layer); | - | ||||||||||||
1247 | Q_UNUSED(cubeFace); | - | ||||||||||||
1248 | texFuncs->glTextureSubImage1D(textureId, target, bindingTarget, mipLevel, | - | ||||||||||||
1249 | 0, mipLevelSize( mipLevel, dimensions[0] ), | - | ||||||||||||
1250 | sourceFormat, sourceType, data, options); | - | ||||||||||||
1251 | break; | - | ||||||||||||
1252 | - | |||||||||||||
1253 | case QOpenGLTexture::Target1DArray: | - | ||||||||||||
1254 | Q_UNUSED(cubeFace); | - | ||||||||||||
1255 | texFuncs->glTextureSubImage2D(textureId, target, bindingTarget, mipLevel, | - | ||||||||||||
1256 | 0, layer, | - | ||||||||||||
1257 | mipLevelSize(mipLevel, dimensions[0]), | - | ||||||||||||
1258 | 1, | - | ||||||||||||
1259 | sourceFormat, sourceType, data, options); | - | ||||||||||||
1260 | break; | - | ||||||||||||
1261 | - | |||||||||||||
1262 | case QOpenGLTexture::Target2D: | - | ||||||||||||
1263 | Q_UNUSED(layer); | - | ||||||||||||
1264 | Q_UNUSED(cubeFace); | - | ||||||||||||
1265 | texFuncs->glTextureSubImage2D(textureId, target, bindingTarget, mipLevel, | - | ||||||||||||
1266 | 0, 0, | - | ||||||||||||
1267 | mipLevelSize(mipLevel, dimensions[0]), | - | ||||||||||||
1268 | mipLevelSize(mipLevel, dimensions[1]), | - | ||||||||||||
1269 | sourceFormat, sourceType, data, options); | - | ||||||||||||
1270 | break; | - | ||||||||||||
1271 | - | |||||||||||||
1272 | case QOpenGLTexture::Target2DArray: | - | ||||||||||||
1273 | Q_UNUSED(cubeFace); | - | ||||||||||||
1274 | texFuncs->glTextureSubImage3D(textureId, target, bindingTarget, mipLevel, | - | ||||||||||||
1275 | 0, 0, layer, | - | ||||||||||||
1276 | mipLevelSize(mipLevel, dimensions[0]), | - | ||||||||||||
1277 | mipLevelSize(mipLevel, dimensions[1]), | - | ||||||||||||
1278 | 1, | - | ||||||||||||
1279 | sourceFormat, sourceType, data, options); | - | ||||||||||||
1280 | break; | - | ||||||||||||
1281 | - | |||||||||||||
1282 | case QOpenGLTexture::Target3D: | - | ||||||||||||
1283 | Q_UNUSED(cubeFace); | - | ||||||||||||
1284 | texFuncs->glTextureSubImage3D(textureId, target, bindingTarget, mipLevel, | - | ||||||||||||
1285 | 0, 0, layer, | - | ||||||||||||
1286 | mipLevelSize(mipLevel, dimensions[0]), | - | ||||||||||||
1287 | mipLevelSize(mipLevel, dimensions[1]), | - | ||||||||||||
1288 | mipLevelSize(mipLevel, dimensions[2]), | - | ||||||||||||
1289 | sourceFormat, sourceType, data, options); | - | ||||||||||||
1290 | break; | - | ||||||||||||
1291 | - | |||||||||||||
1292 | case QOpenGLTexture::TargetCubeMap: | - | ||||||||||||
1293 | Q_UNUSED(layer); | - | ||||||||||||
1294 | texFuncs->glTextureSubImage2D(textureId, cubeFace, bindingTarget, mipLevel, | - | ||||||||||||
1295 | 0, 0, | - | ||||||||||||
1296 | mipLevelSize(mipLevel, dimensions[0]), | - | ||||||||||||
1297 | mipLevelSize(mipLevel, dimensions[1]), | - | ||||||||||||
1298 | sourceFormat, sourceType, data, options); | - | ||||||||||||
1299 | break; | - | ||||||||||||
1300 | - | |||||||||||||
1301 | case QOpenGLTexture::TargetCubeMapArray: { | - | ||||||||||||
1302 | int faceIndex = cubeFace - QOpenGLTexture::CubeMapPositiveX; | - | ||||||||||||
1303 | int layerFace = 6 * layer + faceIndex; | - | ||||||||||||
1304 | texFuncs->glTextureSubImage3D(textureId, target, bindingTarget, mipLevel, | - | ||||||||||||
1305 | 0, 0, layerFace, | - | ||||||||||||
1306 | mipLevelSize(mipLevel, dimensions[0]), | - | ||||||||||||
1307 | mipLevelSize(mipLevel, dimensions[1]), | - | ||||||||||||
1308 | 1, | - | ||||||||||||
1309 | sourceFormat, sourceType, data, options); | - | ||||||||||||
1310 | break; | - | ||||||||||||
1311 | } | - | ||||||||||||
1312 | - | |||||||||||||
1313 | case QOpenGLTexture::TargetRectangle: | - | ||||||||||||
1314 | Q_UNUSED(mipLevel); | - | ||||||||||||
1315 | Q_UNUSED(layer); | - | ||||||||||||
1316 | Q_UNUSED(cubeFace); | - | ||||||||||||
1317 | texFuncs->glTextureSubImage2D(textureId, target, bindingTarget, 0, | - | ||||||||||||
1318 | 0, 0, | - | ||||||||||||
1319 | dimensions[0], | - | ||||||||||||
1320 | dimensions[1], | - | ||||||||||||
1321 | sourceFormat, sourceType, data, options); | - | ||||||||||||
1322 | break; | - | ||||||||||||
1323 | - | |||||||||||||
1324 | case QOpenGLTexture::Target2DMultisample: | - | ||||||||||||
1325 | case QOpenGLTexture::Target2DMultisampleArray: | - | ||||||||||||
1326 | case QOpenGLTexture::TargetBuffer: | - | ||||||||||||
1327 | // We don't upload pixel data for these targets | - | ||||||||||||
1328 | qWarning("QOpenGLTexture::setData(): Texture target does not support pixel data upload"); | - | ||||||||||||
1329 | break; | - | ||||||||||||
1330 | } | - | ||||||||||||
1331 | - | |||||||||||||
1332 | // If requested perform automatic mip map generation | - | ||||||||||||
1333 | if (mipLevel == 0 && autoGenerateMipMaps && mipLevels > 1) { | - | ||||||||||||
1334 | Q_Q(QOpenGLTexture); | - | ||||||||||||
1335 | q->generateMipMaps(); | - | ||||||||||||
1336 | } | - | ||||||||||||
1337 | } | - | ||||||||||||
1338 | - | |||||||||||||
1339 | void QOpenGLTexturePrivate::setCompressedData(int mipLevel, int layer, QOpenGLTexture::CubeMapFace cubeFace, | - | ||||||||||||
1340 | int dataSize, const void *data, | - | ||||||||||||
1341 | const QOpenGLPixelTransferOptions * const options) | - | ||||||||||||
1342 | { | - | ||||||||||||
1343 | if (!isCompressedFormat(format)) { | - | ||||||||||||
1344 | qWarning("Cannot set compressed data for non-compressed format 0x%x", format); | - | ||||||||||||
1345 | return; | - | ||||||||||||
1346 | } | - | ||||||||||||
1347 | - | |||||||||||||
1348 | const bool needsFullSpec = !isUsingImmutableStorage(); // was allocateStorage() a no-op? | - | ||||||||||||
1349 | - | |||||||||||||
1350 | switch (target) { | - | ||||||||||||
1351 | case QOpenGLTexture::Target1D: | - | ||||||||||||
1352 | Q_UNUSED(layer); | - | ||||||||||||
1353 | Q_UNUSED(cubeFace); | - | ||||||||||||
1354 | if (needsFullSpec) { | - | ||||||||||||
1355 | texFuncs->glCompressedTextureImage1D(textureId, target, bindingTarget, mipLevel, | - | ||||||||||||
1356 | format, | - | ||||||||||||
1357 | mipLevelSize(mipLevel, dimensions[0]), | - | ||||||||||||
1358 | 0, dataSize, data, options); | - | ||||||||||||
1359 | } else { | - | ||||||||||||
1360 | texFuncs->glCompressedTextureSubImage1D(textureId, target, bindingTarget, mipLevel, | - | ||||||||||||
1361 | 0, mipLevelSize( mipLevel, dimensions[0] ), | - | ||||||||||||
1362 | format, dataSize, data, options); | - | ||||||||||||
1363 | } | - | ||||||||||||
1364 | break; | - | ||||||||||||
1365 | - | |||||||||||||
1366 | case QOpenGLTexture::Target1DArray: | - | ||||||||||||
1367 | Q_UNUSED(cubeFace); | - | ||||||||||||
1368 | if (!needsFullSpec) { | - | ||||||||||||
1369 | texFuncs->glCompressedTextureSubImage2D(textureId, target, bindingTarget, mipLevel, | - | ||||||||||||
1370 | 0, layer, | - | ||||||||||||
1371 | mipLevelSize(mipLevel, dimensions[0]), | - | ||||||||||||
1372 | 1, | - | ||||||||||||
1373 | format, dataSize, data, options); | - | ||||||||||||
1374 | } | - | ||||||||||||
1375 | break; | - | ||||||||||||
1376 | - | |||||||||||||
1377 | case QOpenGLTexture::Target2D: | - | ||||||||||||
1378 | Q_UNUSED(layer); | - | ||||||||||||
1379 | Q_UNUSED(cubeFace); | - | ||||||||||||
1380 | if (needsFullSpec) { | - | ||||||||||||
1381 | texFuncs->glCompressedTextureImage2D(textureId, target, bindingTarget, mipLevel, | - | ||||||||||||
1382 | format, | - | ||||||||||||
1383 | mipLevelSize(mipLevel, dimensions[0]), | - | ||||||||||||
1384 | mipLevelSize(mipLevel, dimensions[1]), | - | ||||||||||||
1385 | 0, dataSize, data, options); | - | ||||||||||||
1386 | } else { | - | ||||||||||||
1387 | texFuncs->glCompressedTextureSubImage2D(textureId, target, bindingTarget, mipLevel, | - | ||||||||||||
1388 | 0, 0, | - | ||||||||||||
1389 | mipLevelSize(mipLevel, dimensions[0]), | - | ||||||||||||
1390 | mipLevelSize(mipLevel, dimensions[1]), | - | ||||||||||||
1391 | format, dataSize, data, options); | - | ||||||||||||
1392 | } | - | ||||||||||||
1393 | break; | - | ||||||||||||
1394 | - | |||||||||||||
1395 | case QOpenGLTexture::Target2DArray: | - | ||||||||||||
1396 | Q_UNUSED(cubeFace); | - | ||||||||||||
1397 | if (!needsFullSpec) { | - | ||||||||||||
1398 | texFuncs->glCompressedTextureSubImage3D(textureId, target, bindingTarget, mipLevel, | - | ||||||||||||
1399 | 0, 0, layer, | - | ||||||||||||
1400 | mipLevelSize(mipLevel, dimensions[0]), | - | ||||||||||||
1401 | mipLevelSize(mipLevel, dimensions[1]), | - | ||||||||||||
1402 | 1, | - | ||||||||||||
1403 | format, dataSize, data, options); | - | ||||||||||||
1404 | } | - | ||||||||||||
1405 | break; | - | ||||||||||||
1406 | - | |||||||||||||
1407 | case QOpenGLTexture::Target3D: | - | ||||||||||||
1408 | Q_UNUSED(cubeFace); | - | ||||||||||||
1409 | if (needsFullSpec) { | - | ||||||||||||
1410 | texFuncs->glCompressedTextureImage3D(textureId, target, bindingTarget, mipLevel, | - | ||||||||||||
1411 | format, | - | ||||||||||||
1412 | mipLevelSize(mipLevel, dimensions[0]), | - | ||||||||||||
1413 | mipLevelSize(mipLevel, dimensions[1]), | - | ||||||||||||
1414 | mipLevelSize(mipLevel, dimensions[2]), | - | ||||||||||||
1415 | 0, dataSize, data, options); | - | ||||||||||||
1416 | } else { | - | ||||||||||||
1417 | texFuncs->glCompressedTextureSubImage3D(textureId, target, bindingTarget, mipLevel, | - | ||||||||||||
1418 | 0, 0, layer, | - | ||||||||||||
1419 | mipLevelSize(mipLevel, dimensions[0]), | - | ||||||||||||
1420 | mipLevelSize(mipLevel, dimensions[1]), | - | ||||||||||||
1421 | mipLevelSize(mipLevel, dimensions[2]), | - | ||||||||||||
1422 | format, dataSize, data, options); | - | ||||||||||||
1423 | } | - | ||||||||||||
1424 | break; | - | ||||||||||||
1425 | - | |||||||||||||
1426 | case QOpenGLTexture::TargetCubeMap: | - | ||||||||||||
1427 | Q_UNUSED(layer); | - | ||||||||||||
1428 | if (needsFullSpec) { | - | ||||||||||||
1429 | texFuncs->glCompressedTextureImage2D(textureId, cubeFace, bindingTarget, mipLevel, | - | ||||||||||||
1430 | format, | - | ||||||||||||
1431 | mipLevelSize(mipLevel, dimensions[0]), | - | ||||||||||||
1432 | mipLevelSize(mipLevel, dimensions[1]), | - | ||||||||||||
1433 | 0, dataSize, data, options); | - | ||||||||||||
1434 | } else { | - | ||||||||||||
1435 | texFuncs->glCompressedTextureSubImage2D(textureId, cubeFace, bindingTarget, mipLevel, | - | ||||||||||||
1436 | 0, 0, | - | ||||||||||||
1437 | mipLevelSize(mipLevel, dimensions[0]), | - | ||||||||||||
1438 | mipLevelSize(mipLevel, dimensions[1]), | - | ||||||||||||
1439 | format, dataSize, data, options); | - | ||||||||||||
1440 | } | - | ||||||||||||
1441 | break; | - | ||||||||||||
1442 | - | |||||||||||||
1443 | case QOpenGLTexture::TargetCubeMapArray: { | - | ||||||||||||
1444 | int faceIndex = cubeFace - QOpenGLTexture::CubeMapPositiveX; | - | ||||||||||||
1445 | int layerFace = 6 * layer + faceIndex; | - | ||||||||||||
1446 | if (!needsFullSpec) { | - | ||||||||||||
1447 | texFuncs->glCompressedTextureSubImage3D(textureId, target, bindingTarget, mipLevel, | - | ||||||||||||
1448 | 0, 0, layerFace, | - | ||||||||||||
1449 | mipLevelSize(mipLevel, dimensions[0]), | - | ||||||||||||
1450 | mipLevelSize(mipLevel, dimensions[1]), | - | ||||||||||||
1451 | 1, | - | ||||||||||||
1452 | format, dataSize, data, options); | - | ||||||||||||
1453 | } | - | ||||||||||||
1454 | break; | - | ||||||||||||
1455 | } | - | ||||||||||||
1456 | - | |||||||||||||
1457 | case QOpenGLTexture::TargetRectangle: | - | ||||||||||||
1458 | case QOpenGLTexture::Target2DMultisample: | - | ||||||||||||
1459 | case QOpenGLTexture::Target2DMultisampleArray: | - | ||||||||||||
1460 | case QOpenGLTexture::TargetBuffer: | - | ||||||||||||
1461 | // We don't upload pixel data for these targets | - | ||||||||||||
1462 | qWarning("QOpenGLTexture::setCompressedData(): Texture target does not support pixel data upload"); | - | ||||||||||||
1463 | break; | - | ||||||||||||
1464 | } | - | ||||||||||||
1465 | - | |||||||||||||
1466 | // If requested perform automatic mip map generation | - | ||||||||||||
1467 | if (mipLevel == 0 && autoGenerateMipMaps && mipLevels > 1) { | - | ||||||||||||
1468 | Q_Q(QOpenGLTexture); | - | ||||||||||||
1469 | q->generateMipMaps(); | - | ||||||||||||
1470 | } | - | ||||||||||||
1471 | } | - | ||||||||||||
1472 | - | |||||||||||||
1473 | void QOpenGLTexturePrivate::setWrapMode(QOpenGLTexture::WrapMode mode) | - | ||||||||||||
1474 | { | - | ||||||||||||
1475 | switch (target) { | - | ||||||||||||
1476 | case QOpenGLTexture::Target1D: | - | ||||||||||||
1477 | case QOpenGLTexture::Target1DArray: | - | ||||||||||||
1478 | case QOpenGLTexture::TargetBuffer: | - | ||||||||||||
1479 | wrapModes[0] = mode; | - | ||||||||||||
1480 | texFuncs->glTextureParameteri(textureId, target, bindingTarget, GL_TEXTURE_WRAP_S, mode); | - | ||||||||||||
1481 | break; | - | ||||||||||||
1482 | - | |||||||||||||
1483 | case QOpenGLTexture::Target2D: | - | ||||||||||||
1484 | case QOpenGLTexture::Target2DArray: | - | ||||||||||||
1485 | case QOpenGLTexture::TargetCubeMap: | - | ||||||||||||
1486 | case QOpenGLTexture::TargetCubeMapArray: | - | ||||||||||||
1487 | case QOpenGLTexture::Target2DMultisample: | - | ||||||||||||
1488 | case QOpenGLTexture::Target2DMultisampleArray: | - | ||||||||||||
1489 | case QOpenGLTexture::TargetRectangle: | - | ||||||||||||
1490 | wrapModes[0] = wrapModes[1] = mode; | - | ||||||||||||
1491 | texFuncs->glTextureParameteri(textureId, target, bindingTarget, GL_TEXTURE_WRAP_S, mode); | - | ||||||||||||
1492 | texFuncs->glTextureParameteri(textureId, target, bindingTarget, GL_TEXTURE_WRAP_T, mode); | - | ||||||||||||
1493 | break; | - | ||||||||||||
1494 | - | |||||||||||||
1495 | case QOpenGLTexture::Target3D: | - | ||||||||||||
1496 | wrapModes[0] = wrapModes[1] = wrapModes[2] = mode; | - | ||||||||||||
1497 | texFuncs->glTextureParameteri(textureId, target, bindingTarget, GL_TEXTURE_WRAP_S, mode); | - | ||||||||||||
1498 | texFuncs->glTextureParameteri(textureId, target, bindingTarget, GL_TEXTURE_WRAP_T, mode); | - | ||||||||||||
1499 | texFuncs->glTextureParameteri(textureId, target, bindingTarget, GL_TEXTURE_WRAP_R, mode); | - | ||||||||||||
1500 | break; | - | ||||||||||||
1501 | } | - | ||||||||||||
1502 | } | - | ||||||||||||
1503 | - | |||||||||||||
1504 | void QOpenGLTexturePrivate::setWrapMode(QOpenGLTexture::CoordinateDirection direction, QOpenGLTexture::WrapMode mode) | - | ||||||||||||
1505 | { | - | ||||||||||||
1506 | switch (target) { | - | ||||||||||||
1507 | case QOpenGLTexture::Target1D: | - | ||||||||||||
1508 | case QOpenGLTexture::Target1DArray: | - | ||||||||||||
1509 | case QOpenGLTexture::TargetBuffer: | - | ||||||||||||
1510 | switch (direction) { | - | ||||||||||||
1511 | case QOpenGLTexture::DirectionS: | - | ||||||||||||
1512 | wrapModes[0] = mode; | - | ||||||||||||
1513 | texFuncs->glTextureParameteri(textureId, target, bindingTarget, GL_TEXTURE_WRAP_S, mode); | - | ||||||||||||
1514 | break; | - | ||||||||||||
1515 | - | |||||||||||||
1516 | case QOpenGLTexture::DirectionT: | - | ||||||||||||
1517 | case QOpenGLTexture::DirectionR: | - | ||||||||||||
1518 | qWarning("QOpenGLTexture::setWrapMode() direction not valid for this texture target"); | - | ||||||||||||
1519 | break; | - | ||||||||||||
1520 | } | - | ||||||||||||
1521 | break; | - | ||||||||||||
1522 | - | |||||||||||||
1523 | case QOpenGLTexture::Target2D: | - | ||||||||||||
1524 | case QOpenGLTexture::Target2DArray: | - | ||||||||||||
1525 | case QOpenGLTexture::TargetCubeMap: | - | ||||||||||||
1526 | case QOpenGLTexture::TargetCubeMapArray: | - | ||||||||||||
1527 | case QOpenGLTexture::Target2DMultisample: | - | ||||||||||||
1528 | case QOpenGLTexture::Target2DMultisampleArray: | - | ||||||||||||
1529 | case QOpenGLTexture::TargetRectangle: | - | ||||||||||||
1530 | switch (direction) { | - | ||||||||||||
1531 | case QOpenGLTexture::DirectionS: | - | ||||||||||||
1532 | wrapModes[0] = mode; | - | ||||||||||||
1533 | texFuncs->glTextureParameteri(textureId, target, bindingTarget, GL_TEXTURE_WRAP_S, mode); | - | ||||||||||||
1534 | break; | - | ||||||||||||
1535 | - | |||||||||||||
1536 | case QOpenGLTexture::DirectionT: | - | ||||||||||||
1537 | wrapModes[1] = mode; | - | ||||||||||||
1538 | texFuncs->glTextureParameteri(textureId, target, bindingTarget, GL_TEXTURE_WRAP_T, mode); | - | ||||||||||||
1539 | break; | - | ||||||||||||
1540 | - | |||||||||||||
1541 | case QOpenGLTexture::DirectionR: | - | ||||||||||||
1542 | qWarning("QOpenGLTexture::setWrapMode() direction not valid for this texture target"); | - | ||||||||||||
1543 | break; | - | ||||||||||||
1544 | } | - | ||||||||||||
1545 | break; | - | ||||||||||||
1546 | - | |||||||||||||
1547 | case QOpenGLTexture::Target3D: | - | ||||||||||||
1548 | switch (direction) { | - | ||||||||||||
1549 | case QOpenGLTexture::DirectionS: | - | ||||||||||||
1550 | wrapModes[0] = mode; | - | ||||||||||||
1551 | texFuncs->glTextureParameteri(textureId, target, bindingTarget, direction, mode); | - | ||||||||||||
1552 | break; | - | ||||||||||||
1553 | - | |||||||||||||
1554 | case QOpenGLTexture::DirectionT: | - | ||||||||||||
1555 | wrapModes[1] = mode; | - | ||||||||||||
1556 | texFuncs->glTextureParameteri(textureId, target, bindingTarget, direction, mode); | - | ||||||||||||
1557 | break; | - | ||||||||||||
1558 | - | |||||||||||||
1559 | case QOpenGLTexture::DirectionR: | - | ||||||||||||
1560 | wrapModes[2] = mode; | - | ||||||||||||
1561 | texFuncs->glTextureParameteri(textureId, target, bindingTarget, direction, mode); | - | ||||||||||||
1562 | break; | - | ||||||||||||
1563 | } | - | ||||||||||||
1564 | break; | - | ||||||||||||
1565 | } | - | ||||||||||||
1566 | } | - | ||||||||||||
1567 | - | |||||||||||||
1568 | QOpenGLTexture::WrapMode QOpenGLTexturePrivate::wrapMode(QOpenGLTexture::CoordinateDirection direction) const | - | ||||||||||||
1569 | { | - | ||||||||||||
1570 | switch (target) { | - | ||||||||||||
1571 | case QOpenGLTexture::Target1D: | - | ||||||||||||
1572 | case QOpenGLTexture::Target1DArray: | - | ||||||||||||
1573 | case QOpenGLTexture::TargetBuffer: | - | ||||||||||||
1574 | switch (direction) { | - | ||||||||||||
1575 | case QOpenGLTexture::DirectionS: | - | ||||||||||||
1576 | return wrapModes[0]; | - | ||||||||||||
1577 | - | |||||||||||||
1578 | case QOpenGLTexture::DirectionT: | - | ||||||||||||
1579 | case QOpenGLTexture::DirectionR: | - | ||||||||||||
1580 | qWarning("QOpenGLTexture::wrapMode() direction not valid for this texture target"); | - | ||||||||||||
1581 | return QOpenGLTexture::Repeat; | - | ||||||||||||
1582 | } | - | ||||||||||||
1583 | break; | - | ||||||||||||
1584 | - | |||||||||||||
1585 | case QOpenGLTexture::Target2D: | - | ||||||||||||
1586 | case QOpenGLTexture::Target2DArray: | - | ||||||||||||
1587 | case QOpenGLTexture::TargetCubeMap: | - | ||||||||||||
1588 | case QOpenGLTexture::TargetCubeMapArray: | - | ||||||||||||
1589 | case QOpenGLTexture::Target2DMultisample: | - | ||||||||||||
1590 | case QOpenGLTexture::Target2DMultisampleArray: | - | ||||||||||||
1591 | case QOpenGLTexture::TargetRectangle: | - | ||||||||||||
1592 | switch (direction) { | - | ||||||||||||
1593 | case QOpenGLTexture::DirectionS: | - | ||||||||||||
1594 | return wrapModes[0]; | - | ||||||||||||
1595 | - | |||||||||||||
1596 | case QOpenGLTexture::DirectionT: | - | ||||||||||||
1597 | return wrapModes[1]; | - | ||||||||||||
1598 | - | |||||||||||||
1599 | case QOpenGLTexture::DirectionR: | - | ||||||||||||
1600 | qWarning("QOpenGLTexture::wrapMode() direction not valid for this texture target"); | - | ||||||||||||
1601 | return QOpenGLTexture::Repeat; | - | ||||||||||||
1602 | } | - | ||||||||||||
1603 | break; | - | ||||||||||||
1604 | - | |||||||||||||
1605 | case QOpenGLTexture::Target3D: | - | ||||||||||||
1606 | switch (direction) { | - | ||||||||||||
1607 | case QOpenGLTexture::DirectionS: | - | ||||||||||||
1608 | return wrapModes[0]; | - | ||||||||||||
1609 | - | |||||||||||||
1610 | case QOpenGLTexture::DirectionT: | - | ||||||||||||
1611 | return wrapModes[1]; | - | ||||||||||||
1612 | - | |||||||||||||
1613 | case QOpenGLTexture::DirectionR: | - | ||||||||||||
1614 | return wrapModes[2]; | - | ||||||||||||
1615 | } | - | ||||||||||||
1616 | break; | - | ||||||||||||
1617 | } | - | ||||||||||||
1618 | // Should never get here | - | ||||||||||||
1619 | Q_ASSERT(false); | - | ||||||||||||
1620 | return QOpenGLTexture::Repeat; | - | ||||||||||||
1621 | } | - | ||||||||||||
1622 | - | |||||||||||||
1623 | QOpenGLTexture *QOpenGLTexturePrivate::createTextureView(QOpenGLTexture::Target viewTarget, | - | ||||||||||||
1624 | QOpenGLTexture::TextureFormat viewFormat, | - | ||||||||||||
1625 | int minimumMipmapLevel, int maximumMipmapLevel, | - | ||||||||||||
1626 | int minimumLayer, int maximumLayer) const | - | ||||||||||||
1627 | { | - | ||||||||||||
1628 | // Do sanity checks - see http://www.opengl.org/wiki/GLAPI/glTextureView | - | ||||||||||||
1629 | - | |||||||||||||
1630 | // Check the targets are compatible | - | ||||||||||||
1631 | bool viewTargetCompatible = false; | - | ||||||||||||
1632 | switch (target) { | - | ||||||||||||
1633 | case QOpenGLTexture::Target1D: | - | ||||||||||||
1634 | case QOpenGLTexture::Target1DArray: | - | ||||||||||||
1635 | viewTargetCompatible = (viewTarget == QOpenGLTexture::Target1D | - | ||||||||||||
1636 | || viewTarget == QOpenGLTexture::Target1DArray); | - | ||||||||||||
1637 | break; | - | ||||||||||||
1638 | - | |||||||||||||
1639 | - | |||||||||||||
1640 | case QOpenGLTexture::Target2D: | - | ||||||||||||
1641 | case QOpenGLTexture::Target2DArray: | - | ||||||||||||
1642 | viewTargetCompatible = (viewTarget == QOpenGLTexture::Target2D | - | ||||||||||||
1643 | || viewTarget == QOpenGLTexture::Target2DArray); | - | ||||||||||||
1644 | break; | - | ||||||||||||
1645 | - | |||||||||||||
1646 | case QOpenGLTexture::Target3D: | - | ||||||||||||
1647 | viewTargetCompatible = (viewTarget == QOpenGLTexture::Target3D); | - | ||||||||||||
1648 | break; | - | ||||||||||||
1649 | - | |||||||||||||
1650 | case QOpenGLTexture::TargetCubeMap: | - | ||||||||||||
1651 | case QOpenGLTexture::TargetCubeMapArray: | - | ||||||||||||
1652 | viewTargetCompatible = (viewTarget == QOpenGLTexture::TargetCubeMap | - | ||||||||||||
1653 | || viewTarget == QOpenGLTexture::Target2D | - | ||||||||||||
1654 | || viewTarget == QOpenGLTexture::Target2DArray | - | ||||||||||||
1655 | || viewTarget == QOpenGLTexture::TargetCubeMapArray); | - | ||||||||||||
1656 | break; | - | ||||||||||||
1657 | - | |||||||||||||
1658 | case QOpenGLTexture::Target2DMultisample: | - | ||||||||||||
1659 | case QOpenGLTexture::Target2DMultisampleArray: | - | ||||||||||||
1660 | viewTargetCompatible = (viewTarget == QOpenGLTexture::Target2DMultisample | - | ||||||||||||
1661 | || viewTarget == QOpenGLTexture::Target2DMultisampleArray); | - | ||||||||||||
1662 | break; | - | ||||||||||||
1663 | - | |||||||||||||
1664 | case QOpenGLTexture::TargetRectangle: | - | ||||||||||||
1665 | viewTargetCompatible = (viewTarget == QOpenGLTexture::TargetRectangle); | - | ||||||||||||
1666 | break; | - | ||||||||||||
1667 | - | |||||||||||||
1668 | case QOpenGLTexture::TargetBuffer: | - | ||||||||||||
1669 | // Cannot be used with texture views | - | ||||||||||||
1670 | break; | - | ||||||||||||
1671 | } | - | ||||||||||||
1672 | - | |||||||||||||
1673 | if (!viewTargetCompatible) { | - | ||||||||||||
1674 | qWarning("QOpenGLTexture::createTextureView(): Incompatible source and view targets"); | - | ||||||||||||
1675 | return 0; | - | ||||||||||||
1676 | } | - | ||||||||||||
1677 | - | |||||||||||||
1678 | // Check the formats are compatible | - | ||||||||||||
1679 | bool viewFormatCompatible = false; | - | ||||||||||||
1680 | switch (formatClass) { | - | ||||||||||||
1681 | case QOpenGLTexture::NoFormatClass: | - | ||||||||||||
1682 | break; | - | ||||||||||||
1683 | - | |||||||||||||
1684 | case QOpenGLTexture::FormatClass_128Bit: | - | ||||||||||||
1685 | viewFormatCompatible = (viewFormat == QOpenGLTexture::RGBA32F | - | ||||||||||||
1686 | || viewFormat == QOpenGLTexture::RGBA32U | - | ||||||||||||
1687 | || viewFormat == QOpenGLTexture::RGBA32I); | - | ||||||||||||
1688 | break; | - | ||||||||||||
1689 | - | |||||||||||||
1690 | case QOpenGLTexture::FormatClass_96Bit: | - | ||||||||||||
1691 | viewFormatCompatible = (viewFormat == QOpenGLTexture::RGB32F | - | ||||||||||||
1692 | || viewFormat == QOpenGLTexture::RGB32U | - | ||||||||||||
1693 | || viewFormat == QOpenGLTexture::RGB32I); | - | ||||||||||||
1694 | break; | - | ||||||||||||
1695 | - | |||||||||||||
1696 | case QOpenGLTexture::FormatClass_64Bit: | - | ||||||||||||
1697 | viewFormatCompatible = (viewFormat == QOpenGLTexture::RGBA16F | - | ||||||||||||
1698 | || viewFormat == QOpenGLTexture::RG32F | - | ||||||||||||
1699 | || viewFormat == QOpenGLTexture::RGBA16U | - | ||||||||||||
1700 | || viewFormat == QOpenGLTexture::RG32U | - | ||||||||||||
1701 | || viewFormat == QOpenGLTexture::RGBA16I | - | ||||||||||||
1702 | || viewFormat == QOpenGLTexture::RG32I | - | ||||||||||||
1703 | || viewFormat == QOpenGLTexture::RGBA16_UNorm | - | ||||||||||||
1704 | || viewFormat == QOpenGLTexture::RGBA16_SNorm); | - | ||||||||||||
1705 | break; | - | ||||||||||||
1706 | - | |||||||||||||
1707 | case QOpenGLTexture::FormatClass_48Bit: | - | ||||||||||||
1708 | viewFormatCompatible = (viewFormat == QOpenGLTexture::RGB16_UNorm | - | ||||||||||||
1709 | || viewFormat == QOpenGLTexture::RGB16_SNorm | - | ||||||||||||
1710 | || viewFormat == QOpenGLTexture::RGB16F | - | ||||||||||||
1711 | || viewFormat == QOpenGLTexture::RGB16U | - | ||||||||||||
1712 | || viewFormat == QOpenGLTexture::RGB16I); | - | ||||||||||||
1713 | break; | - | ||||||||||||
1714 | - | |||||||||||||
1715 | case QOpenGLTexture::FormatClass_32Bit: | - | ||||||||||||
1716 | viewFormatCompatible = (viewFormat == QOpenGLTexture::RG16F | - | ||||||||||||
1717 | || viewFormat == QOpenGLTexture::RG11B10F | - | ||||||||||||
1718 | || viewFormat == QOpenGLTexture::R32F | - | ||||||||||||
1719 | || viewFormat == QOpenGLTexture::RGB10A2 | - | ||||||||||||
1720 | || viewFormat == QOpenGLTexture::RGBA8U | - | ||||||||||||
1721 | || viewFormat == QOpenGLTexture::RG16U | - | ||||||||||||
1722 | || viewFormat == QOpenGLTexture::R32U | - | ||||||||||||
1723 | || viewFormat == QOpenGLTexture::RGBA8I | - | ||||||||||||
1724 | || viewFormat == QOpenGLTexture::RG16I | - | ||||||||||||
1725 | || viewFormat == QOpenGLTexture::R32I | - | ||||||||||||
1726 | || viewFormat == QOpenGLTexture::RGBA8_UNorm | - | ||||||||||||
1727 | || viewFormat == QOpenGLTexture::RG16_UNorm | - | ||||||||||||
1728 | || viewFormat == QOpenGLTexture::RGBA8_SNorm | - | ||||||||||||
1729 | || viewFormat == QOpenGLTexture::RG16_SNorm | - | ||||||||||||
1730 | || viewFormat == QOpenGLTexture::SRGB8_Alpha8 | - | ||||||||||||
1731 | || viewFormat == QOpenGLTexture::RGB9E5); | - | ||||||||||||
1732 | break; | - | ||||||||||||
1733 | - | |||||||||||||
1734 | case QOpenGLTexture::FormatClass_24Bit: | - | ||||||||||||
1735 | viewFormatCompatible = (viewFormat == QOpenGLTexture::RGB8_UNorm | - | ||||||||||||
1736 | || viewFormat == QOpenGLTexture::RGB8_SNorm | - | ||||||||||||
1737 | || viewFormat == QOpenGLTexture::SRGB8 | - | ||||||||||||
1738 | || viewFormat == QOpenGLTexture::RGB8U | - | ||||||||||||
1739 | || viewFormat == QOpenGLTexture::RGB8I); | - | ||||||||||||
1740 | break; | - | ||||||||||||
1741 | - | |||||||||||||
1742 | case QOpenGLTexture::FormatClass_16Bit: | - | ||||||||||||
1743 | viewFormatCompatible = (viewFormat == QOpenGLTexture::R16F | - | ||||||||||||
1744 | || viewFormat == QOpenGLTexture::RG8U | - | ||||||||||||
1745 | || viewFormat == QOpenGLTexture::R16U | - | ||||||||||||
1746 | || viewFormat == QOpenGLTexture::RG8I | - | ||||||||||||
1747 | || viewFormat == QOpenGLTexture::R16I | - | ||||||||||||
1748 | || viewFormat == QOpenGLTexture::RG8_UNorm | - | ||||||||||||
1749 | || viewFormat == QOpenGLTexture::R16_UNorm | - | ||||||||||||
1750 | || viewFormat == QOpenGLTexture::RG8_SNorm | - | ||||||||||||
1751 | || viewFormat == QOpenGLTexture::R16_SNorm); | - | ||||||||||||
1752 | break; | - | ||||||||||||
1753 | - | |||||||||||||
1754 | case QOpenGLTexture::FormatClass_8Bit: | - | ||||||||||||
1755 | viewFormatCompatible = (viewFormat == QOpenGLTexture::R8U | - | ||||||||||||
1756 | || viewFormat == QOpenGLTexture::R8I | - | ||||||||||||
1757 | || viewFormat == QOpenGLTexture::R8_UNorm | - | ||||||||||||
1758 | || viewFormat == QOpenGLTexture::R8_SNorm); | - | ||||||||||||
1759 | break; | - | ||||||||||||
1760 | - | |||||||||||||
1761 | case QOpenGLTexture::FormatClass_RGTC1_R: | - | ||||||||||||
1762 | viewFormatCompatible = (viewFormat == QOpenGLTexture::R_ATI1N_UNorm | - | ||||||||||||
1763 | || viewFormat == QOpenGLTexture::R_ATI1N_SNorm); | - | ||||||||||||
1764 | break; | - | ||||||||||||
1765 | - | |||||||||||||
1766 | case QOpenGLTexture::FormatClass_RGTC2_RG: | - | ||||||||||||
1767 | viewFormatCompatible = (viewFormat == QOpenGLTexture::RG_ATI2N_UNorm | - | ||||||||||||
1768 | || viewFormat == QOpenGLTexture::RG_ATI2N_SNorm); | - | ||||||||||||
1769 | break; | - | ||||||||||||
1770 | - | |||||||||||||
1771 | case QOpenGLTexture::FormatClass_BPTC_Unorm: | - | ||||||||||||
1772 | viewFormatCompatible = (viewFormat == QOpenGLTexture::RGB_BP_UNorm | - | ||||||||||||
1773 | || viewFormat == QOpenGLTexture::SRGB_BP_UNorm); | - | ||||||||||||
1774 | break; | - | ||||||||||||
1775 | - | |||||||||||||
1776 | case QOpenGLTexture::FormatClass_BPTC_Float: | - | ||||||||||||
1777 | viewFormatCompatible = (viewFormat == QOpenGLTexture::RGB_BP_UNSIGNED_FLOAT | - | ||||||||||||
1778 | || viewFormat == QOpenGLTexture::RGB_BP_SIGNED_FLOAT); | - | ||||||||||||
1779 | break; | - | ||||||||||||
1780 | - | |||||||||||||
1781 | case QOpenGLTexture::FormatClass_S3TC_DXT1_RGB: | - | ||||||||||||
1782 | viewFormatCompatible = (viewFormat == QOpenGLTexture::RGB_DXT1 | - | ||||||||||||
1783 | || viewFormat == QOpenGLTexture::SRGB_DXT1); | - | ||||||||||||
1784 | break; | - | ||||||||||||
1785 | - | |||||||||||||
1786 | case QOpenGLTexture::FormatClass_S3TC_DXT1_RGBA: | - | ||||||||||||
1787 | viewFormatCompatible = (viewFormat == QOpenGLTexture::RGBA_DXT1 | - | ||||||||||||
1788 | || viewFormat == QOpenGLTexture::SRGB_Alpha_DXT1); | - | ||||||||||||
1789 | break; | - | ||||||||||||
1790 | - | |||||||||||||
1791 | case QOpenGLTexture::FormatClass_S3TC_DXT3_RGBA: | - | ||||||||||||
1792 | viewFormatCompatible = (viewFormat == QOpenGLTexture::RGBA_DXT3 | - | ||||||||||||
1793 | || viewFormat == QOpenGLTexture::SRGB_Alpha_DXT3); | - | ||||||||||||
1794 | break; | - | ||||||||||||
1795 | - | |||||||||||||
1796 | case QOpenGLTexture::FormatClass_S3TC_DXT5_RGBA: | - | ||||||||||||
1797 | viewFormatCompatible = (viewFormat == QOpenGLTexture::RGBA_DXT5 | - | ||||||||||||
1798 | || viewFormat == QOpenGLTexture::SRGB_Alpha_DXT5); | - | ||||||||||||
1799 | break; | - | ||||||||||||
1800 | - | |||||||||||||
1801 | case QOpenGLTexture::FormatClass_Unique: | - | ||||||||||||
1802 | viewFormatCompatible = (viewFormat == format); | - | ||||||||||||
1803 | break; | - | ||||||||||||
1804 | } | - | ||||||||||||
1805 | - | |||||||||||||
1806 | if (!viewFormatCompatible) { | - | ||||||||||||
1807 | qWarning("QOpenGLTexture::createTextureView(): Incompatible source and view formats"); | - | ||||||||||||
1808 | return 0; | - | ||||||||||||
1809 | } | - | ||||||||||||
1810 | - | |||||||||||||
1811 | - | |||||||||||||
1812 | // Create a view | - | ||||||||||||
1813 | QOpenGLTexture *view = new QOpenGLTexture(viewTarget); | - | ||||||||||||
1814 | view->setFormat(viewFormat); | - | ||||||||||||
1815 | view->create(); | - | ||||||||||||
1816 | view->d_ptr->textureView = true; | - | ||||||||||||
1817 | texFuncs->glTextureView(view->textureId(), viewTarget, textureId, viewFormat, | - | ||||||||||||
1818 | minimumMipmapLevel, maximumMipmapLevel - minimumMipmapLevel + 1, | - | ||||||||||||
1819 | minimumLayer, maximumLayer - minimumLayer + 1); | - | ||||||||||||
1820 | return view; | - | ||||||||||||
1821 | } | - | ||||||||||||
1822 | - | |||||||||||||
1823 | - | |||||||||||||
1824 | /*! | - | ||||||||||||
1825 | \class QOpenGLTexture | - | ||||||||||||
1826 | \inmodule QtGui | - | ||||||||||||
1827 | \since 5.2 | - | ||||||||||||
1828 | \wrapper | - | ||||||||||||
1829 | \brief The QOpenGLTexture class encapsulates an OpenGL texture object. | - | ||||||||||||
1830 | - | |||||||||||||
1831 | QOpenGLTexture makes it easy to work with OpenGL textures and the myriad features | - | ||||||||||||
1832 | and targets that they offer depending upon the capabilities of your OpenGL implementation. | - | ||||||||||||
1833 | - | |||||||||||||
1834 | The typical usage pattern for QOpenGLTexture is | - | ||||||||||||
1835 | \list | - | ||||||||||||
1836 | \li Instantiate the object specifying the texture target type | - | ||||||||||||
1837 | \li Set properties that affect the storage requirements e.g. storage format, dimensions | - | ||||||||||||
1838 | \li Allocate the server-side storage | - | ||||||||||||
1839 | \li Optionally upload pixel data | - | ||||||||||||
1840 | \li Optionally set any additional properties e.g. filtering and border options | - | ||||||||||||
1841 | \li Render with texture or render to texture | - | ||||||||||||
1842 | \endlist | - | ||||||||||||
1843 | - | |||||||||||||
1844 | In the common case of simply using a QImage as the source of texture pixel data | - | ||||||||||||
1845 | most of the above steps are performed automatically. | - | ||||||||||||
1846 | - | |||||||||||||
1847 | \code | - | ||||||||||||
1848 | // Prepare texture | - | ||||||||||||
1849 | QOpenGLTexture *texture = new QOpenGLTexture(QImage(fileName).mirrored()); | - | ||||||||||||
1850 | texture->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear); | - | ||||||||||||
1851 | texture->setMagnificationFilter(QOpenGLTexture::Linear); | - | ||||||||||||
1852 | ... | - | ||||||||||||
1853 | // Render with texture | - | ||||||||||||
1854 | texture->bind(); | - | ||||||||||||
1855 | glDrawArrays(...); | - | ||||||||||||
1856 | \endcode | - | ||||||||||||
1857 | - | |||||||||||||
1858 | Note that the QImage is mirrored vertically to account for the fact that | - | ||||||||||||
1859 | OpenGL and QImage use opposite directions for the y axis. Another option | - | ||||||||||||
1860 | would be to transform your texture coordinates. | - | ||||||||||||
1861 | */ | - | ||||||||||||
1862 | - | |||||||||||||
1863 | /*! | - | ||||||||||||
1864 | \enum QOpenGLTexture::Filter | - | ||||||||||||
1865 | This enum defines the filtering parameters for a QOpenGLTexture object. | - | ||||||||||||
1866 | \value Nearest Equivalent to GL_NEAREST | - | ||||||||||||
1867 | \value Linear Equivalent to GL_LINEAR | - | ||||||||||||
1868 | \value NearestMipMapNearest Equivalent to GL_NEAREST_MIPMAP_NEAREST | - | ||||||||||||
1869 | \value NearestMipMapLinear Equivalent to GL_NEAREST_MIPMAP_LINEAR | - | ||||||||||||
1870 | \value LinearMipMapNearest Equivalent to GL_LINEAR_MIPMAP_NEAREST | - | ||||||||||||
1871 | \value LinearMipMapLinear Equivalent to GL_LINEAR_MIPMAP_LINEAR | - | ||||||||||||
1872 | */ | - | ||||||||||||
1873 | - | |||||||||||||
1874 | /*! | - | ||||||||||||
1875 | \enum QOpenGLTexture::Target | - | ||||||||||||
1876 | This enum defines the texture target of a QOpenGLTexture object. | - | ||||||||||||
1877 | - | |||||||||||||
1878 | \value Target1D A 1-dimensional texture. | - | ||||||||||||
1879 | Equivalent to GL_TEXTURE_1D. | - | ||||||||||||
1880 | \value Target1DArray An array of 1-dimensional textures. | - | ||||||||||||
1881 | Equivalent to GL_TEXTURE_1D_ARRAY | - | ||||||||||||
1882 | \value Target2D A 2-dimensional texture. | - | ||||||||||||
1883 | Equivalent to GL_TEXTURE_2D | - | ||||||||||||
1884 | \value Target2DArray An array of 1-dimensional textures. | - | ||||||||||||
1885 | Equivalent to GL_TEXTURE_2D_ARRAY | - | ||||||||||||
1886 | \value Target3D A 3-dimensional texture. | - | ||||||||||||
1887 | Equivalent to GL_TEXTURE_3D | - | ||||||||||||
1888 | \value TargetCubeMap A cubemap texture. | - | ||||||||||||
1889 | Equivalent to GL_TEXTURE_CUBE_MAP | - | ||||||||||||
1890 | \value TargetCubeMapArray An array of cubemap textures. | - | ||||||||||||
1891 | Equivalent to GL_TEXTURE_CUBE_MAP_ARRAY | - | ||||||||||||
1892 | \value Target2DMultisample A 2-dimensional texture with multisample support. | - | ||||||||||||
1893 | Equivalent to GL_TEXTURE_2D_MULTISAMPLE | - | ||||||||||||
1894 | \value Target2DMultisampleArray An array of 2-dimensional textures with multisample support. | - | ||||||||||||
1895 | Equivalent to GL_TEXTURE_2D_MULTISAMPLE_ARRAY | - | ||||||||||||
1896 | \value TargetRectangle A rectangular 2-dimensional texture. | - | ||||||||||||
1897 | Equivalent to GL_TEXTURE_RECTANGLE | - | ||||||||||||
1898 | \value TargetBuffer A texture with data from an OpenGL buffer object. | - | ||||||||||||
1899 | Equivalent to GL_TEXTURE_BUFFER | - | ||||||||||||
1900 | */ | - | ||||||||||||
1901 | - | |||||||||||||
1902 | /*! | - | ||||||||||||
1903 | \enum QOpenGLTexture::BindingTarget | - | ||||||||||||
1904 | This enum defines the possible binding targets of texture units. | - | ||||||||||||
1905 | - | |||||||||||||
1906 | \value BindingTarget1D Equivalent to GL_TEXTURE_BINDING_1D | - | ||||||||||||
1907 | \value BindingTarget1DArray Equivalent to GL_TEXTURE_BINDING_1D_ARRAY | - | ||||||||||||
1908 | \value BindingTarget2D Equivalent to GL_TEXTURE_BINDING_2D | - | ||||||||||||
1909 | \value BindingTarget2DArray Equivalent to GL_TEXTURE_BINDING_2D_ARRAY | - | ||||||||||||
1910 | \value BindingTarget3D Equivalent to GL_TEXTURE_BINDING_3D | - | ||||||||||||
1911 | \value BindingTargetCubeMap Equivalent to GL_TEXTURE_BINDING_CUBE_MAP | - | ||||||||||||
1912 | \value BindingTargetCubeMapArray Equivalent to GL_TEXTURE_BINDING_CUBE_MAP_ARRAY | - | ||||||||||||
1913 | \value BindingTarget2DMultisample Equivalent to GL_TEXTURE_BINDING_2D_MULTISAMPLE | - | ||||||||||||
1914 | \value BindingTarget2DMultisampleArray Equivalent to GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY | - | ||||||||||||
1915 | \value BindingTargetRectangle Equivalent to GL_TEXTURE_BINDING_RECTANGLE | - | ||||||||||||
1916 | \value BindingTargetBuffer Equivalent to GL_TEXTURE_BINDING_BUFFER | - | ||||||||||||
1917 | */ | - | ||||||||||||
1918 | - | |||||||||||||
1919 | /*! | - | ||||||||||||
1920 | \enum QOpenGLTexture::MipMapGeneration | - | ||||||||||||
1921 | This enum defines the options to control mipmap generation. | - | ||||||||||||
1922 | - | |||||||||||||
1923 | \value GenerateMipMaps Mipmaps should be generated | - | ||||||||||||
1924 | \value DontGenerateMipMaps Mipmaps should not be generated | - | ||||||||||||
1925 | */ | - | ||||||||||||
1926 | - | |||||||||||||
1927 | /*! | - | ||||||||||||
1928 | \enum QOpenGLTexture::TextureUnitReset | - | ||||||||||||
1929 | This enum defines options ot control texture unit activation. | - | ||||||||||||
1930 | - | |||||||||||||
1931 | \value ResetTextureUnit The previous active texture unit will be reset | - | ||||||||||||
1932 | \value DontResetTextureUnit The previous active texture unit will not be rest | - | ||||||||||||
1933 | */ | - | ||||||||||||
1934 | - | |||||||||||||
1935 | /*! | - | ||||||||||||
1936 | \enum QOpenGLTexture::TextureFormat | - | ||||||||||||
1937 | This enum defines the possible texture formats. Depending upon your OpenGL | - | ||||||||||||
1938 | implementation only a subset of these may be supported. | - | ||||||||||||
1939 | - | |||||||||||||
1940 | \value NoFormat Equivalent to GL_NONE | - | ||||||||||||
1941 | - | |||||||||||||
1942 | \value R8_UNorm Equivalent to GL_R8 | - | ||||||||||||
1943 | \value RG8_UNorm Equivalent to GL_RG8 | - | ||||||||||||
1944 | \value RGB8_UNorm Equivalent to GL_RGB8 | - | ||||||||||||
1945 | \value RGBA8_UNorm Equivalent to GL_RGBA8 | - | ||||||||||||
1946 | - | |||||||||||||
1947 | \value R16_UNorm Equivalent to GL_R16 | - | ||||||||||||
1948 | \value RG16_UNorm Equivalent to GL_RG16 | - | ||||||||||||
1949 | \value RGB16_UNorm Equivalent to GL_RGB16 | - | ||||||||||||
1950 | \value RGBA16_UNorm Equivalent to GL_RGBA16 | - | ||||||||||||
1951 | - | |||||||||||||
1952 | \value R8_SNorm Equivalent to GL_R8_SNORM | - | ||||||||||||
1953 | \value RG8_SNorm Equivalent to GL_RG8_SNORM | - | ||||||||||||
1954 | \value RGB8_SNorm Equivalent to GL_RGB8_SNORM | - | ||||||||||||
1955 | \value RGBA8_SNorm Equivalent to GL_RGBA8_SNORM | - | ||||||||||||
1956 | - | |||||||||||||
1957 | \value R16_SNorm Equivalent to GL_R16_SNORM | - | ||||||||||||
1958 | \value RG16_SNorm Equivalent to GL_RG16_SNORM | - | ||||||||||||
1959 | \value RGB16_SNorm Equivalent to GL_RGB16_SNORM | - | ||||||||||||
1960 | \value RGBA16_SNorm Equivalent to GL_RGBA16_SNORM | - | ||||||||||||
1961 | - | |||||||||||||
1962 | \value R8U Equivalent to GL_R8UI | - | ||||||||||||
1963 | \value RG8U Equivalent to GL_RG8UI | - | ||||||||||||
1964 | \value RGB8U Equivalent to GL_RGB8UI | - | ||||||||||||
1965 | \value RGBA8U Equivalent to GL_RGBA8UI | - | ||||||||||||
1966 | - | |||||||||||||
1967 | \value R16U Equivalent to GL_R16UI | - | ||||||||||||
1968 | \value RG16U Equivalent to GL_RG16UI | - | ||||||||||||
1969 | \value RGB16U Equivalent to GL_RGB16UI | - | ||||||||||||
1970 | \value RGBA16U Equivalent to GL_RGBA16UI | - | ||||||||||||
1971 | - | |||||||||||||
1972 | \value R32U Equivalent to GL_R32UI | - | ||||||||||||
1973 | \value RG32U Equivalent to GL_RG32UI | - | ||||||||||||
1974 | \value RGB32U Equivalent to GL_RGB32UI | - | ||||||||||||
1975 | \value RGBA32U Equivalent to GL_RGBA32UI | - | ||||||||||||
1976 | - | |||||||||||||
1977 | \value R8I Equivalent to GL_R8I | - | ||||||||||||
1978 | \value RG8I Equivalent to GL_RG8I | - | ||||||||||||
1979 | \value RGB8I Equivalent to GL_RGB8I | - | ||||||||||||
1980 | \value RGBA8I Equivalent to GL_RGBA8I | - | ||||||||||||
1981 | - | |||||||||||||
1982 | \value R16I Equivalent to GL_R16I | - | ||||||||||||
1983 | \value RG16I Equivalent to GL_RG16I | - | ||||||||||||
1984 | \value RGB16I Equivalent to GL_RGB16I | - | ||||||||||||
1985 | \value RGBA16I Equivalent to GL_RGBA16I | - | ||||||||||||
1986 | - | |||||||||||||
1987 | \value R32I Equivalent to GL_R32I | - | ||||||||||||
1988 | \value RG32I Equivalent to GL_RG32I | - | ||||||||||||
1989 | \value RGB32I Equivalent to GL_RGB32I | - | ||||||||||||
1990 | \value RGBA32I Equivalent to GL_RGBA32I | - | ||||||||||||
1991 | - | |||||||||||||
1992 | \value R16F Equivalent to GL_R16F | - | ||||||||||||
1993 | \value RG16F Equivalent to GL_RG16F | - | ||||||||||||
1994 | \value RGB16F Equivalent to GL_RGB16F | - | ||||||||||||
1995 | \value RGBA16F Equivalent to GL_RGBA16F | - | ||||||||||||
1996 | - | |||||||||||||
1997 | \value R32F Equivalent to GL_R32F | - | ||||||||||||
1998 | \value RG32F Equivalent to GL_RG32F | - | ||||||||||||
1999 | \value RGB32F Equivalent to GL_RGB32F | - | ||||||||||||
2000 | \value RGBA32F Equivalent to GL_RGBA32F | - | ||||||||||||
2001 | - | |||||||||||||
2002 | \value RGB9E5 Equivalent to GL_RGB9_E5 | - | ||||||||||||
2003 | \value RG11B10F Equivalent to GL_R11F_G11F_B10F | - | ||||||||||||
2004 | \value RG3B2 Equivalent to GL_R3_G3_B2 | - | ||||||||||||
2005 | \value R5G6B5 Equivalent to GL_RGB565 | - | ||||||||||||
2006 | \value RGB5A1 Equivalent to GL_RGB5_A1 | - | ||||||||||||
2007 | \value RGBA4 Equivalent to GL_RGBA4 | - | ||||||||||||
2008 | \value RGB10A2 Equivalent to GL_RGB10_A2UI | - | ||||||||||||
2009 | - | |||||||||||||
2010 | \value D16 Equivalent to GL_DEPTH_COMPONENT16 | - | ||||||||||||
2011 | \value D24 Equivalent to GL_DEPTH_COMPONENT24 | - | ||||||||||||
2012 | \value D24S8 Equivalent to GL_DEPTH24_STENCIL8 | - | ||||||||||||
2013 | \value D32 Equivalent to GL_DEPTH_COMPONENT32 | - | ||||||||||||
2014 | \value D32F Equivalent to GL_DEPTH_COMPONENT32F | - | ||||||||||||
2015 | \value D32FS8X24 Equivalent to GL_DEPTH32F_STENCIL8 | - | ||||||||||||
2016 | \value S8 Equivalent to GL_STENCIL_INDEX8. Introduced in Qt 5.4 | - | ||||||||||||
2017 | - | |||||||||||||
2018 | \value RGB_DXT1 Equivalent to GL_COMPRESSED_RGB_S3TC_DXT1_EXT | - | ||||||||||||
2019 | \value RGBA_DXT1 Equivalent to GL_COMPRESSED_RGBA_S3TC_DXT1_EXT | - | ||||||||||||
2020 | \value RGBA_DXT3 Equivalent to GL_COMPRESSED_RGBA_S3TC_DXT3_EXT | - | ||||||||||||
2021 | \value RGBA_DXT5 Equivalent to GL_COMPRESSED_RGBA_S3TC_DXT5_EXT | - | ||||||||||||
2022 | \value R_ATI1N_UNorm Equivalent to GL_COMPRESSED_RED_RGTC1 | - | ||||||||||||
2023 | \value R_ATI1N_SNorm Equivalent to GL_COMPRESSED_SIGNED_RED_RGTC1 | - | ||||||||||||
2024 | \value RG_ATI2N_UNorm Equivalent to GL_COMPRESSED_RG_RGTC2 | - | ||||||||||||
2025 | \value RG_ATI2N_SNorm Equivalent to GL_COMPRESSED_SIGNED_RG_RGTC2 | - | ||||||||||||
2026 | \value RGB_BP_UNSIGNED_FLOAT Equivalent to GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB | - | ||||||||||||
2027 | \value RGB_BP_SIGNED_FLOAT Equivalent to GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB | - | ||||||||||||
2028 | \value RGB_BP_UNorm Equivalent to GL_COMPRESSED_RGBA_BPTC_UNORM_ARB | - | ||||||||||||
2029 | \value R11_EAC_UNorm Equivalent to GL_COMPRESSED_R11_EAC | - | ||||||||||||
2030 | \value R11_EAC_SNorm Equivalent to GL_COMPRESSED_SIGNED_R11_EAC | - | ||||||||||||
2031 | \value RG11_EAC_UNorm Equivalent to GL_COMPRESSED_RG11_EAC | - | ||||||||||||
2032 | \value RG11_EAC_SNorm Equivalent to GL_COMPRESSED_SIGNED_RG11_EAC | - | ||||||||||||
2033 | \value RGB8_ETC2 Equivalent to GL_COMPRESSED_RGB8_ETC2 | - | ||||||||||||
2034 | \value SRGB8_ETC2 Equivalent to GL_COMPRESSED_SRGB8_ETC2 | - | ||||||||||||
2035 | \value RGB8_PunchThrough_Alpha1_ETC2 Equivalent to GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 | - | ||||||||||||
2036 | \value SRGB8_PunchThrough_Alpha1_ETC2 Equivalent to GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 | - | ||||||||||||
2037 | \value RGBA8_ETC2_EAC Equivalent to GL_COMPRESSED_RGBA8_ETC2_EAC | - | ||||||||||||
2038 | \value SRGB8_Alpha8_ETC2_EAC Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC | - | ||||||||||||
2039 | \value RGB8_ETC1 Equivalent to GL_ETC1_RGB8_OES | - | ||||||||||||
2040 | - | |||||||||||||
2041 | \value SRGB8 Equivalent to GL_SRGB8 | - | ||||||||||||
2042 | \value SRGB8_Alpha8 Equivalent to GL_SRGB8_ALPHA8 | - | ||||||||||||
2043 | \value SRGB_DXT1 Equivalent to GL_COMPRESSED_SRGB_S3TC_DXT1_EXT | - | ||||||||||||
2044 | \value SRGB_Alpha_DXT1 Equivalent to GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT | - | ||||||||||||
2045 | \value SRGB_Alpha_DXT3 Equivalent to GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT | - | ||||||||||||
2046 | \value SRGB_Alpha_DXT5 Equivalent to GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT | - | ||||||||||||
2047 | \value SRGB_BP_UNorm Equivalent to GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB | - | ||||||||||||
2048 | - | |||||||||||||
2049 | \value DepthFormat Equivalent to GL_DEPTH_COMPONENT (only OpenGL ES 3 or ES 2 with OES_depth_texture) | - | ||||||||||||
2050 | \value AlphaFormat Equivalent to GL_ALPHA (OpenGL ES 2 only) | - | ||||||||||||
2051 | \value RGBFormat Equivalent to GL_RGB (OpenGL ES 2 only) | - | ||||||||||||
2052 | \value RGBAFormat Equivalent to GL_RGBA (OpenGL ES 2 only) | - | ||||||||||||
2053 | \value LuminanceFormat Equivalent to GL_LUMINANCE (OpenGL ES 2 only) | - | ||||||||||||
2054 | \value LuminanceAlphaFormat Equivalent to GL_LUMINANCE_ALPHA (OpenGL ES 2 only) | - | ||||||||||||
2055 | */ | - | ||||||||||||
2056 | - | |||||||||||||
2057 | /*! | - | ||||||||||||
2058 | \enum QOpenGLTexture::CubeMapFace | - | ||||||||||||
2059 | This enum defines the possible CubeMap faces. | - | ||||||||||||
2060 | - | |||||||||||||
2061 | \value CubeMapPositiveX Equivalent to GL_TEXTURE_CUBE_MAP_POSITIVE_X | - | ||||||||||||
2062 | \value CubeMapNegativeX Equivalent to GL_TEXTURE_CUBE_MAP_NEGATIVE_X | - | ||||||||||||
2063 | \value CubeMapPositiveY Equivalent to GL_TEXTURE_CUBE_MAP_POSITIVE_Y | - | ||||||||||||
2064 | \value CubeMapNegativeY Equivalent to GL_TEXTURE_CUBE_MAP_NEGATIVE_Y | - | ||||||||||||
2065 | \value CubeMapPositiveZ Equivalent to GL_TEXTURE_CUBE_MAP_POSITIVE_Z | - | ||||||||||||
2066 | \value CubeMapNegativeZ Equivalent to GL_TEXTURE_CUBE_MAP_NEGATIVE_Z | - | ||||||||||||
2067 | */ | - | ||||||||||||
2068 | - | |||||||||||||
2069 | /*! | - | ||||||||||||
2070 | \enum QOpenGLTexture::PixelFormat | - | ||||||||||||
2071 | This enum defines the possible client-side pixel formats for a pixel | - | ||||||||||||
2072 | transfer operation. | - | ||||||||||||
2073 | - | |||||||||||||
2074 | \value NoSourceFormat Equivalent to GL_NONE | - | ||||||||||||
2075 | \value Red Equivalent to GL_RED | - | ||||||||||||
2076 | \value RG Equivalent to GL_RG | - | ||||||||||||
2077 | \value RGB Equivalent to GL_RGB | - | ||||||||||||
2078 | \value BGR Equivalent to GL_BGR | - | ||||||||||||
2079 | \value RGBA Equivalent to GL_RGBA | - | ||||||||||||
2080 | \value BGRA Equivalent to GL_BGRA | - | ||||||||||||
2081 | \value Red_Integer Equivalent to GL_RED_INTEGER | - | ||||||||||||
2082 | \value RG_Integer Equivalent to GL_RG_INTEGER | - | ||||||||||||
2083 | \value RGB_Integer Equivalent to GL_RGB_INTEGER | - | ||||||||||||
2084 | \value BGR_Integer Equivalent to GL_BGR_INTEGER | - | ||||||||||||
2085 | \value RGBA_Integer Equivalent to GL_RGBA_INTEGER | - | ||||||||||||
2086 | \value BGRA_Integer Equivalent to GL_BGRA_INTEGER | - | ||||||||||||
2087 | \value Stencil Equivalent to GL_STENCIL_INDEX. Introduced in Qt 5.4 | - | ||||||||||||
2088 | \value Depth Equivalent to GL_DEPTH_COMPONENT | - | ||||||||||||
2089 | \value DepthStencil Equivalent to GL_DEPTH_STENCIL | - | ||||||||||||
2090 | \value Alpha Equivalent to GL_ALPHA (OpenGL ES 2 only) | - | ||||||||||||
2091 | \value Luminance Equivalent to GL_LUMINANCE (OpenGL ES 2 only) | - | ||||||||||||
2092 | \value LuminanceAlpha Equivalent to GL_LUMINANCE_ALPHA (OpenGL ES 2 only) | - | ||||||||||||
2093 | - | |||||||||||||
2094 | */ | - | ||||||||||||
2095 | - | |||||||||||||
2096 | /*! | - | ||||||||||||
2097 | \enum QOpenGLTexture::PixelType | - | ||||||||||||
2098 | This enum defines the possible pixel data types for a pixel transfer operation | - | ||||||||||||
2099 | - | |||||||||||||
2100 | \value NoPixelType Equivalent to GL_NONE | - | ||||||||||||
2101 | \value Int8 Equivalent to GL_BYTE | - | ||||||||||||
2102 | \value UInt8 Equivalent to GL_UNSIGNED_BYTE | - | ||||||||||||
2103 | \value Int16 Equivalent to GL_SHORT | - | ||||||||||||
2104 | \value UInt16 Equivalent to GL_UNSIGNED_SHORT | - | ||||||||||||
2105 | \value Int32 Equivalent to GL_INT | - | ||||||||||||
2106 | \value UInt32 Equivalent to GL_UNSIGNED_INT | - | ||||||||||||
2107 | \value Float16 Equivalent to GL_HALF_FLOAT | - | ||||||||||||
2108 | \value Float16OES Equivalent to GL_HALF_FLOAT_OES | - | ||||||||||||
2109 | \value Float32 Equivalent to GL_FLOAT | - | ||||||||||||
2110 | \value UInt32_RGB9_E5 Equivalent to GL_UNSIGNED_INT_5_9_9_9_REV | - | ||||||||||||
2111 | \value UInt32_RG11B10F Equivalent to GL_UNSIGNED_INT_10F_11F_11F_REV | - | ||||||||||||
2112 | \value UInt8_RG3B2 Equivalent to GL_UNSIGNED_BYTE_3_3_2 | - | ||||||||||||
2113 | \value UInt8_RG3B2_Rev Equivalent to GL_UNSIGNED_BYTE_2_3_3_REV | - | ||||||||||||
2114 | \value UInt16_RGB5A1 Equivalent to GL_UNSIGNED_SHORT_5_5_5_1 | - | ||||||||||||
2115 | \value UInt16_RGB5A1_Rev Equivalent to GL_UNSIGNED_SHORT_1_5_5_5_REV | - | ||||||||||||
2116 | \value UInt16_R5G6B5 Equivalent to GL_UNSIGNED_SHORT_5_6_5 | - | ||||||||||||
2117 | \value UInt16_R5G6B5_Rev Equivalent to GL_UNSIGNED_SHORT_5_6_5_REV | - | ||||||||||||
2118 | \value UInt16_RGBA4 Equivalent to GL_UNSIGNED_SHORT_4_4_4_4 | - | ||||||||||||
2119 | \value UInt16_RGBA4_Rev Equivalent to GL_UNSIGNED_SHORT_4_4_4_4_REV | - | ||||||||||||
2120 | \value UInt32_RGBA8 Equivalent to GL_UNSIGNED_INT_8_8_8_8 | - | ||||||||||||
2121 | \value UInt32_RGBA8_Rev Equivalent to GL_UNSIGNED_INT_8_8_8_8_REV | - | ||||||||||||
2122 | \value UInt32_RGB10A2 Equivalent to GL_UNSIGNED_INT_10_10_10_2 | - | ||||||||||||
2123 | \value UInt32_RGB10A2_Rev Equivalent to GL_UNSIGNED_INT_2_10_10_10_REV | - | ||||||||||||
2124 | \value UInt32_D24S8 Equivalent to GL_UNSIGNED_INT_24_8. Introduced in Qt 5.4 | - | ||||||||||||
2125 | \value Float32_D32_UInt32_S8_X24 Equivalent to GL_FLOAT_32_UNSIGNED_INT_24_8_REV. Introduced in Qt 5.4 | - | ||||||||||||
2126 | */ | - | ||||||||||||
2127 | - | |||||||||||||
2128 | /*! | - | ||||||||||||
2129 | \enum QOpenGLTexture::Feature | - | ||||||||||||
2130 | This enum defines the OpenGL texture-related features that can be tested for. | - | ||||||||||||
2131 | - | |||||||||||||
2132 | \value ImmutableStorage Support for immutable texture storage | - | ||||||||||||
2133 | \value ImmutableMultisampleStorage Support for immutable texture storage with | - | ||||||||||||
2134 | multisample targets | - | ||||||||||||
2135 | \value TextureRectangle Support for the GL_TEXTURE_RECTANGLE target | - | ||||||||||||
2136 | \value TextureArrays Support for texture targets with array layers | - | ||||||||||||
2137 | \value Texture3D Support for the 3 dimensional texture target | - | ||||||||||||
2138 | \value TextureMultisample Support for texture targets that have multisample capabilities | - | ||||||||||||
2139 | \value TextureBuffer Support for textures that use OpenGL buffer objects | - | ||||||||||||
2140 | as their data source | - | ||||||||||||
2141 | \value TextureCubeMapArrays Support for cubemap array texture target | - | ||||||||||||
2142 | \value Swizzle Support for texture component swizzle masks | - | ||||||||||||
2143 | \value StencilTexturing Support for stencil texturing (i.e. looking up depth or stencil | - | ||||||||||||
2144 | components of a combined depth/stencil format texture in GLSL shaders). | - | ||||||||||||
2145 | \value AnisotropicFiltering Support for anisotropic texture filtering | - | ||||||||||||
2146 | \value NPOTTextures Basic support for non-power-of-two textures | - | ||||||||||||
2147 | \value NPOTTextureRepeat Full support for non-power-of-two textures including texture | - | ||||||||||||
2148 | repeat modes | - | ||||||||||||
2149 | \value Texture1D Support for the 1 dimensional texture target | - | ||||||||||||
2150 | \value TextureComparisonOperators Support for texture comparison operators | - | ||||||||||||
2151 | \value TextureMipMapLevel Support for setting the base and maximum mipmap levels | - | ||||||||||||
2152 | */ | - | ||||||||||||
2153 | - | |||||||||||||
2154 | /*! | - | ||||||||||||
2155 | \enum QOpenGLTexture::SwizzleComponent | - | ||||||||||||
2156 | This enum defines the texture color components that can be assigned a swizzle mask. | - | ||||||||||||
2157 | - | |||||||||||||
2158 | \value SwizzleRed The red component. Equivalent to GL_TEXTURE_SWIZZLE_R | - | ||||||||||||
2159 | \value SwizzleGreen The green component. Equivalent to GL_TEXTURE_SWIZZLE_G | - | ||||||||||||
2160 | \value SwizzleBlue The blue component. Equivalent to GL_TEXTURE_SWIZZLE_B | - | ||||||||||||
2161 | \value SwizzleAlpha The alpha component. Equivalent to GL_TEXTURE_SWIZZLE_A | - | ||||||||||||
2162 | */ | - | ||||||||||||
2163 | - | |||||||||||||
2164 | /*! | - | ||||||||||||
2165 | \enum QOpenGLTexture::SwizzleValue | - | ||||||||||||
2166 | This enum defines the possible mask values for texture swizzling. | - | ||||||||||||
2167 | - | |||||||||||||
2168 | \value RedValue Maps the component to the red channel. Equivalent to GL_RED | - | ||||||||||||
2169 | \value GreenValue Maps the component to the green channel. Equivalent to GL_GREEN | - | ||||||||||||
2170 | \value BlueValue Maps the component to the blue channel. Equivalent to GL_BLUE | - | ||||||||||||
2171 | \value AlphaValue Maps the component to the alpha channel. Equivalent to GL_ALPHA | - | ||||||||||||
2172 | \value ZeroValue Maps the component to a fixed value of 0. Equivalent to GL_ZERO | - | ||||||||||||
2173 | \value OneValue Maps the component to a fixed value of 1. Equivalent to GL_ONE | - | ||||||||||||
2174 | */ | - | ||||||||||||
2175 | - | |||||||||||||
2176 | /*! | - | ||||||||||||
2177 | \enum QOpenGLTexture::WrapMode | - | ||||||||||||
2178 | This enum defines the possible texture coordinate wrapping modes. | - | ||||||||||||
2179 | - | |||||||||||||
2180 | \value Repeat Texture coordinate is repeated. Equivalent to GL_REPEAT | - | ||||||||||||
2181 | \value MirroredRepeat Texture coordinate is reflected about 0 and 1. Equivalent to GL_MIRRORED_REPEAT | - | ||||||||||||
2182 | \value ClampToEdge Clamps the texture coordinates to [0,1]. Equivalent to GL_CLAMP_TO_EDGE | - | ||||||||||||
2183 | \value ClampToBorder As for ClampToEdge but also blends samples at 0 and 1 with a | - | ||||||||||||
2184 | fixed border color. Equivalent to GL_CLAMP_TO_BORDER | - | ||||||||||||
2185 | */ | - | ||||||||||||
2186 | - | |||||||||||||
2187 | /*! | - | ||||||||||||
2188 | \enum QOpenGLTexture::CoordinateDirection | - | ||||||||||||
2189 | This enum defines the possible texture coordinate directions | - | ||||||||||||
2190 | - | |||||||||||||
2191 | \value DirectionS The horizontal direction. Equivalent to GL_TEXTURE_WRAP_S | - | ||||||||||||
2192 | \value DirectionT The vertical direction. Equivalent to GL_TEXTURE_WRAP_T | - | ||||||||||||
2193 | \value DirectionR The depth direction. Equivalent to GL_TEXTURE_WRAP_R | - | ||||||||||||
2194 | */ | - | ||||||||||||
2195 | - | |||||||||||||
2196 | /*! | - | ||||||||||||
2197 | Creates a QOpenGLTexture object that can later be bound to \a target. | - | ||||||||||||
2198 | - | |||||||||||||
2199 | This does not create the underlying OpenGL texture object. Therefore, | - | ||||||||||||
2200 | construction using this constructor does not require a valid current | - | ||||||||||||
2201 | OpenGL context. | - | ||||||||||||
2202 | */ | - | ||||||||||||
2203 | QOpenGLTexture::QOpenGLTexture(Target target) | - | ||||||||||||
2204 | : d_ptr(new QOpenGLTexturePrivate(target, this)) | - | ||||||||||||
2205 | { | - | ||||||||||||
2206 | } | - | ||||||||||||
2207 | - | |||||||||||||
2208 | /*! | - | ||||||||||||
2209 | Creates a QOpenGLTexture object that can later be bound to the 2D texture | - | ||||||||||||
2210 | target and contains the pixel data contained in \a image. If you wish | - | ||||||||||||
2211 | to have a chain of mipmaps generated then set \a genMipMaps to \c true (this | - | ||||||||||||
2212 | is the default). | - | ||||||||||||
2213 | - | |||||||||||||
2214 | This does create the underlying OpenGL texture object. Therefore, | - | ||||||||||||
2215 | construction using this constructor does require a valid current | - | ||||||||||||
2216 | OpenGL context. | - | ||||||||||||
2217 | */ | - | ||||||||||||
2218 | QOpenGLTexture::QOpenGLTexture(const QImage& image, MipMapGeneration genMipMaps) | - | ||||||||||||
2219 | : d_ptr(new QOpenGLTexturePrivate(QOpenGLTexture::Target2D, this)) | - | ||||||||||||
2220 | { | - | ||||||||||||
2221 | setData(image, genMipMaps); | - | ||||||||||||
2222 | } | - | ||||||||||||
2223 | - | |||||||||||||
2224 | QOpenGLTexture::~QOpenGLTexture() | - | ||||||||||||
2225 | { | - | ||||||||||||
2226 | } | - | ||||||||||||
2227 | - | |||||||||||||
2228 | /*! | - | ||||||||||||
2229 | Returns the binding target of this texture. | - | ||||||||||||
2230 | - | |||||||||||||
2231 | \since 5.4 | - | ||||||||||||
2232 | */ | - | ||||||||||||
2233 | QOpenGLTexture::Target QOpenGLTexture::target() const | - | ||||||||||||
2234 | { | - | ||||||||||||
2235 | Q_D(const QOpenGLTexture); | - | ||||||||||||
2236 | return d->target; | - | ||||||||||||
2237 | } | - | ||||||||||||
2238 | - | |||||||||||||
2239 | /*! | - | ||||||||||||
2240 | Creates the underlying OpenGL texture object. This requires a current valid | - | ||||||||||||
2241 | OpenGL context. If the texture object already exists, this function does | - | ||||||||||||
2242 | nothing. | - | ||||||||||||
2243 | - | |||||||||||||
2244 | Once the texture object is created you can obtain the object | - | ||||||||||||
2245 | name from the textureId() function. This may be useful if you wish to make | - | ||||||||||||
2246 | some raw OpenGL calls related to this texture. | - | ||||||||||||
2247 | - | |||||||||||||
2248 | Normally it should not be necessary to call this function directly as all | - | ||||||||||||
2249 | functions that set properties of the texture object implicitly call create() | - | ||||||||||||
2250 | on your behalf. | - | ||||||||||||
2251 | - | |||||||||||||
2252 | Returns \c true if the creation succeeded, otherwise returns \c false. | - | ||||||||||||
2253 | - | |||||||||||||
2254 | \sa destroy(), isCreated(), textureId() | - | ||||||||||||
2255 | */ | - | ||||||||||||
2256 | bool QOpenGLTexture::create() | - | ||||||||||||
2257 | { | - | ||||||||||||
2258 | Q_D(QOpenGLTexture); | - | ||||||||||||
2259 | return d->create(); | - | ||||||||||||
2260 | } | - | ||||||||||||
2261 | - | |||||||||||||
2262 | /*! | - | ||||||||||||
2263 | Destroys the underlying OpenGL texture object. This requires a current valid | - | ||||||||||||
2264 | OpenGL context. | - | ||||||||||||
2265 | - | |||||||||||||
2266 | \sa create(), isCreated(), textureId() | - | ||||||||||||
2267 | */ | - | ||||||||||||
2268 | void QOpenGLTexture::destroy() | - | ||||||||||||
2269 | { | - | ||||||||||||
2270 | Q_D(QOpenGLTexture); | - | ||||||||||||
2271 | return d->destroy(); | - | ||||||||||||
2272 | } | - | ||||||||||||
2273 | - | |||||||||||||
2274 | /*! | - | ||||||||||||
2275 | Returns \c true if the underlying OpenGL texture object has been created. | - | ||||||||||||
2276 | - | |||||||||||||
2277 | \sa create(), destroy(), textureId() | - | ||||||||||||
2278 | */ | - | ||||||||||||
2279 | bool QOpenGLTexture::isCreated() const | - | ||||||||||||
2280 | { | - | ||||||||||||
2281 | Q_D(const QOpenGLTexture); | - | ||||||||||||
2282 | return d->textureId != 0; | - | ||||||||||||
2283 | } | - | ||||||||||||
2284 | - | |||||||||||||
2285 | /*! | - | ||||||||||||
2286 | Returns the name of the underlying OpenGL texture object or 0 if it has | - | ||||||||||||
2287 | not yet been created. | - | ||||||||||||
2288 | - | |||||||||||||
2289 | \sa create(), destroy(), isCreated() | - | ||||||||||||
2290 | */ | - | ||||||||||||
2291 | GLuint QOpenGLTexture::textureId() const | - | ||||||||||||
2292 | { | - | ||||||||||||
2293 | Q_D(const QOpenGLTexture); | - | ||||||||||||
2294 | return d->textureId; | - | ||||||||||||
2295 | } | - | ||||||||||||
2296 | - | |||||||||||||
2297 | /*! | - | ||||||||||||
2298 | Binds this texture to the currently active texture unit ready for | - | ||||||||||||
2299 | rendering. Note that you do not need to bind QOpenGLTexture objects | - | ||||||||||||
2300 | in order to modify them as the implementation makes use of the | - | ||||||||||||
2301 | EXT_direct_state_access extension where available and simulates it | - | ||||||||||||
2302 | where it is not. | - | ||||||||||||
2303 | - | |||||||||||||
2304 | \sa release() | - | ||||||||||||
2305 | */ | - | ||||||||||||
2306 | void QOpenGLTexture::bind() | - | ||||||||||||
2307 | { | - | ||||||||||||
2308 | Q_D(QOpenGLTexture); | - | ||||||||||||
2309 | Q_ASSERT(d->textureId); | - | ||||||||||||
2310 | d->bind(); | - | ||||||||||||
2311 | } | - | ||||||||||||
2312 | - | |||||||||||||
2313 | /*! | - | ||||||||||||
2314 | Binds this texture to texture unit \a unit ready for | - | ||||||||||||
2315 | rendering. Note that you do not need to bind QOpenGLTexture objects | - | ||||||||||||
2316 | in order to modify them as the implementation makes use of the | - | ||||||||||||
2317 | EXT_direct_state_access extension where available and simulates it | - | ||||||||||||
2318 | where it is not. | - | ||||||||||||
2319 | - | |||||||||||||
2320 | If parameter \a reset is \c true then this function will restore | - | ||||||||||||
2321 | the active unit to the texture unit that was active upon entry. | - | ||||||||||||
2322 | - | |||||||||||||
2323 | \sa release() | - | ||||||||||||
2324 | */ | - | ||||||||||||
2325 | void QOpenGLTexture::bind(uint unit, TextureUnitReset reset) | - | ||||||||||||
2326 | { | - | ||||||||||||
2327 | Q_D(QOpenGLTexture); | - | ||||||||||||
2328 | Q_ASSERT(d->textureId); | - | ||||||||||||
2329 | d->bind(unit, reset); | - | ||||||||||||
2330 | } | - | ||||||||||||
2331 | - | |||||||||||||
2332 | /*! | - | ||||||||||||
2333 | Unbinds this texture from the currently active texture unit. | - | ||||||||||||
2334 | - | |||||||||||||
2335 | \sa bind() | - | ||||||||||||
2336 | */ | - | ||||||||||||
2337 | void QOpenGLTexture::release() | - | ||||||||||||
2338 | { | - | ||||||||||||
2339 | Q_D(QOpenGLTexture); | - | ||||||||||||
2340 | d->release(); | - | ||||||||||||
2341 | } | - | ||||||||||||
2342 | - | |||||||||||||
2343 | /*! | - | ||||||||||||
2344 | Unbinds this texture from texture unit \a unit. | - | ||||||||||||
2345 | - | |||||||||||||
2346 | If parameter \a reset is \c true then this function | - | ||||||||||||
2347 | will restore the active unit to the texture unit that was active | - | ||||||||||||
2348 | upon entry. | - | ||||||||||||
2349 | */ | - | ||||||||||||
2350 | void QOpenGLTexture::release(uint unit, TextureUnitReset reset) | - | ||||||||||||
2351 | { | - | ||||||||||||
2352 | Q_D(QOpenGLTexture); | - | ||||||||||||
2353 | d->release(unit, reset); | - | ||||||||||||
2354 | } | - | ||||||||||||
2355 | - | |||||||||||||
2356 | /*! | - | ||||||||||||
2357 | Returns \c true if this texture is bound to the corresponding target | - | ||||||||||||
2358 | of the currently active texture unit. | - | ||||||||||||
2359 | - | |||||||||||||
2360 | \sa bind(), release() | - | ||||||||||||
2361 | */ | - | ||||||||||||
2362 | bool QOpenGLTexture::isBound() const | - | ||||||||||||
2363 | { | - | ||||||||||||
2364 | Q_D(const QOpenGLTexture); | - | ||||||||||||
2365 | Q_ASSERT(d->textureId); | - | ||||||||||||
2366 | return d->isBound(); | - | ||||||||||||
2367 | } | - | ||||||||||||
2368 | - | |||||||||||||
2369 | /*! | - | ||||||||||||
2370 | Returns \c true if this texture is bound to the corresponding target | - | ||||||||||||
2371 | of texture unit \a unit. | - | ||||||||||||
2372 | - | |||||||||||||
2373 | \sa bind(), release() | - | ||||||||||||
2374 | */ | - | ||||||||||||
2375 | bool QOpenGLTexture::isBound(uint unit) | - | ||||||||||||
2376 | { | - | ||||||||||||
2377 | Q_D(const QOpenGLTexture); | - | ||||||||||||
2378 | Q_ASSERT(d->textureId); | - | ||||||||||||
2379 | return d->isBound(unit); | - | ||||||||||||
2380 | } | - | ||||||||||||
2381 | - | |||||||||||||
2382 | /*! | - | ||||||||||||
2383 | Returns the textureId of the texture that is bound to the \a target | - | ||||||||||||
2384 | of the currently active texture unit. | - | ||||||||||||
2385 | */ | - | ||||||||||||
2386 | GLuint QOpenGLTexture::boundTextureId(BindingTarget target) | - | ||||||||||||
2387 | { | - | ||||||||||||
2388 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - | ||||||||||||
2389 | if (!ctx) { | - | ||||||||||||
2390 | qWarning("QOpenGLTexture::boundTextureId() requires a valid current context"); | - | ||||||||||||
2391 | return 0; | - | ||||||||||||
2392 | } | - | ||||||||||||
2393 | - | |||||||||||||
2394 | GLint textureId = 0; | - | ||||||||||||
2395 | ctx->functions()->glGetIntegerv(target, &textureId); | - | ||||||||||||
2396 | return static_cast<GLuint>(textureId); | - | ||||||||||||
2397 | } | - | ||||||||||||
2398 | - | |||||||||||||
2399 | /*! | - | ||||||||||||
2400 | Returns the textureId of the texture that is bound to the \a target | - | ||||||||||||
2401 | of the texture unit \a unit. | - | ||||||||||||
2402 | */ | - | ||||||||||||
2403 | GLuint QOpenGLTexture::boundTextureId(uint unit, BindingTarget target) | - | ||||||||||||
2404 | { | - | ||||||||||||
2405 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - | ||||||||||||
2406 | if (!ctx) { | - | ||||||||||||
2407 | qWarning("QOpenGLTexture::boundTextureId() requires a valid current context"); | - | ||||||||||||
2408 | return 0; | - | ||||||||||||
2409 | } | - | ||||||||||||
2410 | - | |||||||||||||
2411 | QOpenGLFunctions *funcs = ctx->functions(); | - | ||||||||||||
2412 | funcs->initializeOpenGLFunctions(); | - | ||||||||||||
2413 | - | |||||||||||||
2414 | GLint oldTextureUnit = 0; | - | ||||||||||||
2415 | funcs->glGetIntegerv(GL_ACTIVE_TEXTURE, &oldTextureUnit); | - | ||||||||||||
2416 | - | |||||||||||||
2417 | funcs->glActiveTexture(unit); | - | ||||||||||||
2418 | GLint textureId = 0; | - | ||||||||||||
2419 | funcs->glGetIntegerv(target, &textureId); | - | ||||||||||||
2420 | funcs->glActiveTexture(oldTextureUnit); | - | ||||||||||||
2421 | - | |||||||||||||
2422 | return static_cast<GLuint>(textureId); | - | ||||||||||||
2423 | } | - | ||||||||||||
2424 | - | |||||||||||||
2425 | /*! | - | ||||||||||||
2426 | Sets the format of this texture object to \a format. This function | - | ||||||||||||
2427 | must be called before texture storage is allocated. | - | ||||||||||||
2428 | - | |||||||||||||
2429 | Note that all formats may not be supported. The exact set of supported | - | ||||||||||||
2430 | formats is dependent upon your OpenGL implementation and version. | - | ||||||||||||
2431 | - | |||||||||||||
2432 | \sa format(), allocateStorage() | - | ||||||||||||
2433 | */ | - | ||||||||||||
2434 | void QOpenGLTexture::setFormat(TextureFormat format) | - | ||||||||||||
2435 | { | - | ||||||||||||
2436 | Q_D(QOpenGLTexture); | - | ||||||||||||
2437 | d->create(); | - | ||||||||||||
2438 | if (isStorageAllocated()) { | - | ||||||||||||
2439 | qWarning("QOpenGLTexture::setFormat(): Cannot change format once storage has been allocated"); | - | ||||||||||||
2440 | return; | - | ||||||||||||
2441 | } | - | ||||||||||||
2442 | - | |||||||||||||
2443 | d->format = format; | - | ||||||||||||
2444 | - | |||||||||||||
2445 | switch (format) { | - | ||||||||||||
2446 | case NoFormat: | - | ||||||||||||
2447 | d->formatClass = NoFormatClass; | - | ||||||||||||
2448 | break; | - | ||||||||||||
2449 | - | |||||||||||||
2450 | case RGBA32F: | - | ||||||||||||
2451 | case RGBA32U: | - | ||||||||||||
2452 | case RGBA32I: | - | ||||||||||||
2453 | d->formatClass = FormatClass_128Bit; | - | ||||||||||||
2454 | break; | - | ||||||||||||
2455 | - | |||||||||||||
2456 | case RGB32F: | - | ||||||||||||
2457 | case RGB32U: | - | ||||||||||||
2458 | case RGB32I: | - | ||||||||||||
2459 | d->formatClass = FormatClass_96Bit; | - | ||||||||||||
2460 | break; | - | ||||||||||||
2461 | - | |||||||||||||
2462 | case RGBA16F: | - | ||||||||||||
2463 | case RG32F: | - | ||||||||||||
2464 | case RGBA16U: | - | ||||||||||||
2465 | case RG32U: | - | ||||||||||||
2466 | case RGBA16I: | - | ||||||||||||
2467 | case RG32I: | - | ||||||||||||
2468 | case RGBA16_UNorm: | - | ||||||||||||
2469 | case RGBA16_SNorm: | - | ||||||||||||
2470 | d->formatClass = FormatClass_64Bit; | - | ||||||||||||
2471 | break; | - | ||||||||||||
2472 | - | |||||||||||||
2473 | case RGB16_UNorm: | - | ||||||||||||
2474 | case RGB16_SNorm: | - | ||||||||||||
2475 | case RGB16F: | - | ||||||||||||
2476 | case RGB16U: | - | ||||||||||||
2477 | case RGB16I: | - | ||||||||||||
2478 | d->formatClass = FormatClass_48Bit; | - | ||||||||||||
2479 | break; | - | ||||||||||||
2480 | - | |||||||||||||
2481 | case RG16F: | - | ||||||||||||
2482 | case RG11B10F: | - | ||||||||||||
2483 | case R32F: | - | ||||||||||||
2484 | case RGB10A2: | - | ||||||||||||
2485 | case RGBA8U: | - | ||||||||||||
2486 | case RG16U: | - | ||||||||||||
2487 | case R32U: | - | ||||||||||||
2488 | case RGBA8I: | - | ||||||||||||
2489 | case RG16I: | - | ||||||||||||
2490 | case R32I: | - | ||||||||||||
2491 | case RGBA8_UNorm: | - | ||||||||||||
2492 | case RG16_UNorm: | - | ||||||||||||
2493 | case RGBA8_SNorm: | - | ||||||||||||
2494 | case RG16_SNorm: | - | ||||||||||||
2495 | case SRGB8_Alpha8: | - | ||||||||||||
2496 | case RGB9E5: | - | ||||||||||||
2497 | d->formatClass = FormatClass_32Bit; | - | ||||||||||||
2498 | break; | - | ||||||||||||
2499 | - | |||||||||||||
2500 | case RGB8_UNorm: | - | ||||||||||||
2501 | case RGB8_SNorm: | - | ||||||||||||
2502 | case SRGB8: | - | ||||||||||||
2503 | case RGB8U: | - | ||||||||||||
2504 | case RGB8I: | - | ||||||||||||
2505 | d->formatClass = FormatClass_24Bit; | - | ||||||||||||
2506 | break; | - | ||||||||||||
2507 | - | |||||||||||||
2508 | case R16F: | - | ||||||||||||
2509 | case RG8U: | - | ||||||||||||
2510 | case R16U: | - | ||||||||||||
2511 | case RG8I: | - | ||||||||||||
2512 | case R16I: | - | ||||||||||||
2513 | case RG8_UNorm: | - | ||||||||||||
2514 | case R16_UNorm: | - | ||||||||||||
2515 | case RG8_SNorm: | - | ||||||||||||
2516 | case R16_SNorm: | - | ||||||||||||
2517 | d->formatClass = FormatClass_16Bit; | - | ||||||||||||
2518 | break; | - | ||||||||||||
2519 | - | |||||||||||||
2520 | case R8U: | - | ||||||||||||
2521 | case R8I: | - | ||||||||||||
2522 | case R8_UNorm: | - | ||||||||||||
2523 | case R8_SNorm: | - | ||||||||||||
2524 | d->formatClass = FormatClass_8Bit; | - | ||||||||||||
2525 | break; | - | ||||||||||||
2526 | - | |||||||||||||
2527 | case R_ATI1N_UNorm: | - | ||||||||||||
2528 | case R_ATI1N_SNorm: | - | ||||||||||||
2529 | d->formatClass = FormatClass_RGTC1_R; | - | ||||||||||||
2530 | break; | - | ||||||||||||
2531 | - | |||||||||||||
2532 | case RG_ATI2N_UNorm: | - | ||||||||||||
2533 | case RG_ATI2N_SNorm: | - | ||||||||||||
2534 | d->formatClass = FormatClass_RGTC2_RG; | - | ||||||||||||
2535 | break; | - | ||||||||||||
2536 | - | |||||||||||||
2537 | case RGB_BP_UNorm: | - | ||||||||||||
2538 | case SRGB_BP_UNorm: | - | ||||||||||||
2539 | d->formatClass = FormatClass_BPTC_Unorm; | - | ||||||||||||
2540 | break; | - | ||||||||||||
2541 | - | |||||||||||||
2542 | case RGB_BP_UNSIGNED_FLOAT: | - | ||||||||||||
2543 | case RGB_BP_SIGNED_FLOAT: | - | ||||||||||||
2544 | d->formatClass = FormatClass_BPTC_Float; | - | ||||||||||||
2545 | break; | - | ||||||||||||
2546 | - | |||||||||||||
2547 | case RGB_DXT1: | - | ||||||||||||
2548 | case SRGB_DXT1: | - | ||||||||||||
2549 | d->formatClass = FormatClass_S3TC_DXT1_RGB; | - | ||||||||||||
2550 | break; | - | ||||||||||||
2551 | - | |||||||||||||
2552 | case RGBA_DXT1: | - | ||||||||||||
2553 | case SRGB_Alpha_DXT1: | - | ||||||||||||
2554 | d->formatClass = FormatClass_S3TC_DXT1_RGBA; | - | ||||||||||||
2555 | break; | - | ||||||||||||
2556 | - | |||||||||||||
2557 | case RGBA_DXT3: | - | ||||||||||||
2558 | case SRGB_Alpha_DXT3: | - | ||||||||||||
2559 | d->formatClass = FormatClass_S3TC_DXT3_RGBA; | - | ||||||||||||
2560 | break; | - | ||||||||||||
2561 | - | |||||||||||||
2562 | case RGBA_DXT5: | - | ||||||||||||
2563 | case SRGB_Alpha_DXT5: | - | ||||||||||||
2564 | d->formatClass = FormatClass_S3TC_DXT5_RGBA; | - | ||||||||||||
2565 | break; | - | ||||||||||||
2566 | - | |||||||||||||
2567 | case QOpenGLTexture::R11_EAC_UNorm: | - | ||||||||||||
2568 | case QOpenGLTexture::R11_EAC_SNorm: | - | ||||||||||||
2569 | case QOpenGLTexture::RG11_EAC_UNorm: | - | ||||||||||||
2570 | case QOpenGLTexture::RG11_EAC_SNorm: | - | ||||||||||||
2571 | case QOpenGLTexture::RGB8_ETC2: | - | ||||||||||||
2572 | case QOpenGLTexture::SRGB8_ETC2: | - | ||||||||||||
2573 | case QOpenGLTexture::RGB8_PunchThrough_Alpha1_ETC2: | - | ||||||||||||
2574 | case QOpenGLTexture::SRGB8_PunchThrough_Alpha1_ETC2: | - | ||||||||||||
2575 | case QOpenGLTexture::RGBA8_ETC2_EAC: | - | ||||||||||||
2576 | case QOpenGLTexture::SRGB8_Alpha8_ETC2_EAC: | - | ||||||||||||
2577 | case QOpenGLTexture::RGB8_ETC1: | - | ||||||||||||
2578 | case RG3B2: | - | ||||||||||||
2579 | case R5G6B5: | - | ||||||||||||
2580 | case RGB5A1: | - | ||||||||||||
2581 | case RGBA4: | - | ||||||||||||
2582 | case D16: | - | ||||||||||||
2583 | case D24: | - | ||||||||||||
2584 | case D24S8: | - | ||||||||||||
2585 | case D32: | - | ||||||||||||
2586 | case D32F: | - | ||||||||||||
2587 | case D32FS8X24: | - | ||||||||||||
2588 | case S8: | - | ||||||||||||
2589 | case DepthFormat: | - | ||||||||||||
2590 | case AlphaFormat: | - | ||||||||||||
2591 | case RGBFormat: | - | ||||||||||||
2592 | case RGBAFormat: | - | ||||||||||||
2593 | case LuminanceFormat: | - | ||||||||||||
2594 | case LuminanceAlphaFormat: | - | ||||||||||||
2595 | d->formatClass = FormatClass_Unique; | - | ||||||||||||
2596 | break; | - | ||||||||||||
2597 | } | - | ||||||||||||
2598 | } | - | ||||||||||||
2599 | - | |||||||||||||
2600 | /*! | - | ||||||||||||
2601 | Returns the format of this texture object. | - | ||||||||||||
2602 | - | |||||||||||||
2603 | \sa setFormat() | - | ||||||||||||
2604 | */ | - | ||||||||||||
2605 | QOpenGLTexture::TextureFormat QOpenGLTexture::format() const | - | ||||||||||||
2606 | { | - | ||||||||||||
2607 | Q_D(const QOpenGLTexture); | - | ||||||||||||
2608 | return d->format; | - | ||||||||||||
2609 | } | - | ||||||||||||
2610 | - | |||||||||||||
2611 | /*! | - | ||||||||||||
2612 | Sets the dimensions of this texture object to \a width, | - | ||||||||||||
2613 | \a height, and \a depth. The default for each dimension is 1. | - | ||||||||||||
2614 | The maximum allowable texture size is dependent upon your OpenGL | - | ||||||||||||
2615 | implementation. Allocating storage for a texture less than the | - | ||||||||||||
2616 | maximum size can still fail if your system is low on resources. | - | ||||||||||||
2617 | - | |||||||||||||
2618 | \sa width(), height(), depth() | - | ||||||||||||
2619 | */ | - | ||||||||||||
2620 | void QOpenGLTexture::setSize(int width, int height, int depth) | - | ||||||||||||
2621 | { | - | ||||||||||||
2622 | Q_D(QOpenGLTexture); | - | ||||||||||||
2623 | d->create(); | - | ||||||||||||
2624 | if (isStorageAllocated()) { | - | ||||||||||||
2625 | qWarning("Cannot resize a texture that already has storage allocated.\n" | - | ||||||||||||
2626 | "To do so, destroy() the texture and then create() and setSize()"); | - | ||||||||||||
2627 | return; | - | ||||||||||||
2628 | } | - | ||||||||||||
2629 | - | |||||||||||||
2630 | switch (d->target) { | - | ||||||||||||
2631 | case QOpenGLTexture::Target1D: | - | ||||||||||||
2632 | case QOpenGLTexture::Target1DArray: | - | ||||||||||||
2633 | case QOpenGLTexture::TargetBuffer: | - | ||||||||||||
2634 | d->dimensions[0] = width; | - | ||||||||||||
2635 | Q_UNUSED(height); | - | ||||||||||||
2636 | Q_UNUSED(depth); | - | ||||||||||||
2637 | break; | - | ||||||||||||
2638 | - | |||||||||||||
2639 | case QOpenGLTexture::Target2D: | - | ||||||||||||
2640 | case QOpenGLTexture::Target2DArray: | - | ||||||||||||
2641 | case QOpenGLTexture::TargetRectangle: | - | ||||||||||||
2642 | case QOpenGLTexture::Target2DMultisample: | - | ||||||||||||
2643 | case QOpenGLTexture::Target2DMultisampleArray: | - | ||||||||||||
2644 | d->dimensions[0] = width; | - | ||||||||||||
2645 | d->dimensions[1] = height; | - | ||||||||||||
2646 | Q_UNUSED(depth); | - | ||||||||||||
2647 | break; | - | ||||||||||||
2648 | - | |||||||||||||
2649 | case QOpenGLTexture::TargetCubeMap: | - | ||||||||||||
2650 | case QOpenGLTexture::TargetCubeMapArray: | - | ||||||||||||
2651 | if (width != height) | - | ||||||||||||
2652 | qWarning("QAbstractOpenGLTexture::setSize(): Cube map textures must be square"); | - | ||||||||||||
2653 | d->dimensions[0] = d->dimensions[1] = width; | - | ||||||||||||
2654 | Q_UNUSED(depth); | - | ||||||||||||
2655 | break; | - | ||||||||||||
2656 | - | |||||||||||||
2657 | case QOpenGLTexture::Target3D: | - | ||||||||||||
2658 | d->dimensions[0] = width; | - | ||||||||||||
2659 | d->dimensions[1] = height; | - | ||||||||||||
2660 | d->dimensions[2] = depth; | - | ||||||||||||
2661 | break; | - | ||||||||||||
2662 | } | - | ||||||||||||
2663 | } | - | ||||||||||||
2664 | - | |||||||||||||
2665 | /*! | - | ||||||||||||
2666 | Returns the width of a 1D, 2D or 3D texture. | - | ||||||||||||
2667 | - | |||||||||||||
2668 | \sa height(), depth(), setSize() | - | ||||||||||||
2669 | */ | - | ||||||||||||
2670 | int QOpenGLTexture::width() const | - | ||||||||||||
2671 | { | - | ||||||||||||
2672 | Q_D(const QOpenGLTexture); | - | ||||||||||||
2673 | return d->dimensions[0]; | - | ||||||||||||
2674 | } | - | ||||||||||||
2675 | - | |||||||||||||
2676 | /*! | - | ||||||||||||
2677 | Returns the height of a 2D or 3D texture. | - | ||||||||||||
2678 | - | |||||||||||||
2679 | \sa width(), depth(), setSize() | - | ||||||||||||
2680 | */ | - | ||||||||||||
2681 | int QOpenGLTexture::height() const | - | ||||||||||||
2682 | { | - | ||||||||||||
2683 | Q_D(const QOpenGLTexture); | - | ||||||||||||
2684 | return d->dimensions[1]; | - | ||||||||||||
2685 | } | - | ||||||||||||
2686 | - | |||||||||||||
2687 | /*! | - | ||||||||||||
2688 | Returns the depth of a 3D texture. | - | ||||||||||||
2689 | - | |||||||||||||
2690 | \sa width(), height(), setSize() | - | ||||||||||||
2691 | */ | - | ||||||||||||
2692 | int QOpenGLTexture::depth() const | - | ||||||||||||
2693 | { | - | ||||||||||||
2694 | Q_D(const QOpenGLTexture); | - | ||||||||||||
2695 | return d->dimensions[2]; | - | ||||||||||||
2696 | } | - | ||||||||||||
2697 | - | |||||||||||||
2698 | /*! | - | ||||||||||||
2699 | For texture targets that support mipmaps, this function | - | ||||||||||||
2700 | sets the requested number of mipmap \a levels to allocate storage | - | ||||||||||||
2701 | for. This function should be called before storage is allocated | - | ||||||||||||
2702 | for the texture. | - | ||||||||||||
2703 | - | |||||||||||||
2704 | If the texture target does not support mipmaps this function | - | ||||||||||||
2705 | has no effect. | - | ||||||||||||
2706 | - | |||||||||||||
2707 | \sa mipLevels(), maximumMipLevels(), isStorageAllocated() | - | ||||||||||||
2708 | */ | - | ||||||||||||
2709 | void QOpenGLTexture::setMipLevels(int levels) | - | ||||||||||||
2710 | { | - | ||||||||||||
2711 | Q_D(QOpenGLTexture); | - | ||||||||||||
2712 | d->create(); | - | ||||||||||||
2713 | if (isStorageAllocated()) { | - | ||||||||||||
2714 | qWarning("Cannot set mip levels on a texture that already has storage allocated.\n" | - | ||||||||||||
2715 | "To do so, destroy() the texture and then create() and setMipLevels()"); | - | ||||||||||||
2716 | return; | - | ||||||||||||
2717 | } | - | ||||||||||||
2718 | - | |||||||||||||
2719 | switch (d->target) { | - | ||||||||||||
2720 | case QOpenGLTexture::Target1D: | - | ||||||||||||
2721 | case QOpenGLTexture::Target1DArray: | - | ||||||||||||
2722 | case QOpenGLTexture::Target2D: | - | ||||||||||||
2723 | case QOpenGLTexture::Target2DArray: | - | ||||||||||||
2724 | case QOpenGLTexture::TargetCubeMap: | - | ||||||||||||
2725 | case QOpenGLTexture::TargetCubeMapArray: | - | ||||||||||||
2726 | case QOpenGLTexture::Target3D: | - | ||||||||||||
2727 | d->requestedMipLevels = levels; | - | ||||||||||||
2728 | break; | - | ||||||||||||
2729 | - | |||||||||||||
2730 | case QOpenGLTexture::TargetBuffer: | - | ||||||||||||
2731 | case QOpenGLTexture::TargetRectangle: | - | ||||||||||||
2732 | case QOpenGLTexture::Target2DMultisample: | - | ||||||||||||
2733 | case QOpenGLTexture::Target2DMultisampleArray: | - | ||||||||||||
2734 | qWarning("QAbstractOpenGLTexture::setMipLevels(): This texture target does not support mipmaps"); | - | ||||||||||||
2735 | break; | - | ||||||||||||
2736 | } | - | ||||||||||||
2737 | } | - | ||||||||||||
2738 | - | |||||||||||||
2739 | /*! | - | ||||||||||||
2740 | Returns the number of mipmap levels for this texture. If storage | - | ||||||||||||
2741 | has not yet been allocated for this texture it returns the | - | ||||||||||||
2742 | requested number of mipmap levels. | - | ||||||||||||
2743 | - | |||||||||||||
2744 | \sa setMipLevels(), maximumMipLevels(), isStorageAllocated() | - | ||||||||||||
2745 | */ | - | ||||||||||||
2746 | int QOpenGLTexture::mipLevels() const | - | ||||||||||||
2747 | { | - | ||||||||||||
2748 | Q_D(const QOpenGLTexture); | - | ||||||||||||
2749 | return isStorageAllocated() ? d->mipLevels : d->requestedMipLevels; | - | ||||||||||||
2750 | } | - | ||||||||||||
2751 | - | |||||||||||||
2752 | /*! | - | ||||||||||||
2753 | Returns the maximum number of mipmap levels that this texture | - | ||||||||||||
2754 | can have given the current dimensions. | - | ||||||||||||
2755 | - | |||||||||||||
2756 | \sa setMipLevels(), mipLevels(), setSize() | - | ||||||||||||
2757 | */ | - | ||||||||||||
2758 | int QOpenGLTexture::maximumMipLevels() const | - | ||||||||||||
2759 | { | - | ||||||||||||
2760 | Q_D(const QOpenGLTexture); | - | ||||||||||||
2761 | return d->maximumMipLevelCount(); | - | ||||||||||||
2762 | } | - | ||||||||||||
2763 | - | |||||||||||||
2764 | /*! | - | ||||||||||||
2765 | Sets the number of array \a layers to allocate storage for. This | - | ||||||||||||
2766 | function should be called before storage is allocated for the texture. | - | ||||||||||||
2767 | - | |||||||||||||
2768 | For targets that do not support array layers this function has | - | ||||||||||||
2769 | no effect. | - | ||||||||||||
2770 | - | |||||||||||||
2771 | \sa layers(), isStorageAllocated() | - | ||||||||||||
2772 | */ | - | ||||||||||||
2773 | void QOpenGLTexture::setLayers(int layers) | - | ||||||||||||
2774 | { | - | ||||||||||||
2775 | Q_D(QOpenGLTexture); | - | ||||||||||||
2776 | d->create(); | - | ||||||||||||
2777 | if (isStorageAllocated()) { | - | ||||||||||||
2778 | qWarning("Cannot set layers on a texture that already has storage allocated.\n" | - | ||||||||||||
2779 | "To do so, destroy() the texture and then create() and setLayers()"); | - | ||||||||||||
2780 | return; | - | ||||||||||||
2781 | } | - | ||||||||||||
2782 | - | |||||||||||||
2783 | switch (d->target) { | - | ||||||||||||
2784 | case QOpenGLTexture::Target1DArray: | - | ||||||||||||
2785 | case QOpenGLTexture::Target2DArray: | - | ||||||||||||
2786 | case QOpenGLTexture::TargetCubeMapArray: | - | ||||||||||||
2787 | case QOpenGLTexture::Target2DMultisampleArray: | - | ||||||||||||
2788 | d->layers = layers; | - | ||||||||||||
2789 | break; | - | ||||||||||||
2790 | - | |||||||||||||
2791 | case QOpenGLTexture::Target1D: | - | ||||||||||||
2792 | case QOpenGLTexture::Target2D: | - | ||||||||||||
2793 | case QOpenGLTexture::Target3D: | - | ||||||||||||
2794 | case QOpenGLTexture::TargetCubeMap: | - | ||||||||||||
2795 | case QOpenGLTexture::TargetBuffer: | - | ||||||||||||
2796 | case QOpenGLTexture::TargetRectangle: | - | ||||||||||||
2797 | case QOpenGLTexture::Target2DMultisample: | - | ||||||||||||
2798 | qWarning("Texture target does not support array layers"); | - | ||||||||||||
2799 | break; | - | ||||||||||||
2800 | } | - | ||||||||||||
2801 | } | - | ||||||||||||
2802 | - | |||||||||||||
2803 | /*! | - | ||||||||||||
2804 | Returns the number of array layers for this texture. If | - | ||||||||||||
2805 | storage has not yet been allocated for this texture then | - | ||||||||||||
2806 | this function returns the requested number of array layers. | - | ||||||||||||
2807 | - | |||||||||||||
2808 | For texture targets that do not support array layers this | - | ||||||||||||
2809 | will return 1. | - | ||||||||||||
2810 | - | |||||||||||||
2811 | \sa setLayers(), isStorageAllocated() | - | ||||||||||||
2812 | */ | - | ||||||||||||
2813 | int QOpenGLTexture::layers() const | - | ||||||||||||
2814 | { | - | ||||||||||||
2815 | Q_D(const QOpenGLTexture); | - | ||||||||||||
2816 | return d->layers; | - | ||||||||||||
2817 | } | - | ||||||||||||
2818 | - | |||||||||||||
2819 | /*! | - | ||||||||||||
2820 | Returns the number of faces for this texture. For cubemap | - | ||||||||||||
2821 | and cubemap array type targets this will be 6. | - | ||||||||||||
2822 | - | |||||||||||||
2823 | For non-cubemap type targets this will return 1. | - | ||||||||||||
2824 | */ | - | ||||||||||||
2825 | int QOpenGLTexture::faces() const | - | ||||||||||||
2826 | { | - | ||||||||||||
2827 | Q_D(const QOpenGLTexture); | - | ||||||||||||
2828 | return d->faces; | - | ||||||||||||
2829 | } | - | ||||||||||||
2830 | - | |||||||||||||
2831 | /*! | - | ||||||||||||
2832 | Sets the number of \a samples to allocate storage for when rendering to | - | ||||||||||||
2833 | a multisample capable texture target. This function should | - | ||||||||||||
2834 | be called before storage is allocated for the texture. | - | ||||||||||||
2835 | - | |||||||||||||
2836 | For targets that do not support multisampling this function has | - | ||||||||||||
2837 | no effect. | - | ||||||||||||
2838 | - | |||||||||||||
2839 | \sa samples(), isStorageAllocated() | - | ||||||||||||
2840 | */ | - | ||||||||||||
2841 | void QOpenGLTexture::setSamples(int samples) | - | ||||||||||||
2842 | { | - | ||||||||||||
2843 | Q_D(QOpenGLTexture); | - | ||||||||||||
2844 | d->create(); | - | ||||||||||||
2845 | if (isStorageAllocated()) { | - | ||||||||||||
2846 | qWarning("Cannot set sample count on a texture that already has storage allocated.\n" | - | ||||||||||||
2847 | "To do so, destroy() the texture and then create() and setSamples()"); | - | ||||||||||||
2848 | return; | - | ||||||||||||
2849 | } | - | ||||||||||||
2850 | - | |||||||||||||
2851 | switch (d->target) { | - | ||||||||||||
2852 | case QOpenGLTexture::Target2DMultisample: | - | ||||||||||||
2853 | case QOpenGLTexture::Target2DMultisampleArray: | - | ||||||||||||
2854 | d->samples = samples; | - | ||||||||||||
2855 | break; | - | ||||||||||||
2856 | - | |||||||||||||
2857 | case QOpenGLTexture::Target1D: | - | ||||||||||||
2858 | case QOpenGLTexture::Target2D: | - | ||||||||||||
2859 | case QOpenGLTexture::Target3D: | - | ||||||||||||
2860 | case QOpenGLTexture::Target1DArray: | - | ||||||||||||
2861 | case QOpenGLTexture::Target2DArray: | - | ||||||||||||
2862 | case QOpenGLTexture::TargetCubeMap: | - | ||||||||||||
2863 | case QOpenGLTexture::TargetCubeMapArray: | - | ||||||||||||
2864 | case QOpenGLTexture::TargetBuffer: | - | ||||||||||||
2865 | case QOpenGLTexture::TargetRectangle: | - | ||||||||||||
2866 | - | |||||||||||||
2867 | qWarning("Texture target does not support multisampling"); | - | ||||||||||||
2868 | break; | - | ||||||||||||
2869 | } | - | ||||||||||||
2870 | } | - | ||||||||||||
2871 | - | |||||||||||||
2872 | /*! | - | ||||||||||||
2873 | Returns the number of multisample sample points for this texture. | - | ||||||||||||
2874 | If storage has not yet been allocated for this texture then | - | ||||||||||||
2875 | this function returns the requested number of samples. | - | ||||||||||||
2876 | - | |||||||||||||
2877 | For texture targets that do not support multisampling this | - | ||||||||||||
2878 | will return 0. | - | ||||||||||||
2879 | - | |||||||||||||
2880 | \sa setSamples(), isStorageAllocated() | - | ||||||||||||
2881 | */ | - | ||||||||||||
2882 | int QOpenGLTexture::samples() const | - | ||||||||||||
2883 | { | - | ||||||||||||
2884 | Q_D(const QOpenGLTexture); | - | ||||||||||||
2885 | return d->samples; | - | ||||||||||||
2886 | } | - | ||||||||||||
2887 | - | |||||||||||||
2888 | /*! | - | ||||||||||||
2889 | Sets whether the sample positions and number of samples used with | - | ||||||||||||
2890 | a multisample capable texture target to \a fixed. If set to \c true | - | ||||||||||||
2891 | the sample positions and number of samples used are the same for | - | ||||||||||||
2892 | all texels in the image and will not depend upon the image size or | - | ||||||||||||
2893 | internal format. This function should be called before storage is allocated | - | ||||||||||||
2894 | for the texture. | - | ||||||||||||
2895 | - | |||||||||||||
2896 | For targets that do not support multisampling this function has | - | ||||||||||||
2897 | no effect. | - | ||||||||||||
2898 | - | |||||||||||||
2899 | The default value is \c true. | - | ||||||||||||
2900 | - | |||||||||||||
2901 | \sa isFixedSamplePositions(), isStorageAllocated() | - | ||||||||||||
2902 | */ | - | ||||||||||||
2903 | void QOpenGLTexture::setFixedSamplePositions(bool fixed) | - | ||||||||||||
2904 | { | - | ||||||||||||
2905 | Q_D(QOpenGLTexture); | - | ||||||||||||
2906 | d->create(); | - | ||||||||||||
2907 | if (isStorageAllocated()) { | - | ||||||||||||
2908 | qWarning("Cannot set sample positions on a texture that already has storage allocated.\n" | - | ||||||||||||
2909 | "To do so, destroy() the texture and then create() and setFixedSamplePositions()"); | - | ||||||||||||
2910 | return; | - | ||||||||||||
2911 | } | - | ||||||||||||
2912 | - | |||||||||||||
2913 | switch (d->target) { | - | ||||||||||||
2914 | case QOpenGLTexture::Target2DMultisample: | - | ||||||||||||
2915 | case QOpenGLTexture::Target2DMultisampleArray: | - | ||||||||||||
2916 | d->fixedSamplePositions = fixed; | - | ||||||||||||
2917 | break; | - | ||||||||||||
2918 | - | |||||||||||||
2919 | case QOpenGLTexture::Target1D: | - | ||||||||||||
2920 | case QOpenGLTexture::Target2D: | - | ||||||||||||
2921 | case QOpenGLTexture::Target3D: | - | ||||||||||||
2922 | case QOpenGLTexture::Target1DArray: | - | ||||||||||||
2923 | case QOpenGLTexture::Target2DArray: | - | ||||||||||||
2924 | case QOpenGLTexture::TargetCubeMap: | - | ||||||||||||
2925 | case QOpenGLTexture::TargetCubeMapArray: | - | ||||||||||||
2926 | case QOpenGLTexture::TargetBuffer: | - | ||||||||||||
2927 | case QOpenGLTexture::TargetRectangle: | - | ||||||||||||
2928 | - | |||||||||||||
2929 | qWarning("Texture target does not support multisampling"); | - | ||||||||||||
2930 | break; | - | ||||||||||||
2931 | } | - | ||||||||||||
2932 | } | - | ||||||||||||
2933 | - | |||||||||||||
2934 | /*! | - | ||||||||||||
2935 | Returns whether this texture uses a fixed pattern of multisample | - | ||||||||||||
2936 | samples. If storage has not yet been allocated for this texture then | - | ||||||||||||
2937 | this function returns the requested fixed sample position setting. | - | ||||||||||||
2938 | - | |||||||||||||
2939 | For texture targets that do not support multisampling this | - | ||||||||||||
2940 | will return \c true. | - | ||||||||||||
2941 | - | |||||||||||||
2942 | \sa setFixedSamplePositions(), isStorageAllocated() | - | ||||||||||||
2943 | */ | - | ||||||||||||
2944 | bool QOpenGLTexture::isFixedSamplePositions() const | - | ||||||||||||
2945 | { | - | ||||||||||||
2946 | Q_D(const QOpenGLTexture); | - | ||||||||||||
2947 | return d->fixedSamplePositions; | - | ||||||||||||
2948 | } | - | ||||||||||||
2949 | - | |||||||||||||
2950 | /*! | - | ||||||||||||
2951 | Allocates server-side storage for this texture object taking | - | ||||||||||||
2952 | into account, the format, dimensions, mipmap levels, array | - | ||||||||||||
2953 | layers and cubemap faces. | - | ||||||||||||
2954 | - | |||||||||||||
2955 | Once storage has been allocated it is no longer possible to change | - | ||||||||||||
2956 | these properties. | - | ||||||||||||
2957 | - | |||||||||||||
2958 | If supported QOpenGLTexture makes use of immutable texture | - | ||||||||||||
2959 | storage. | - | ||||||||||||
2960 | - | |||||||||||||
2961 | Once storage has been allocated for the texture then pixel data | - | ||||||||||||
2962 | can be uploaded via one of the setData() overloads. | - | ||||||||||||
2963 | - | |||||||||||||
2964 | \note If immutable texture storage is not available, | - | ||||||||||||
2965 | then a default pixel format and pixel type will be used to | - | ||||||||||||
2966 | create the mutable storage. You can use the other | - | ||||||||||||
2967 | allocateStorage() overload to specify exactly the pixel format | - | ||||||||||||
2968 | and the pixel type to use when allocating mutable storage; | - | ||||||||||||
2969 | this is particulary useful under certain OpenGL ES implementations | - | ||||||||||||
2970 | (notably, OpenGL ES 2), where the pixel format and the pixel type | - | ||||||||||||
2971 | used at allocation time must perfectly match the format | - | ||||||||||||
2972 | and the type passed to any subsequent setData() call. | - | ||||||||||||
2973 | - | |||||||||||||
2974 | \sa isStorageAllocated(), setData() | - | ||||||||||||
2975 | */ | - | ||||||||||||
2976 | void QOpenGLTexture::allocateStorage() | - | ||||||||||||
2977 | { | - | ||||||||||||
2978 | Q_D(QOpenGLTexture); | - | ||||||||||||
2979 | if (d->create()) { | - | ||||||||||||
2980 | const QOpenGLTexture::PixelFormat pixelFormat = pixelFormatCompatibleWithInternalFormat(d->format); | - | ||||||||||||
2981 | const QOpenGLTexture::PixelType pixelType = pixelTypeCompatibleWithInternalFormat(d->format); | - | ||||||||||||
2982 | d->allocateStorage(pixelFormat, pixelType); | - | ||||||||||||
2983 | } | - | ||||||||||||
2984 | } | - | ||||||||||||
2985 | - | |||||||||||||
2986 | /*! | - | ||||||||||||
2987 | \since 5.5 | - | ||||||||||||
2988 | - | |||||||||||||
2989 | Allocates server-side storage for this texture object taking | - | ||||||||||||
2990 | into account, the format, dimensions, mipmap levels, array | - | ||||||||||||
2991 | layers and cubemap faces. | - | ||||||||||||
2992 | - | |||||||||||||
2993 | Once storage has been allocated it is no longer possible to change | - | ||||||||||||
2994 | these properties. | - | ||||||||||||
2995 | - | |||||||||||||
2996 | If supported QOpenGLTexture makes use of immutable texture | - | ||||||||||||
2997 | storage. However, if immutable texture storage is not available, | - | ||||||||||||
2998 | then the specified \a pixelFormat and \a pixelType will be used | - | ||||||||||||
2999 | to allocate mutable storage; note that in certain OpenGL implementations | - | ||||||||||||
3000 | (notably, OpenGL ES 2) they must perfectly match the format | - | ||||||||||||
3001 | and the type passed to any subsequent setData() call. | - | ||||||||||||
3002 | - | |||||||||||||
3003 | Once storage has been allocated for the texture then pixel data | - | ||||||||||||
3004 | can be uploaded via one of the setData() overloads. | - | ||||||||||||
3005 | - | |||||||||||||
3006 | \sa isStorageAllocated(), setData() | - | ||||||||||||
3007 | */ | - | ||||||||||||
3008 | void QOpenGLTexture::allocateStorage(QOpenGLTexture::PixelFormat pixelFormat, QOpenGLTexture::PixelType pixelType) | - | ||||||||||||
3009 | { | - | ||||||||||||
3010 | Q_D(QOpenGLTexture); | - | ||||||||||||
3011 | if (d->create()) | - | ||||||||||||
3012 | d->allocateStorage(pixelFormat, pixelType); | - | ||||||||||||
3013 | } | - | ||||||||||||
3014 | - | |||||||||||||
3015 | /*! | - | ||||||||||||
3016 | Returns \c true if server-side storage for this texture as been | - | ||||||||||||
3017 | allocated. | - | ||||||||||||
3018 | - | |||||||||||||
3019 | The texture format, dimensions, mipmap levels and array layers | - | ||||||||||||
3020 | cannot be altered once storage ihas been allocated. | - | ||||||||||||
3021 | - | |||||||||||||
3022 | \sa allocateStorage(), setSize(), setMipLevels(), setLayers(), setFormat() | - | ||||||||||||
3023 | */ | - | ||||||||||||
3024 | bool QOpenGLTexture::isStorageAllocated() const | - | ||||||||||||
3025 | { | - | ||||||||||||
3026 | Q_D(const QOpenGLTexture); | - | ||||||||||||
3027 | return d->storageAllocated; | - | ||||||||||||
3028 | } | - | ||||||||||||
3029 | - | |||||||||||||
3030 | /*! | - | ||||||||||||
3031 | Attempts to create a texture view onto this texture. A texture | - | ||||||||||||
3032 | view is somewhat analogous to a view in SQL in that it presents | - | ||||||||||||
3033 | a restricted or reinterpreted view of the original data. Texture | - | ||||||||||||
3034 | views do not allocate any more server-side storage, insted relying | - | ||||||||||||
3035 | on the storage buffer of the source texture. | - | ||||||||||||
3036 | - | |||||||||||||
3037 | Texture views are only available when using immutable storage. For | - | ||||||||||||
3038 | more information on texture views see | - | ||||||||||||
3039 | http://www.opengl.org/wiki/Texture_Storage#Texture_views. | - | ||||||||||||
3040 | - | |||||||||||||
3041 | The \a target argument specifies the target to use for the view. | - | ||||||||||||
3042 | Only some targets can be used depending upon the target of the original | - | ||||||||||||
3043 | target. For e.g. a view onto a Target1DArray texture can specify | - | ||||||||||||
3044 | either Target1DArray or Target1D but for the latter the number of | - | ||||||||||||
3045 | array layers specified with \a minimumLayer and \a maximumLayer must | - | ||||||||||||
3046 | be exactly 1. | - | ||||||||||||
3047 | - | |||||||||||||
3048 | Simpliar constraints apply for the \a viewFormat. See the above link | - | ||||||||||||
3049 | and the specification for more details. | - | ||||||||||||
3050 | - | |||||||||||||
3051 | The \a minimumMipmapLevel, \a maximumMipmapLevel, \a minimumLayer, | - | ||||||||||||
3052 | and \a maximumLayer arguments serve to restrict the parts of the | - | ||||||||||||
3053 | texture accessible by the texture view. | - | ||||||||||||
3054 | - | |||||||||||||
3055 | If creation of the texture view fails this function will return | - | ||||||||||||
3056 | 0. If the function succeeds it will return a pointer to a new | - | ||||||||||||
3057 | QOpenGLTexture object that will return \c true from its isTextureView() | - | ||||||||||||
3058 | function. | - | ||||||||||||
3059 | - | |||||||||||||
3060 | \sa isTextureView() | - | ||||||||||||
3061 | */ | - | ||||||||||||
3062 | QOpenGLTexture *QOpenGLTexture::createTextureView(Target target, | - | ||||||||||||
3063 | TextureFormat viewFormat, | - | ||||||||||||
3064 | int minimumMipmapLevel, int maximumMipmapLevel, | - | ||||||||||||
3065 | int minimumLayer, int maximumLayer) const | - | ||||||||||||
3066 | { | - | ||||||||||||
3067 | Q_D(const QOpenGLTexture); | - | ||||||||||||
3068 | if (!isStorageAllocated()) { | - | ||||||||||||
3069 | qWarning("Cannot set create a texture view of a texture that does not have storage allocated."); | - | ||||||||||||
3070 | return 0; | - | ||||||||||||
3071 | } | - | ||||||||||||
3072 | Q_ASSERT(maximumMipmapLevel >= minimumMipmapLevel); | - | ||||||||||||
3073 | Q_ASSERT(maximumLayer >= minimumLayer); | - | ||||||||||||
3074 | return d->createTextureView(target, viewFormat, | - | ||||||||||||
3075 | minimumMipmapLevel, maximumMipmapLevel, | - | ||||||||||||
3076 | minimumLayer, maximumLayer); | - | ||||||||||||
3077 | } | - | ||||||||||||
3078 | - | |||||||||||||
3079 | /*! | - | ||||||||||||
3080 | Returns \c true if this texture object is actually a view onto another | - | ||||||||||||
3081 | texture object. | - | ||||||||||||
3082 | - | |||||||||||||
3083 | \sa createTextureView() | - | ||||||||||||
3084 | */ | - | ||||||||||||
3085 | bool QOpenGLTexture::isTextureView() const | - | ||||||||||||
3086 | { | - | ||||||||||||
3087 | Q_D(const QOpenGLTexture); | - | ||||||||||||
3088 | Q_ASSERT(d->textureId); | - | ||||||||||||
3089 | return d->textureView; | - | ||||||||||||
3090 | } | - | ||||||||||||
3091 | - | |||||||||||||
3092 | /*! | - | ||||||||||||
3093 | Uploads pixel \a data for this texture object \a mipLevel, array \a layer, and \a cubeFace. | - | ||||||||||||
3094 | Storage must have been allocated before uploading pixel data. Some overloads of setData() | - | ||||||||||||
3095 | will set appropriate dimensions, mipmap levels, and array layers and then allocate storage | - | ||||||||||||
3096 | for you if they have enough information to do so. This will be noted in the function | - | ||||||||||||
3097 | documentation. | - | ||||||||||||
3098 | - | |||||||||||||
3099 | The structure of the pixel data pointed to by \a data is specified by \a sourceFormat | - | ||||||||||||
3100 | and \a sourceType. The pixel data upload can optionally be controlled by \a options. | - | ||||||||||||
3101 | - | |||||||||||||
3102 | If using a compressed format() then you should use setCompressedData() instead of this | - | ||||||||||||
3103 | function. | - | ||||||||||||
3104 | - | |||||||||||||
3105 | \since 5.3 | - | ||||||||||||
3106 | \sa setCompressedData() | - | ||||||||||||
3107 | */ | - | ||||||||||||
3108 | void QOpenGLTexture::setData(int mipLevel, int layer, CubeMapFace cubeFace, | - | ||||||||||||
3109 | PixelFormat sourceFormat, PixelType sourceType, | - | ||||||||||||
3110 | const void *data, const QOpenGLPixelTransferOptions * const options) | - | ||||||||||||
3111 | { | - | ||||||||||||
3112 | Q_D(QOpenGLTexture); | - | ||||||||||||
3113 | Q_ASSERT(d->textureId); | - | ||||||||||||
3114 | if (!isStorageAllocated()) { | - | ||||||||||||
3115 | qWarning("Cannot set data on a texture that does not have storage allocated.\n" | - | ||||||||||||
3116 | "To do so call allocateStorage() before this function"); | - | ||||||||||||
3117 | return; | - | ||||||||||||
3118 | } | - | ||||||||||||
3119 | d->setData(mipLevel, layer, cubeFace, sourceFormat, sourceType, data, options); | - | ||||||||||||
3120 | } | - | ||||||||||||
3121 | - | |||||||||||||
3122 | /*! | - | ||||||||||||
3123 | \since 5.3 | - | ||||||||||||
3124 | \overload | - | ||||||||||||
3125 | */ | - | ||||||||||||
3126 | void QOpenGLTexture::setData(int mipLevel, int layer, | - | ||||||||||||
3127 | PixelFormat sourceFormat, PixelType sourceType, | - | ||||||||||||
3128 | const void *data, const QOpenGLPixelTransferOptions * const options) | - | ||||||||||||
3129 | { | - | ||||||||||||
3130 | Q_D(QOpenGLTexture); | - | ||||||||||||
3131 | Q_ASSERT(d->textureId); | - | ||||||||||||
3132 | d->setData(mipLevel, layer, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options); | - | ||||||||||||
3133 | } | - | ||||||||||||
3134 | - | |||||||||||||
3135 | /*! | - | ||||||||||||
3136 | \since 5.3 | - | ||||||||||||
3137 | \overload | - | ||||||||||||
3138 | */ | - | ||||||||||||
3139 | void QOpenGLTexture::setData(int mipLevel, | - | ||||||||||||
3140 | PixelFormat sourceFormat, PixelType sourceType, | - | ||||||||||||
3141 | const void *data, const QOpenGLPixelTransferOptions * const options) | - | ||||||||||||
3142 | { | - | ||||||||||||
3143 | Q_D(QOpenGLTexture); | - | ||||||||||||
3144 | Q_ASSERT(d->textureId); | - | ||||||||||||
3145 | d->setData(mipLevel, 0, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options); | - | ||||||||||||
3146 | } | - | ||||||||||||
3147 | - | |||||||||||||
3148 | /*! | - | ||||||||||||
3149 | \since 5.3 | - | ||||||||||||
3150 | \overload | - | ||||||||||||
3151 | */ | - | ||||||||||||
3152 | void QOpenGLTexture::setData(PixelFormat sourceFormat, PixelType sourceType, | - | ||||||||||||
3153 | const void *data, const QOpenGLPixelTransferOptions * const options) | - | ||||||||||||
3154 | { | - | ||||||||||||
3155 | Q_D(QOpenGLTexture); | - | ||||||||||||
3156 | Q_ASSERT(d->textureId); | - | ||||||||||||
3157 | d->setData(0, 0, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options); | - | ||||||||||||
3158 | } | - | ||||||||||||
3159 | - | |||||||||||||
3160 | #if QT_DEPRECATED_SINCE(5, 3) | - | ||||||||||||
3161 | /*! | - | ||||||||||||
3162 | \obsolete | - | ||||||||||||
3163 | \overload | - | ||||||||||||
3164 | - | |||||||||||||
3165 | \sa setCompressedData() | - | ||||||||||||
3166 | */ | - | ||||||||||||
3167 | void QOpenGLTexture::setData(int mipLevel, int layer, CubeMapFace cubeFace, | - | ||||||||||||
3168 | PixelFormat sourceFormat, PixelType sourceType, | - | ||||||||||||
3169 | void *data, const QOpenGLPixelTransferOptions * const options) | - | ||||||||||||
3170 | { | - | ||||||||||||
3171 | Q_D(QOpenGLTexture); | - | ||||||||||||
3172 | Q_ASSERT(d->textureId); | - | ||||||||||||
3173 | if (!isStorageAllocated()) { | - | ||||||||||||
3174 | qWarning("Cannot set data on a texture that does not have storage allocated.\n" | - | ||||||||||||
3175 | "To do so call allocateStorage() before this function"); | - | ||||||||||||
3176 | return; | - | ||||||||||||
3177 | } | - | ||||||||||||
3178 | d->setData(mipLevel, layer, cubeFace, sourceFormat, sourceType, data, options); | - | ||||||||||||
3179 | } | - | ||||||||||||
3180 | - | |||||||||||||
3181 | /*! | - | ||||||||||||
3182 | \obsolete | - | ||||||||||||
3183 | \overload | - | ||||||||||||
3184 | */ | - | ||||||||||||
3185 | void QOpenGLTexture::setData(int mipLevel, int layer, | - | ||||||||||||
3186 | PixelFormat sourceFormat, PixelType sourceType, | - | ||||||||||||
3187 | void *data, const QOpenGLPixelTransferOptions * const options) | - | ||||||||||||
3188 | { | - | ||||||||||||
3189 | Q_D(QOpenGLTexture); | - | ||||||||||||
3190 | Q_ASSERT(d->textureId); | - | ||||||||||||
3191 | d->setData(mipLevel, layer, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options); | - | ||||||||||||
3192 | } | - | ||||||||||||
3193 | - | |||||||||||||
3194 | /*! | - | ||||||||||||
3195 | \obsolete | - | ||||||||||||
3196 | \overload | - | ||||||||||||
3197 | */ | - | ||||||||||||
3198 | void QOpenGLTexture::setData(int mipLevel, | - | ||||||||||||
3199 | PixelFormat sourceFormat, PixelType sourceType, | - | ||||||||||||
3200 | void *data, const QOpenGLPixelTransferOptions * const options) | - | ||||||||||||
3201 | { | - | ||||||||||||
3202 | Q_D(QOpenGLTexture); | - | ||||||||||||
3203 | Q_ASSERT(d->textureId); | - | ||||||||||||
3204 | d->setData(mipLevel, 0, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options); | - | ||||||||||||
3205 | } | - | ||||||||||||
3206 | - | |||||||||||||
3207 | /*! | - | ||||||||||||
3208 | \obsolete | - | ||||||||||||
3209 | \overload | - | ||||||||||||
3210 | */ | - | ||||||||||||
3211 | void QOpenGLTexture::setData(PixelFormat sourceFormat, PixelType sourceType, | - | ||||||||||||
3212 | void *data, const QOpenGLPixelTransferOptions * const options) | - | ||||||||||||
3213 | { | - | ||||||||||||
3214 | Q_D(QOpenGLTexture); | - | ||||||||||||
3215 | Q_ASSERT(d->textureId); | - | ||||||||||||
3216 | d->setData(0, 0, QOpenGLTexture::CubeMapPositiveX, sourceFormat, sourceType, data, options); | - | ||||||||||||
3217 | } | - | ||||||||||||
3218 | #endif | - | ||||||||||||
3219 | - | |||||||||||||
3220 | /*! | - | ||||||||||||
3221 | This overload of setData() will allocate storage for you. | - | ||||||||||||
3222 | The pixel data is contained in \a image. Mipmaps are generated by default. | - | ||||||||||||
3223 | Set \a genMipMaps to \l DontGenerateMipMaps to turn off mipmap generation. | - | ||||||||||||
3224 | - | |||||||||||||
3225 | \overload | - | ||||||||||||
3226 | */ | - | ||||||||||||
3227 | void QOpenGLTexture::setData(const QImage& image, MipMapGeneration genMipMaps) | - | ||||||||||||
3228 | { | - | ||||||||||||
3229 | QOpenGLContext *context = QOpenGLContext::currentContext(); | - | ||||||||||||
3230 | if (!context) { | - | ||||||||||||
3231 | qWarning("QOpenGLTexture::setData() requires a valid current context"); | - | ||||||||||||
3232 | return; | - | ||||||||||||
3233 | } | - | ||||||||||||
3234 | - | |||||||||||||
3235 | if (image.isNull()) { | - | ||||||||||||
3236 | qWarning("QOpenGLTexture::setData() tried to set a null image"); | - | ||||||||||||
3237 | return; | - | ||||||||||||
3238 | } | - | ||||||||||||
3239 | - | |||||||||||||
3240 | if (context->isOpenGLES() && context->format().majorVersion() < 3) | - | ||||||||||||
3241 | setFormat(QOpenGLTexture::RGBAFormat); | - | ||||||||||||
3242 | else | - | ||||||||||||
3243 | setFormat(QOpenGLTexture::RGBA8_UNorm); | - | ||||||||||||
3244 | - | |||||||||||||
3245 | setSize(image.width(), image.height()); | - | ||||||||||||
3246 | setMipLevels(genMipMaps == GenerateMipMaps ? maximumMipLevels() : 1); | - | ||||||||||||
3247 | allocateStorage(QOpenGLTexture::RGBA, QOpenGLTexture::UInt8); | - | ||||||||||||
3248 | - | |||||||||||||
3249 | // Upload pixel data and generate mipmaps | - | ||||||||||||
3250 | QImage glImage = image.convertToFormat(QImage::Format_RGBA8888); | - | ||||||||||||
3251 | QOpenGLPixelTransferOptions uploadOptions; | - | ||||||||||||
3252 | uploadOptions.setAlignment(1); | - | ||||||||||||
3253 | setData(0, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, glImage.constBits(), &uploadOptions); | - | ||||||||||||
3254 | } | - | ||||||||||||
3255 | - | |||||||||||||
3256 | /*! | - | ||||||||||||
3257 | Uploads compressed pixel \a data to \a mipLevel, array \a layer, and \a cubeFace. | - | ||||||||||||
3258 | The pixel transfer can optionally be controlled with \a options. The \a dataSize | - | ||||||||||||
3259 | argument should specify the size of the data pointed to by \a data. | - | ||||||||||||
3260 | - | |||||||||||||
3261 | If not using a compressed format() then you should use setData() instead of this | - | ||||||||||||
3262 | function. | - | ||||||||||||
3263 | - | |||||||||||||
3264 | \since 5.3 | - | ||||||||||||
3265 | */ | - | ||||||||||||
3266 | void QOpenGLTexture::setCompressedData(int mipLevel, int layer, CubeMapFace cubeFace, | - | ||||||||||||
3267 | int dataSize, const void *data, | - | ||||||||||||
3268 | const QOpenGLPixelTransferOptions * const options) | - | ||||||||||||
3269 | { | - | ||||||||||||
3270 | Q_D(QOpenGLTexture); | - | ||||||||||||
3271 | Q_ASSERT(d->textureId); | - | ||||||||||||
3272 | if (!isStorageAllocated()) { | - | ||||||||||||
3273 | qWarning("Cannot set data on a texture that does not have storage allocated.\n" | - | ||||||||||||
3274 | "To do so call allocateStorage() before this function"); | - | ||||||||||||
3275 | return; | - | ||||||||||||
3276 | } | - | ||||||||||||
3277 | d->setCompressedData(mipLevel, layer, cubeFace, dataSize, data, options); | - | ||||||||||||
3278 | } | - | ||||||||||||
3279 | - | |||||||||||||
3280 | /*! | - | ||||||||||||
3281 | \overload | - | ||||||||||||
3282 | */ | - | ||||||||||||
3283 | void QOpenGLTexture::setCompressedData(int mipLevel, int layer, int dataSize, const void *data, | - | ||||||||||||
3284 | const QOpenGLPixelTransferOptions * const options) | - | ||||||||||||
3285 | { | - | ||||||||||||
3286 | Q_D(QOpenGLTexture); | - | ||||||||||||
3287 | Q_ASSERT(d->textureId); | - | ||||||||||||
3288 | d->setCompressedData(mipLevel, layer, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options); | - | ||||||||||||
3289 | } | - | ||||||||||||
3290 | - | |||||||||||||
3291 | /*! | - | ||||||||||||
3292 | \overload | - | ||||||||||||
3293 | */ | - | ||||||||||||
3294 | void QOpenGLTexture::setCompressedData(int mipLevel, int dataSize, const void *data, | - | ||||||||||||
3295 | const QOpenGLPixelTransferOptions * const options) | - | ||||||||||||
3296 | { | - | ||||||||||||
3297 | Q_D(QOpenGLTexture); | - | ||||||||||||
3298 | Q_ASSERT(d->textureId); | - | ||||||||||||
3299 | d->setCompressedData(mipLevel, 0, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options); | - | ||||||||||||
3300 | } | - | ||||||||||||
3301 | - | |||||||||||||
3302 | /*! | - | ||||||||||||
3303 | \overload | - | ||||||||||||
3304 | */ | - | ||||||||||||
3305 | void QOpenGLTexture::setCompressedData(int dataSize, const void *data, | - | ||||||||||||
3306 | const QOpenGLPixelTransferOptions * const options) | - | ||||||||||||
3307 | { | - | ||||||||||||
3308 | Q_D(QOpenGLTexture); | - | ||||||||||||
3309 | Q_ASSERT(d->textureId); | - | ||||||||||||
3310 | d->setCompressedData(0, 0, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options); | - | ||||||||||||
3311 | } | - | ||||||||||||
3312 | - | |||||||||||||
3313 | #if QT_DEPRECATED_SINCE(5, 3) | - | ||||||||||||
3314 | /*! | - | ||||||||||||
3315 | \obsolete | - | ||||||||||||
3316 | \overload | - | ||||||||||||
3317 | */ | - | ||||||||||||
3318 | void QOpenGLTexture::setCompressedData(int mipLevel, int layer, CubeMapFace cubeFace, | - | ||||||||||||
3319 | int dataSize, void *data, | - | ||||||||||||
3320 | const QOpenGLPixelTransferOptions * const options) | - | ||||||||||||
3321 | { | - | ||||||||||||
3322 | Q_D(QOpenGLTexture); | - | ||||||||||||
3323 | Q_ASSERT(d->textureId); | - | ||||||||||||
3324 | if (!isStorageAllocated()) { | - | ||||||||||||
3325 | qWarning("Cannot set data on a texture that does not have storage allocated.\n" | - | ||||||||||||
3326 | "To do so call allocateStorage() before this function"); | - | ||||||||||||
3327 | return; | - | ||||||||||||
3328 | } | - | ||||||||||||
3329 | d->setCompressedData(mipLevel, layer, cubeFace, dataSize, data, options); | - | ||||||||||||
3330 | } | - | ||||||||||||
3331 | - | |||||||||||||
3332 | /*! | - | ||||||||||||
3333 | \obsolete | - | ||||||||||||
3334 | \overload | - | ||||||||||||
3335 | */ | - | ||||||||||||
3336 | void QOpenGLTexture::setCompressedData(int mipLevel, int layer, int dataSize, void *data, | - | ||||||||||||
3337 | const QOpenGLPixelTransferOptions * const options) | - | ||||||||||||
3338 | { | - | ||||||||||||
3339 | Q_D(QOpenGLTexture); | - | ||||||||||||
3340 | Q_ASSERT(d->textureId); | - | ||||||||||||
3341 | d->setCompressedData(mipLevel, layer, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options); | - | ||||||||||||
3342 | } | - | ||||||||||||
3343 | - | |||||||||||||
3344 | /*! | - | ||||||||||||
3345 | \obsolete | - | ||||||||||||
3346 | \overload | - | ||||||||||||
3347 | */ | - | ||||||||||||
3348 | void QOpenGLTexture::setCompressedData(int mipLevel, int dataSize, void *data, | - | ||||||||||||
3349 | const QOpenGLPixelTransferOptions * const options) | - | ||||||||||||
3350 | { | - | ||||||||||||
3351 | Q_D(QOpenGLTexture); | - | ||||||||||||
3352 | Q_ASSERT(d->textureId); | - | ||||||||||||
3353 | d->setCompressedData(mipLevel, 0, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options); | - | ||||||||||||
3354 | } | - | ||||||||||||
3355 | - | |||||||||||||
3356 | /*! | - | ||||||||||||
3357 | \obsolete | - | ||||||||||||
3358 | \overload | - | ||||||||||||
3359 | */ | - | ||||||||||||
3360 | void QOpenGLTexture::setCompressedData(int dataSize, void *data, | - | ||||||||||||
3361 | const QOpenGLPixelTransferOptions * const options) | - | ||||||||||||
3362 | { | - | ||||||||||||
3363 | Q_D(QOpenGLTexture); | - | ||||||||||||
3364 | Q_ASSERT(d->textureId); | - | ||||||||||||
3365 | d->setCompressedData(0, 0, QOpenGLTexture::CubeMapPositiveX, dataSize, data, options); | - | ||||||||||||
3366 | } | - | ||||||||||||
3367 | #endif | - | ||||||||||||
3368 | - | |||||||||||||
3369 | /*! | - | ||||||||||||
3370 | Returns \c true if your OpenGL implementation and version supports the texture | - | ||||||||||||
3371 | feature \a feature. | - | ||||||||||||
3372 | */ | - | ||||||||||||
3373 | bool QOpenGLTexture::hasFeature(Feature feature) | - | ||||||||||||
3374 | { | - | ||||||||||||
3375 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - | ||||||||||||
3376 | if (!ctx) { | - | ||||||||||||
3377 | qWarning("QOpenGLTexture::hasFeature() requires a valid current context"); | - | ||||||||||||
3378 | return false; | - | ||||||||||||
3379 | } | - | ||||||||||||
3380 | - | |||||||||||||
3381 | QSurfaceFormat f = ctx->format(); | - | ||||||||||||
3382 | - | |||||||||||||
3383 | bool supported = false; | - | ||||||||||||
3384 | - | |||||||||||||
3385 | #if !defined(QT_OPENGL_ES_2) | - | ||||||||||||
3386 | if (!ctx->isOpenGLES()) { | - | ||||||||||||
3387 | switch (feature) { | - | ||||||||||||
3388 | case ImmutableMultisampleStorage: | - | ||||||||||||
3389 | supported = f.version() >= qMakePair(4, 3) | - | ||||||||||||
3390 | || ctx->hasExtension(QByteArrayLiteral("GL_ARB_texture_storage_multisample")); | - | ||||||||||||
3391 | break; | - | ||||||||||||
3392 | - | |||||||||||||
3393 | case TextureBuffer: | - | ||||||||||||
3394 | supported = f.version() >= qMakePair(3, 0) | - | ||||||||||||
3395 | || ctx->hasExtension(QByteArrayLiteral("GL_ARB_texture_buffer_object")); | - | ||||||||||||
3396 | break; | - | ||||||||||||
3397 | - | |||||||||||||
3398 | case StencilTexturing: | - | ||||||||||||
3399 | supported = f.version() >= qMakePair(4, 3) | - | ||||||||||||
3400 | || ctx->hasExtension(QByteArrayLiteral("GL_ARB_stencil_texturing")); | - | ||||||||||||
3401 | break; | - | ||||||||||||
3402 | - | |||||||||||||
3403 | case ImmutableStorage: | - | ||||||||||||
3404 | supported = f.version() >= qMakePair(4, 2) | - | ||||||||||||
3405 | || ctx->hasExtension(QByteArrayLiteral("GL_ARB_texture_storage")) | - | ||||||||||||
3406 | || ctx->hasExtension(QByteArrayLiteral("GL_EXT_texture_storage")); | - | ||||||||||||
3407 | break; | - | ||||||||||||
3408 | - | |||||||||||||
3409 | case TextureCubeMapArrays: | - | ||||||||||||
3410 | supported = f.version() >= qMakePair(4, 0) | - | ||||||||||||
3411 | || ctx->hasExtension(QByteArrayLiteral("ARB_texture_cube_map_array")); | - | ||||||||||||
3412 | break; | - | ||||||||||||
3413 | - | |||||||||||||
3414 | case Swizzle: | - | ||||||||||||
3415 | supported = f.version() >= qMakePair(3, 3) | - | ||||||||||||
3416 | || ctx->hasExtension(QByteArrayLiteral("GL_ARB_texture_swizzle")); | - | ||||||||||||
3417 | break; | - | ||||||||||||
3418 | - | |||||||||||||
3419 | case TextureMultisample: | - | ||||||||||||
3420 | supported = f.version() >= qMakePair(3, 2) | - | ||||||||||||
3421 | || ctx->hasExtension(QByteArrayLiteral("GL_ARB_texture_multisample")); | - | ||||||||||||
3422 | break; | - | ||||||||||||
3423 | - | |||||||||||||
3424 | case TextureArrays: | - | ||||||||||||
3425 | supported = f.version() >= qMakePair(3, 0) | - | ||||||||||||
3426 | || ctx->hasExtension(QByteArrayLiteral("GL_EXT_texture_array")); | - | ||||||||||||
3427 | break; | - | ||||||||||||
3428 | - | |||||||||||||
3429 | case TextureRectangle: | - | ||||||||||||
3430 | supported = f.version() >= qMakePair(2, 1) | - | ||||||||||||
3431 | || ctx->hasExtension(QByteArrayLiteral("ARB_texture_rectangle")); | - | ||||||||||||
3432 | break; | - | ||||||||||||
3433 | - | |||||||||||||
3434 | case Texture3D: | - | ||||||||||||
3435 | supported = f.version() >= qMakePair(1, 3); | - | ||||||||||||
3436 | break; | - | ||||||||||||
3437 | - | |||||||||||||
3438 | case AnisotropicFiltering: | - | ||||||||||||
3439 | supported = ctx->hasExtension(QByteArrayLiteral("GL_EXT_texture_filter_anisotropic")); | - | ||||||||||||
3440 | break; | - | ||||||||||||
3441 | - | |||||||||||||
3442 | case NPOTTextures: | - | ||||||||||||
3443 | case NPOTTextureRepeat: | - | ||||||||||||
3444 | supported = ctx->hasExtension(QByteArrayLiteral("GL_ARB_texture_non_power_of_two")); | - | ||||||||||||
3445 | break; | - | ||||||||||||
3446 | - | |||||||||||||
3447 | case Texture1D: | - | ||||||||||||
3448 | supported = f.version() >= qMakePair(1, 1); | - | ||||||||||||
3449 | break; | - | ||||||||||||
3450 | - | |||||||||||||
3451 | case TextureComparisonOperators: | - | ||||||||||||
3452 | // GL 1.4 and GL_ARB_shadow alone support only LEQUAL and GEQUAL; | - | ||||||||||||
3453 | // since we're talking about history anyhow avoid to be extra pedantic | - | ||||||||||||
3454 | // in the feature set, and simply claim supported if we have the full set of operators | - | ||||||||||||
3455 | // (which has been added into 1.5 / GL_EXT_shadow_funcs). | - | ||||||||||||
3456 | supported = f.version() >= qMakePair(1, 5) | - | ||||||||||||
3457 | || (ctx->hasExtension(QByteArrayLiteral("GL_ARB_shadow")) | - | ||||||||||||
3458 | && ctx->hasExtension(QByteArrayLiteral("GL_EXT_shadow_funcs"))); | - | ||||||||||||
3459 | break; | - | ||||||||||||
3460 | - | |||||||||||||
3461 | case TextureMipMapLevel: | - | ||||||||||||
3462 | supported = f.version() >= qMakePair(1, 2); | - | ||||||||||||
3463 | break; | - | ||||||||||||
3464 | - | |||||||||||||
3465 | case MaxFeatureFlag: | - | ||||||||||||
3466 | break; | - | ||||||||||||
3467 | } | - | ||||||||||||
3468 | } | - | ||||||||||||
3469 | - | |||||||||||||
3470 | if (ctx->isOpenGLES()) | - | ||||||||||||
3471 | #endif | - | ||||||||||||
3472 | { | - | ||||||||||||
3473 | const char *renderer = reinterpret_cast<const char *>(ctx->functions()->glGetString(GL_RENDERER)); | - | ||||||||||||
3474 | switch (feature) { | - | ||||||||||||
3475 | case ImmutableStorage: | - | ||||||||||||
3476 | supported = (f.version() >= qMakePair(3, 0) || ctx->hasExtension(QByteArrayLiteral("EXT_texture_storage"))) | - | ||||||||||||
3477 | && !(renderer && strstr(renderer, "Mali")); // do not use on Mali: QTBUG-45106 | - | ||||||||||||
3478 | break; | - | ||||||||||||
3479 | - | |||||||||||||
3480 | case ImmutableMultisampleStorage: | - | ||||||||||||
3481 | supported = f.version() >= qMakePair(3, 1); | - | ||||||||||||
3482 | break; | - | ||||||||||||
3483 | - | |||||||||||||
3484 | case TextureRectangle: | - | ||||||||||||
3485 | break; | - | ||||||||||||
3486 | - | |||||||||||||
3487 | case TextureArrays: | - | ||||||||||||
3488 | supported = f.version() >= qMakePair(3, 0); | - | ||||||||||||
3489 | break; | - | ||||||||||||
3490 | - | |||||||||||||
3491 | case Texture3D: | - | ||||||||||||
3492 | supported = f.version() >= qMakePair(3, 0) | - | ||||||||||||
3493 | || ctx->hasExtension(QByteArrayLiteral("GL_OES_texture_3D")); | - | ||||||||||||
3494 | break; | - | ||||||||||||
3495 | - | |||||||||||||
3496 | case TextureMultisample: | - | ||||||||||||
3497 | supported = f.version() >= qMakePair(3, 1); | - | ||||||||||||
3498 | break; | - | ||||||||||||
3499 | - | |||||||||||||
3500 | case TextureBuffer: | - | ||||||||||||
3501 | break; | - | ||||||||||||
3502 | - | |||||||||||||
3503 | case TextureCubeMapArrays: | - | ||||||||||||
3504 | break; | - | ||||||||||||
3505 | - | |||||||||||||
3506 | case Swizzle: | - | ||||||||||||
3507 | supported = f.version() >= qMakePair(3, 0); | - | ||||||||||||
3508 | break; | - | ||||||||||||
3509 | - | |||||||||||||
3510 | case StencilTexturing: | - | ||||||||||||
3511 | break; | - | ||||||||||||
3512 | - | |||||||||||||
3513 | case AnisotropicFiltering: | - | ||||||||||||
3514 | supported = ctx->hasExtension(QByteArrayLiteral("GL_EXT_texture_filter_anisotropic")); | - | ||||||||||||
3515 | break; | - | ||||||||||||
3516 | - | |||||||||||||
3517 | case NPOTTextures: | - | ||||||||||||
3518 | case NPOTTextureRepeat: | - | ||||||||||||
3519 | supported = f.version() >= qMakePair(3,0) | - | ||||||||||||
3520 | || ctx->hasExtension(QByteArrayLiteral("GL_OES_texture_npot")) | - | ||||||||||||
3521 | || ctx->hasExtension(QByteArrayLiteral("GL_ARB_texture_non_power_of_two")); | - | ||||||||||||
3522 | break; | - | ||||||||||||
3523 | - | |||||||||||||
3524 | case Texture1D: | - | ||||||||||||
3525 | break; | - | ||||||||||||
3526 | - | |||||||||||||
3527 | case TextureComparisonOperators: | - | ||||||||||||
3528 | supported = f.version() >= qMakePair(3, 0) | - | ||||||||||||
3529 | || ctx->hasExtension(QByteArrayLiteral("GL_EXT_shadow_samplers")); | - | ||||||||||||
3530 | break; | - | ||||||||||||
3531 | - | |||||||||||||
3532 | case TextureMipMapLevel: | - | ||||||||||||
3533 | supported = f.version() >= qMakePair(3, 0); | - | ||||||||||||
3534 | break; | - | ||||||||||||
3535 | - | |||||||||||||
3536 | case MaxFeatureFlag: | - | ||||||||||||
3537 | break; | - | ||||||||||||
3538 | } | - | ||||||||||||
3539 | } | - | ||||||||||||
3540 | - | |||||||||||||
3541 | return supported; | - | ||||||||||||
3542 | } | - | ||||||||||||
3543 | - | |||||||||||||
3544 | /*! | - | ||||||||||||
3545 | Sets the base mipmap level used for all texture lookups with this texture to \a baseLevel. | - | ||||||||||||
3546 | - | |||||||||||||
3547 | \note This function has no effect on Qt built for OpenGL ES 2. | - | ||||||||||||
3548 | \sa mipBaseLevel(), setMipMaxLevel(), setMipLevelRange() | - | ||||||||||||
3549 | */ | - | ||||||||||||
3550 | void QOpenGLTexture::setMipBaseLevel(int baseLevel) | - | ||||||||||||
3551 | { | - | ||||||||||||
3552 | Q_D(QOpenGLTexture); | - | ||||||||||||
3553 | d->create(); | - | ||||||||||||
3554 | if (!d->features.testFlag(TextureMipMapLevel)) { | - | ||||||||||||
3555 | qWarning("QOpenGLTexture::setMipBaseLevel: requires OpenGL >= 1.2 or OpenGL ES >= 3.0"); | - | ||||||||||||
3556 | return; | - | ||||||||||||
3557 | } | - | ||||||||||||
3558 | Q_ASSERT(d->textureId); | - | ||||||||||||
3559 | Q_ASSERT(d->texFuncs); | - | ||||||||||||
3560 | Q_ASSERT(baseLevel <= d->maxLevel); | - | ||||||||||||
3561 | d->baseLevel = baseLevel; | - | ||||||||||||
3562 | d->texFuncs->glTextureParameteri(d->textureId, d->target, d->bindingTarget, GL_TEXTURE_BASE_LEVEL, baseLevel); | - | ||||||||||||
3563 | } | - | ||||||||||||
3564 | - | |||||||||||||
3565 | /*! | - | ||||||||||||
3566 | Returns the mipmap base level used for all texture lookups with this texture. | - | ||||||||||||
3567 | The default is 0. | - | ||||||||||||
3568 | - | |||||||||||||
3569 | \sa setMipBaseLevel(), mipMaxLevel(), mipLevelRange() | - | ||||||||||||
3570 | */ | - | ||||||||||||
3571 | int QOpenGLTexture::mipBaseLevel() const | - | ||||||||||||
3572 | { | - | ||||||||||||
3573 | Q_D(const QOpenGLTexture); | - | ||||||||||||
3574 | return d->baseLevel; | - | ||||||||||||
3575 | } | - | ||||||||||||
3576 | - | |||||||||||||
3577 | /*! | - | ||||||||||||
3578 | Sets the maximum mipmap level used for all texture lookups with this texture to \a maxLevel. | - | ||||||||||||
3579 | - | |||||||||||||
3580 | \note This function has no effect on Qt built for OpenGL ES 2. | - | ||||||||||||
3581 | \sa mipMaxLevel(), setMipBaseLevel(), setMipLevelRange() | - | ||||||||||||
3582 | */ | - | ||||||||||||
3583 | void QOpenGLTexture::setMipMaxLevel(int maxLevel) | - | ||||||||||||
3584 | { | - | ||||||||||||
3585 | Q_D(QOpenGLTexture); | - | ||||||||||||
3586 | d->create(); | - | ||||||||||||
3587 | if (!d->features.testFlag(TextureMipMapLevel)) { | - | ||||||||||||
3588 | qWarning("QOpenGLTexture::setMipMaxLevel: requires OpenGL >= 1.2 or OpenGL ES >= 3.0"); | - | ||||||||||||
3589 | return; | - | ||||||||||||
3590 | } | - | ||||||||||||
3591 | Q_ASSERT(d->textureId); | - | ||||||||||||
3592 | Q_ASSERT(d->texFuncs); | - | ||||||||||||
3593 | Q_ASSERT(d->baseLevel <= maxLevel); | - | ||||||||||||
3594 | d->maxLevel = maxLevel; | - | ||||||||||||
3595 | d->texFuncs->glTextureParameteri(d->textureId, d->target, d->bindingTarget, GL_TEXTURE_MAX_LEVEL, maxLevel); | - | ||||||||||||
3596 | } | - | ||||||||||||
3597 | - | |||||||||||||
3598 | /*! | - | ||||||||||||
3599 | Returns the mipmap maximum level used for all texture lookups with this texture. | - | ||||||||||||
3600 | - | |||||||||||||
3601 | \sa setMipMaxLevel(), mipBaseLevel(), mipLevelRange() | - | ||||||||||||
3602 | */ | - | ||||||||||||
3603 | int QOpenGLTexture::mipMaxLevel() const | - | ||||||||||||
3604 | { | - | ||||||||||||
3605 | Q_D(const QOpenGLTexture); | - | ||||||||||||
3606 | return d->maxLevel; | - | ||||||||||||
3607 | } | - | ||||||||||||
3608 | - | |||||||||||||
3609 | /*! | - | ||||||||||||
3610 | Sets the range of mipmap levels that can be used for texture lookups with this texture | - | ||||||||||||
3611 | to range from \a baseLevel to \a maxLevel. | - | ||||||||||||
3612 | - | |||||||||||||
3613 | \note This function has no effect on Qt built for OpenGL ES 2. | - | ||||||||||||
3614 | \sa setMipBaseLevel(), setMipMaxLevel(), mipLevelRange() | - | ||||||||||||
3615 | */ | - | ||||||||||||
3616 | void QOpenGLTexture::setMipLevelRange(int baseLevel, int maxLevel) | - | ||||||||||||
3617 | { | - | ||||||||||||
3618 | Q_D(QOpenGLTexture); | - | ||||||||||||
3619 | d->create(); | - | ||||||||||||
3620 | if (!d->features.testFlag(TextureMipMapLevel)) { | - | ||||||||||||
3621 | qWarning("QOpenGLTexture::setMipLevelRange: requires OpenGL >= 1.2 or OpenGL ES >= 3.0"); | - | ||||||||||||
3622 | return; | - | ||||||||||||
3623 | } | - | ||||||||||||
3624 | Q_ASSERT(d->textureId); | - | ||||||||||||
3625 | Q_ASSERT(d->texFuncs); | - | ||||||||||||
3626 | Q_ASSERT(baseLevel <= maxLevel); | - | ||||||||||||
3627 | d->texFuncs->glTextureParameteri(d->textureId, d->target, d->bindingTarget, GL_TEXTURE_BASE_LEVEL, baseLevel); | - | ||||||||||||
3628 | d->texFuncs->glTextureParameteri(d->textureId, d->target, d->bindingTarget, GL_TEXTURE_MAX_LEVEL, maxLevel); | - | ||||||||||||
3629 | } | - | ||||||||||||
3630 | - | |||||||||||||
3631 | /*! | - | ||||||||||||
3632 | Returns the range of mipmap levels that can be used for texture lookups with this texture. | - | ||||||||||||
3633 | - | |||||||||||||
3634 | \sa mipBaseLevel(), mipMaxLevel() | - | ||||||||||||
3635 | */ | - | ||||||||||||
3636 | QPair<int, int> QOpenGLTexture::mipLevelRange() const | - | ||||||||||||
3637 | { | - | ||||||||||||
3638 | Q_D(const QOpenGLTexture); | - | ||||||||||||
3639 | return qMakePair(d->baseLevel, d->maxLevel); | - | ||||||||||||
3640 | } | - | ||||||||||||
3641 | - | |||||||||||||
3642 | /*! | - | ||||||||||||
3643 | If \a enabled is \c true, enables automatic mipmap generation for this texture object | - | ||||||||||||
3644 | to occur whenever the level 0 mipmap data is set via setData(). | - | ||||||||||||
3645 | - | |||||||||||||
3646 | The automatic mipmap generation is enabled by default. | - | ||||||||||||
3647 | - | |||||||||||||
3648 | \note Mipmap generation is not supported for compressed textures with OpenGL ES 2.0. | - | ||||||||||||
3649 | - | |||||||||||||
3650 | \sa isAutoMipMapGenerationEnabled(), generateMipMaps() | - | ||||||||||||
3651 | */ | - | ||||||||||||
3652 | void QOpenGLTexture::setAutoMipMapGenerationEnabled(bool enabled) | - | ||||||||||||
3653 | { | - | ||||||||||||
3654 | Q_D(QOpenGLTexture); | - | ||||||||||||
3655 | d->autoGenerateMipMaps = enabled; | - | ||||||||||||
3656 | } | - | ||||||||||||
3657 | - | |||||||||||||
3658 | /*! | - | ||||||||||||
3659 | Returns whether auto mipmap generation is enabled for this texture object. | - | ||||||||||||
3660 | - | |||||||||||||
3661 | \sa setAutoMipMapGenerationEnabled(), generateMipMaps() | - | ||||||||||||
3662 | */ | - | ||||||||||||
3663 | bool QOpenGLTexture::isAutoMipMapGenerationEnabled() const | - | ||||||||||||
3664 | { | - | ||||||||||||
3665 | Q_D(const QOpenGLTexture); | - | ||||||||||||
3666 | return d->autoGenerateMipMaps; | - | ||||||||||||
3667 | } | - | ||||||||||||
3668 | - | |||||||||||||
3669 | /*! | - | ||||||||||||
3670 | Generates mipmaps for this texture object from mipmap level 0. If you are | - | ||||||||||||
3671 | using a texture target and filtering option that requires mipmaps and you | - | ||||||||||||
3672 | have disabled automatic mipmap generation then you need to call this function | - | ||||||||||||
3673 | or the overload to create the mipmap chain. | - | ||||||||||||
3674 | - | |||||||||||||
3675 | \note Mipmap generation is not supported for compressed textures with OpenGL | - | ||||||||||||
3676 | ES 2.0. | - | ||||||||||||
3677 | - | |||||||||||||
3678 | \sa setAutoMipMapGenerationEnabled(), setMipLevels(), mipLevels() | - | ||||||||||||
3679 | */ | - | ||||||||||||
3680 | void QOpenGLTexture::generateMipMaps() | - | ||||||||||||
3681 | { | - | ||||||||||||
3682 | Q_D(QOpenGLTexture); | - | ||||||||||||
3683 | Q_ASSERT(d->texFuncs); | - | ||||||||||||
3684 | Q_ASSERT(d->textureId); | - | ||||||||||||
3685 | if (isCompressedFormat(d->format)) { | - | ||||||||||||
3686 | if (QOpenGLContext *ctx = QOpenGLContext::currentContext()) | - | ||||||||||||
3687 | if (ctx->isOpenGLES() && ctx->format().majorVersion() < 3) | - | ||||||||||||
3688 | return; | - | ||||||||||||
3689 | } | - | ||||||||||||
3690 | d->texFuncs->glGenerateTextureMipmap(d->textureId, d->target, d->bindingTarget); | - | ||||||||||||
3691 | } | - | ||||||||||||
3692 | - | |||||||||||||
3693 | /*! | - | ||||||||||||
3694 | Generates mipmaps for this texture object from mipmap level \a baseLevel. If you are | - | ||||||||||||
3695 | using a texture target and filtering option that requires mipmaps and you | - | ||||||||||||
3696 | have disabled automatic mipmap generation then you need to call this function | - | ||||||||||||
3697 | or the overload to create the mipmap chain. | - | ||||||||||||
3698 | - | |||||||||||||
3699 | The generation of mipmaps to above \a baseLevel is achieved by setting the mipmap | - | ||||||||||||
3700 | base level to \a baseLevel and then generating the mipmap chain. If \a resetBaseLevel | - | ||||||||||||
3701 | is \c true, then the baseLevel of the texture will be reset to its previous value. | - | ||||||||||||
3702 | - | |||||||||||||
3703 | \sa setAutoMipMapGenerationEnabled(), setMipLevels(), mipLevels() | - | ||||||||||||
3704 | */ | - | ||||||||||||
3705 | void QOpenGLTexture::generateMipMaps(int baseLevel, bool resetBaseLevel) | - | ||||||||||||
3706 | { | - | ||||||||||||
3707 | Q_D(QOpenGLTexture); | - | ||||||||||||
3708 | Q_ASSERT(d->texFuncs); | - | ||||||||||||
3709 | Q_ASSERT(d->textureId); | - | ||||||||||||
3710 | if (isCompressedFormat(d->format)) { | - | ||||||||||||
3711 | if (QOpenGLContext *ctx = QOpenGLContext::currentContext()) | - | ||||||||||||
3712 | if (ctx->isOpenGLES() && ctx->format().majorVersion() < 3) | - | ||||||||||||
3713 | return; | - | ||||||||||||
3714 | } | - | ||||||||||||
3715 | int oldBaseLevel; | - | ||||||||||||
3716 | if (resetBaseLevel) | - | ||||||||||||
3717 | oldBaseLevel = mipBaseLevel(); | - | ||||||||||||
3718 | setMipBaseLevel(baseLevel); | - | ||||||||||||
3719 | d->texFuncs->glGenerateTextureMipmap(d->textureId, d->target, d->bindingTarget); | - | ||||||||||||
3720 | if (resetBaseLevel) | - | ||||||||||||
3721 | setMipBaseLevel(oldBaseLevel); | - | ||||||||||||
3722 | } | - | ||||||||||||
3723 | - | |||||||||||||
3724 | /*! | - | ||||||||||||
3725 | GLSL shaders are able to reorder the components of the vec4 returned by texture | - | ||||||||||||
3726 | functions. It is also desirable to be able to control this reordering from CPU | - | ||||||||||||
3727 | side code. This is made possible by swizzle masks since OpenGL 3.3. | - | ||||||||||||
3728 | - | |||||||||||||
3729 | Each component of the texture can be mapped to one of the SwizzleValue options. | - | ||||||||||||
3730 | - | |||||||||||||
3731 | This function maps \a component to the output \a value. | - | ||||||||||||
3732 | - | |||||||||||||
3733 | \note This function has no effect on Mac and Qt built for OpenGL ES 2. | - | ||||||||||||
3734 | \sa swizzleMask() | - | ||||||||||||
3735 | */ | - | ||||||||||||
3736 | void QOpenGLTexture::setSwizzleMask(SwizzleComponent component, SwizzleValue value) | - | ||||||||||||
3737 | { | - | ||||||||||||
3738 | #if !defined(Q_OS_MAC) && !defined(QT_OPENGL_ES_2) | - | ||||||||||||
3739 | if (!QOpenGLContext::currentContext()->isOpenGLES()) { | - | ||||||||||||
3740 | Q_D(QOpenGLTexture); | - | ||||||||||||
3741 | d->create(); | - | ||||||||||||
3742 | Q_ASSERT(d->texFuncs); | - | ||||||||||||
3743 | Q_ASSERT(d->textureId); | - | ||||||||||||
3744 | if (!d->features.testFlag(Swizzle)) { | - | ||||||||||||
3745 | qWarning("QOpenGLTexture::setSwizzleMask() requires OpenGL >= 3.3"); | - | ||||||||||||
3746 | return; | - | ||||||||||||
3747 | } | - | ||||||||||||
3748 | d->swizzleMask[component - SwizzleRed] = value; | - | ||||||||||||
3749 | d->texFuncs->glTextureParameteri(d->textureId, d->target, d->bindingTarget, component, value); | - | ||||||||||||
3750 | return; | - | ||||||||||||
3751 | } | - | ||||||||||||
3752 | #else | - | ||||||||||||
3753 | Q_UNUSED(component); | - | ||||||||||||
3754 | Q_UNUSED(value); | - | ||||||||||||
3755 | #endif | - | ||||||||||||
3756 | qWarning("QOpenGLTexture: Texture swizzling is not supported"); | - | ||||||||||||
3757 | } | - | ||||||||||||
3758 | - | |||||||||||||
3759 | /*! | - | ||||||||||||
3760 | Parameters \a {r}, \a {g}, \a {b}, and \a {a} are values used for setting | - | ||||||||||||
3761 | the colors red, green, blue, and the alpha value. | - | ||||||||||||
3762 | \overload | - | ||||||||||||
3763 | */ | - | ||||||||||||
3764 | void QOpenGLTexture::setSwizzleMask(SwizzleValue r, SwizzleValue g, | - | ||||||||||||
3765 | SwizzleValue b, SwizzleValue a) | - | ||||||||||||
3766 | { | - | ||||||||||||
3767 | #if !defined(Q_OS_MAC) && !defined(QT_OPENGL_ES_2) | - | ||||||||||||
3768 | if (!QOpenGLContext::currentContext()->isOpenGLES()) { | - | ||||||||||||
3769 | Q_D(QOpenGLTexture); | - | ||||||||||||
3770 | d->create(); | - | ||||||||||||
3771 | Q_ASSERT(d->texFuncs); | - | ||||||||||||
3772 | Q_ASSERT(d->textureId); | - | ||||||||||||
3773 | if (!d->features.testFlag(Swizzle)) { | - | ||||||||||||
3774 | qWarning("QOpenGLTexture::setSwizzleMask() requires OpenGL >= 3.3"); | - | ||||||||||||
3775 | return; | - | ||||||||||||
3776 | } | - | ||||||||||||
3777 | GLint swizzleMask[] = {GLint(r), GLint(g), GLint(b), GLint(a)}; | - | ||||||||||||
3778 | d->swizzleMask[0] = r; | - | ||||||||||||
3779 | d->swizzleMask[1] = g; | - | ||||||||||||
3780 | d->swizzleMask[2] = b; | - | ||||||||||||
3781 | d->swizzleMask[3] = a; | - | ||||||||||||
3782 | d->texFuncs->glTextureParameteriv(d->textureId, d->target, d->bindingTarget, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask); | - | ||||||||||||
3783 | return; | - | ||||||||||||
3784 | } | - | ||||||||||||
3785 | #else | - | ||||||||||||
3786 | Q_UNUSED(r); | - | ||||||||||||
3787 | Q_UNUSED(g); | - | ||||||||||||
3788 | Q_UNUSED(b); | - | ||||||||||||
3789 | Q_UNUSED(a); | - | ||||||||||||
3790 | #endif | - | ||||||||||||
3791 | qWarning("QOpenGLTexture: Texture swizzling is not supported"); | - | ||||||||||||
3792 | } | - | ||||||||||||
3793 | - | |||||||||||||
3794 | /*! | - | ||||||||||||
3795 | Returns the swizzle mask for texture \a component. | - | ||||||||||||
3796 | */ | - | ||||||||||||
3797 | QOpenGLTexture::SwizzleValue QOpenGLTexture::swizzleMask(SwizzleComponent component) const | - | ||||||||||||
3798 | { | - | ||||||||||||
3799 | Q_D(const QOpenGLTexture); | - | ||||||||||||
3800 | return d->swizzleMask[component - SwizzleRed]; | - | ||||||||||||
3801 | } | - | ||||||||||||
3802 | - | |||||||||||||
3803 | /*! | - | ||||||||||||
3804 | \enum QOpenGLTexture::DepthStencilMode | - | ||||||||||||
3805 | \since 5.4 | - | ||||||||||||
3806 | This enum specifies which component of a depth/stencil texture is | - | ||||||||||||
3807 | accessed when the texture is sampled. | - | ||||||||||||
3808 | - | |||||||||||||
3809 | \value DepthMode Equivalent to GL_DEPTH_COMPONENT. | - | ||||||||||||
3810 | \value StencilMode Equivalent to GL_STENCIL_INDEX. | - | ||||||||||||
3811 | */ | - | ||||||||||||
3812 | - | |||||||||||||
3813 | /*! | - | ||||||||||||
3814 | If using a texture that has a combined depth/stencil format this function sets | - | ||||||||||||
3815 | which component of the texture is accessed to \a mode. | - | ||||||||||||
3816 | - | |||||||||||||
3817 | When the parameter is set to DepthMode, then accessing it from the | - | ||||||||||||
3818 | shader will access the depth component as a single float, as normal. But when | - | ||||||||||||
3819 | the parameter is set to StencilMode, the shader will access the stencil component. | - | ||||||||||||
3820 | - | |||||||||||||
3821 | \note This function has no effect on Mac and Qt built for OpenGL ES 2. | - | ||||||||||||
3822 | \since 5.4 | - | ||||||||||||
3823 | \sa depthStencilMode() | - | ||||||||||||
3824 | */ | - | ||||||||||||
3825 | void QOpenGLTexture::setDepthStencilMode(QOpenGLTexture::DepthStencilMode mode) | - | ||||||||||||
3826 | { | - | ||||||||||||
3827 | #if !defined(Q_OS_MAC) && !defined(QT_OPENGL_ES_2) | - | ||||||||||||
3828 | if (!QOpenGLContext::currentContext()->isOpenGLES()) { | - | ||||||||||||
3829 | Q_D(QOpenGLTexture); | - | ||||||||||||
3830 | d->create(); | - | ||||||||||||
3831 | Q_ASSERT(d->texFuncs); | - | ||||||||||||
3832 | Q_ASSERT(d->textureId); | - | ||||||||||||
3833 | if (!d->features.testFlag(StencilTexturing)) { | - | ||||||||||||
3834 | qWarning("QOpenGLTexture::setDepthStencilMode() requires OpenGL >= 4.3 or GL_ARB_stencil_texturing"); | - | ||||||||||||
3835 | return; | - | ||||||||||||
3836 | } | - | ||||||||||||
3837 | d->depthStencilMode = mode; | - | ||||||||||||
3838 | d->texFuncs->glTextureParameteri(d->textureId, d->target, d->bindingTarget, GL_DEPTH_STENCIL_TEXTURE_MODE, mode); | - | ||||||||||||
3839 | return; | - | ||||||||||||
3840 | } | - | ||||||||||||
3841 | #else | - | ||||||||||||
3842 | Q_UNUSED(mode); | - | ||||||||||||
3843 | #endif | - | ||||||||||||
3844 | qWarning("QOpenGLTexture: DepthStencil Mode is not supported"); | - | ||||||||||||
3845 | } | - | ||||||||||||
3846 | - | |||||||||||||
3847 | /*! | - | ||||||||||||
3848 | Returns the depth stencil mode for textures using a combined depth/stencil format. | - | ||||||||||||
3849 | - | |||||||||||||
3850 | \since 5.4 | - | ||||||||||||
3851 | \sa setDepthStencilMode() | - | ||||||||||||
3852 | */ | - | ||||||||||||
3853 | QOpenGLTexture::DepthStencilMode QOpenGLTexture::depthStencilMode() const | - | ||||||||||||
3854 | { | - | ||||||||||||
3855 | Q_D(const QOpenGLTexture); | - | ||||||||||||
3856 | return d->depthStencilMode; | - | ||||||||||||
3857 | } | - | ||||||||||||
3858 | - | |||||||||||||
3859 | /*! | - | ||||||||||||
3860 | \enum QOpenGLTexture::ComparisonFunction | - | ||||||||||||
3861 | \since 5.5 | - | ||||||||||||
3862 | This enum specifies which comparison operator is used when texture comparison | - | ||||||||||||
3863 | is enabled on this texture. | - | ||||||||||||
3864 | - | |||||||||||||
3865 | \value CompareLessEqual Equivalent to GL_LEQUAL. | - | ||||||||||||
3866 | \value CompareGreaterEqual Equivalent to GL_GEQUAL. | - | ||||||||||||
3867 | \value CompareLess Equivalent to GL_LESS. | - | ||||||||||||
3868 | \value CompareGreater Equivalent to GL_GREATER. | - | ||||||||||||
3869 | \value CompareEqual Equivalent to GL_EQUAL. | - | ||||||||||||
3870 | \value CommpareNotEqual Equivalent to GL_NOTEQUAL. | - | ||||||||||||
3871 | \value CompareAlways Equivalent to GL_ALWAYS. | - | ||||||||||||
3872 | \value CompareNever Equivalent to GL_NEVER. | - | ||||||||||||
3873 | - | |||||||||||||
3874 | */ | - | ||||||||||||
3875 | - | |||||||||||||
3876 | /* | - | ||||||||||||
3877 | \since 5.5 | - | ||||||||||||
3878 | - | |||||||||||||
3879 | Sets the texture comparison function on this texture to \a function. The texture | - | ||||||||||||
3880 | comparison function is used by shadow samplers when sampling a depth texture. | - | ||||||||||||
3881 | - | |||||||||||||
3882 | \sa comparisonFunction() | - | ||||||||||||
3883 | */ | - | ||||||||||||
3884 | void QOpenGLTexture::setComparisonFunction(QOpenGLTexture::ComparisonFunction function) | - | ||||||||||||
3885 | { | - | ||||||||||||
3886 | Q_D(QOpenGLTexture); | - | ||||||||||||
3887 | d->create(); | - | ||||||||||||
3888 | if (!d->features.testFlag(TextureComparisonOperators)) { | - | ||||||||||||
3889 | qWarning("QOpenGLTexture::setComparisonFunction: requires OpenGL >= 1.5 or OpenGL ES >= 3.0"); | - | ||||||||||||
3890 | return; | - | ||||||||||||
3891 | } | - | ||||||||||||
3892 | d->comparisonFunction = function; | - | ||||||||||||
3893 | d->texFuncs->glTextureParameteri(d->textureId, d->target, d->bindingTarget, GL_TEXTURE_COMPARE_FUNC, function); | - | ||||||||||||
3894 | } | - | ||||||||||||
3895 | - | |||||||||||||
3896 | /*! | - | ||||||||||||
3897 | \since 5.5 | - | ||||||||||||
3898 | - | |||||||||||||
3899 | Returns the texture comparison operator set on this texture. By default, a | - | ||||||||||||
3900 | texture has a CompareLessEqual comparison function. | - | ||||||||||||
3901 | - | |||||||||||||
3902 | \sa setComparisonFunction() | - | ||||||||||||
3903 | */ | - | ||||||||||||
3904 | QOpenGLTexture::ComparisonFunction QOpenGLTexture::comparisonFunction() const | - | ||||||||||||
3905 | { | - | ||||||||||||
3906 | Q_D(const QOpenGLTexture); | - | ||||||||||||
3907 | return d->comparisonFunction; | - | ||||||||||||
3908 | } | - | ||||||||||||
3909 | - | |||||||||||||
3910 | /*! | - | ||||||||||||
3911 | \enum QOpenGLTexture::ComparisonMode | - | ||||||||||||
3912 | \since 5.5 | - | ||||||||||||
3913 | This enum specifies which comparison mode is used when sampling this texture. | - | ||||||||||||
3914 | - | |||||||||||||
3915 | \value CompareRefToTexture Equivalent to GL_COMPARE_REF_TO_TEXTURE. | - | ||||||||||||
3916 | \value CompareNone Equivalent to GL_NONE. | - | ||||||||||||
3917 | */ | - | ||||||||||||
3918 | - | |||||||||||||
3919 | /*! | - | ||||||||||||
3920 | \since 5.5 | - | ||||||||||||
3921 | - | |||||||||||||
3922 | Sets the texture comparison mode on this texture to \a mode. The texture | - | ||||||||||||
3923 | comparison mode is used by shadow samplers when sampling a depth texture. | - | ||||||||||||
3924 | - | |||||||||||||
3925 | \sa comparisonMode() | - | ||||||||||||
3926 | */ | - | ||||||||||||
3927 | void QOpenGLTexture::setComparisonMode(QOpenGLTexture::ComparisonMode mode) | - | ||||||||||||
3928 | { | - | ||||||||||||
3929 | Q_D(QOpenGLTexture); | - | ||||||||||||
3930 | d->create(); | - | ||||||||||||
3931 | if (!d->features.testFlag(TextureComparisonOperators)) { | - | ||||||||||||
3932 | qWarning("QOpenGLTexture::setComparisonMode: requires OpenGL >= 1.5 or OpenGL ES >= 3.0"); | - | ||||||||||||
3933 | return; | - | ||||||||||||
3934 | } | - | ||||||||||||
3935 | d->comparisonMode = mode; | - | ||||||||||||
3936 | d->texFuncs->glTextureParameteri(d->textureId, d->target, d->bindingTarget, GL_TEXTURE_COMPARE_MODE, mode); | - | ||||||||||||
3937 | } | - | ||||||||||||
3938 | - | |||||||||||||
3939 | /*! | - | ||||||||||||
3940 | \since 5.5 | - | ||||||||||||
3941 | - | |||||||||||||
3942 | Returns the texture comparison mode set on this texture. By default, a | - | ||||||||||||
3943 | texture has a CompareNone comparison mode (i.e. comparisons are disabled). | - | ||||||||||||
3944 | - | |||||||||||||
3945 | \sa setComparisonMode() | - | ||||||||||||
3946 | */ | - | ||||||||||||
3947 | QOpenGLTexture::ComparisonMode QOpenGLTexture::comparisonMode() const | - | ||||||||||||
3948 | { | - | ||||||||||||
3949 | Q_D(const QOpenGLTexture); | - | ||||||||||||
3950 | return d->comparisonMode; | - | ||||||||||||
3951 | } | - | ||||||||||||
3952 | - | |||||||||||||
3953 | /*! | - | ||||||||||||
3954 | Sets the filter used for minification to \a filter. | - | ||||||||||||
3955 | - | |||||||||||||
3956 | \sa minificationFilter(), setMagnificationFilter(), setMinMagFilters() | - | ||||||||||||
3957 | */ | - | ||||||||||||
3958 | void QOpenGLTexture::setMinificationFilter(QOpenGLTexture::Filter filter) | - | ||||||||||||
3959 | { | - | ||||||||||||
3960 | Q_D(QOpenGLTexture); | - | ||||||||||||
3961 | d->create(); | - | ||||||||||||
3962 | Q_ASSERT(d->texFuncs); | - | ||||||||||||
3963 | Q_ASSERT(d->textureId); | - | ||||||||||||
3964 | d->minFilter = filter; | - | ||||||||||||
3965 | d->texFuncs->glTextureParameteri(d->textureId, d->target, d->bindingTarget, GL_TEXTURE_MIN_FILTER, filter); | - | ||||||||||||
3966 | } | - | ||||||||||||
3967 | - | |||||||||||||
3968 | /*! | - | ||||||||||||
3969 | Returns the minification filter. | - | ||||||||||||
3970 | - | |||||||||||||
3971 | \sa setMinificationFilter() | - | ||||||||||||
3972 | */ | - | ||||||||||||
3973 | QOpenGLTexture::Filter QOpenGLTexture::minificationFilter() const | - | ||||||||||||
3974 | { | - | ||||||||||||
3975 | Q_D(const QOpenGLTexture); | - | ||||||||||||
3976 | return d->minFilter; | - | ||||||||||||
3977 | } | - | ||||||||||||
3978 | - | |||||||||||||
3979 | /*! | - | ||||||||||||
3980 | Sets the magnification filter to \a filter. | - | ||||||||||||
3981 | - | |||||||||||||
3982 | \sa magnificationFilter(), setMinificationFilter(), setMinMagFilters() | - | ||||||||||||
3983 | */ | - | ||||||||||||
3984 | void QOpenGLTexture::setMagnificationFilter(QOpenGLTexture::Filter filter) | - | ||||||||||||
3985 | { | - | ||||||||||||
3986 | Q_D(QOpenGLTexture); | - | ||||||||||||
3987 | d->create(); | - | ||||||||||||
3988 | Q_ASSERT(d->texFuncs); | - | ||||||||||||
3989 | Q_ASSERT(d->textureId); | - | ||||||||||||
3990 | d->magFilter = filter; | - | ||||||||||||
3991 | d->texFuncs->glTextureParameteri(d->textureId, d->target, d->bindingTarget, GL_TEXTURE_MAG_FILTER, filter); | - | ||||||||||||
3992 | } | - | ||||||||||||
3993 | - | |||||||||||||
3994 | /*! | - | ||||||||||||
3995 | Returns the magnification filter. | - | ||||||||||||
3996 | - | |||||||||||||
3997 | \sa setMagnificationFilter() | - | ||||||||||||
3998 | */ | - | ||||||||||||
3999 | QOpenGLTexture::Filter QOpenGLTexture::magnificationFilter() const | - | ||||||||||||
4000 | { | - | ||||||||||||
4001 | Q_D(const QOpenGLTexture); | - | ||||||||||||
4002 | return d->magFilter; | - | ||||||||||||
4003 | } | - | ||||||||||||
4004 | - | |||||||||||||
4005 | /*! | - | ||||||||||||
4006 | Sets the minification filter to \a minificationFilter and the magnification filter | - | ||||||||||||
4007 | to \a magnificationFilter. | - | ||||||||||||
4008 | - | |||||||||||||
4009 | \sa minMagFilters(), setMinificationFilter(), setMagnificationFilter() | - | ||||||||||||
4010 | */ | - | ||||||||||||
4011 | void QOpenGLTexture::setMinMagFilters(QOpenGLTexture::Filter minificationFilter, | - | ||||||||||||
4012 | QOpenGLTexture::Filter magnificationFilter) | - | ||||||||||||
4013 | { | - | ||||||||||||
4014 | Q_D(QOpenGLTexture); | - | ||||||||||||
4015 | d->create(); | - | ||||||||||||
4016 | Q_ASSERT(d->texFuncs); | - | ||||||||||||
4017 | Q_ASSERT(d->textureId); | - | ||||||||||||
4018 | d->minFilter = minificationFilter; | - | ||||||||||||
4019 | d->magFilter = magnificationFilter; | - | ||||||||||||
4020 | d->texFuncs->glTextureParameteri(d->textureId, d->target, d->bindingTarget, GL_TEXTURE_MIN_FILTER, minificationFilter); | - | ||||||||||||
4021 | d->texFuncs->glTextureParameteri(d->textureId, d->target, d->bindingTarget, GL_TEXTURE_MAG_FILTER, magnificationFilter); | - | ||||||||||||
4022 | } | - | ||||||||||||
4023 | - | |||||||||||||
4024 | /*! | - | ||||||||||||
4025 | Returns the current minification and magnification filters. | - | ||||||||||||
4026 | - | |||||||||||||
4027 | \sa setMinMagFilters() | - | ||||||||||||
4028 | */ | - | ||||||||||||
4029 | QPair<QOpenGLTexture::Filter, QOpenGLTexture::Filter> QOpenGLTexture::minMagFilters() const | - | ||||||||||||
4030 | { | - | ||||||||||||
4031 | Q_D(const QOpenGLTexture); | - | ||||||||||||
4032 | return QPair<QOpenGLTexture::Filter, QOpenGLTexture::Filter>(d->minFilter, d->magFilter); | - | ||||||||||||
4033 | } | - | ||||||||||||
4034 | - | |||||||||||||
4035 | /*! | - | ||||||||||||
4036 | If your OpenGL implementation supports the GL_EXT_texture_filter_anisotropic extension | - | ||||||||||||
4037 | this function sets the maximum anisotropy level to \a anisotropy. | - | ||||||||||||
4038 | - | |||||||||||||
4039 | \sa maximumAnisotropy() | - | ||||||||||||
4040 | */ | - | ||||||||||||
4041 | void QOpenGLTexture::setMaximumAnisotropy(float anisotropy) | - | ||||||||||||
4042 | { | - | ||||||||||||
4043 | Q_D(QOpenGLTexture); | - | ||||||||||||
4044 | d->create(); | - | ||||||||||||
4045 | Q_ASSERT(d->texFuncs); | - | ||||||||||||
4046 | Q_ASSERT(d->textureId); | - | ||||||||||||
4047 | if (!d->features.testFlag(AnisotropicFiltering)) { | - | ||||||||||||
4048 | qWarning("QOpenGLTexture::setMaximumAnisotropy() requires GL_EXT_texture_filter_anisotropic"); | - | ||||||||||||
4049 | return; | - | ||||||||||||
4050 | } | - | ||||||||||||
4051 | d->maxAnisotropy = anisotropy; | - | ||||||||||||
4052 | d->texFuncs->glTextureParameteri(d->textureId, d->target, d->bindingTarget, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy); | - | ||||||||||||
4053 | } | - | ||||||||||||
4054 | - | |||||||||||||
4055 | /*! | - | ||||||||||||
4056 | Returns the maximum level of anisotropy to be accounted for when performing texture lookups. | - | ||||||||||||
4057 | This requires the GL_EXT_texture_filter_anisotropic extension. | - | ||||||||||||
4058 | - | |||||||||||||
4059 | \sa setMaximumAnisotropy() | - | ||||||||||||
4060 | */ | - | ||||||||||||
4061 | float QOpenGLTexture::maximumAnisotropy() const | - | ||||||||||||
4062 | { | - | ||||||||||||
4063 | Q_D(const QOpenGLTexture); | - | ||||||||||||
4064 | return d->maxAnisotropy; | - | ||||||||||||
4065 | } | - | ||||||||||||
4066 | - | |||||||||||||
4067 | /*! | - | ||||||||||||
4068 | Sets the wrap (or repeat mode) for all texture dimentions to \a mode. | - | ||||||||||||
4069 | - | |||||||||||||
4070 | \sa wrapMode() | - | ||||||||||||
4071 | */ | - | ||||||||||||
4072 | void QOpenGLTexture::setWrapMode(QOpenGLTexture::WrapMode mode) | - | ||||||||||||
4073 | { | - | ||||||||||||
4074 | Q_D(QOpenGLTexture); | - | ||||||||||||
4075 | d->create(); | - | ||||||||||||
4076 | Q_ASSERT(d->texFuncs); | - | ||||||||||||
4077 | Q_ASSERT(d->textureId); | - | ||||||||||||
4078 | d->setWrapMode(mode); | - | ||||||||||||
4079 | } | - | ||||||||||||
4080 | - | |||||||||||||
4081 | /*! | - | ||||||||||||
4082 | Holds the texture dimension \a direction. | - | ||||||||||||
4083 | \overload | - | ||||||||||||
4084 | */ | - | ||||||||||||
4085 | void QOpenGLTexture::setWrapMode(QOpenGLTexture::CoordinateDirection direction, QOpenGLTexture::WrapMode mode) | - | ||||||||||||
4086 | { | - | ||||||||||||
4087 | Q_D(QOpenGLTexture); | - | ||||||||||||
4088 | d->create(); | - | ||||||||||||
4089 | Q_ASSERT(d->texFuncs); | - | ||||||||||||
4090 | Q_ASSERT(d->textureId); | - | ||||||||||||
4091 | d->setWrapMode(direction, mode); | - | ||||||||||||
4092 | } | - | ||||||||||||
4093 | - | |||||||||||||
4094 | /*! | - | ||||||||||||
4095 | Returns the wrap mode for the texture dimension \a direction. | - | ||||||||||||
4096 | - | |||||||||||||
4097 | \sa setWrapMode() | - | ||||||||||||
4098 | */ | - | ||||||||||||
4099 | QOpenGLTexture::WrapMode QOpenGLTexture::wrapMode(QOpenGLTexture::CoordinateDirection direction) const | - | ||||||||||||
4100 | { | - | ||||||||||||
4101 | Q_D(const QOpenGLTexture); | - | ||||||||||||
4102 | return d->wrapMode(direction); | - | ||||||||||||
4103 | } | - | ||||||||||||
4104 | - | |||||||||||||
4105 | /*! | - | ||||||||||||
4106 | Sets the border color of the texture to \a color. | - | ||||||||||||
4107 | - | |||||||||||||
4108 | \note This function has no effect on Mac and Qt built for OpenGL ES 2. | - | ||||||||||||
4109 | \sa borderColor() | - | ||||||||||||
4110 | */ | - | ||||||||||||
4111 | void QOpenGLTexture::setBorderColor(QColor color) | - | ||||||||||||
{ | ||||||||||||||
#if !defined(QT_OPENGL_ES_2) | ||||||||||||||
if (!QOpenGLContext::currentContext()->isOpenGLES()){ | ||||||||||||||
4113 | Q_D(QOpenGLTexture); | - | ||||||||||||
d->create(); | ||||||||||||||
Q_ASSERT(d->texFuncs); | ||||||||||||||
Q_ASSERTsetBorderColor(d->textureId);static_cast<floatvalues[4]; | ||||||||||||||
values[0] =>(color.redF(); | ||||||||||||||
values[1] =()), static_cast<float>(color.greenF(); | ||||||||||||||
values[2] =()), | ||||||||||||||
4114 | static_cast<float>(color.blueF(); | - | ||||||||||||
values[3] =()), static_cast<float>(color.alphaF(); | ||||||||||||||
d->borderColor.clear(); | ||||||||||||||
for (int i = 0; i < 4; ++i) | ||||||||||||||
d->borderColor.append(QVariant(values[i])); | ||||||||||||||
d->texFuncs->glTextureParameterfv(d->textureId, d->target, d->bindingTarget, GL_TEXTURE_BORDER_COLOR, values); | ||||||||||||||
return; | ||||||||||||||
} | ||||||||||||||
#else | ||||||||||||||
Q_UNUSED(color); | ||||||||||||||
#endif | ||||||||||||||
qWarning("QOpenGLTexture: Border color is not supported");())); | ||||||||||||||
4115 | } never executed: end of block | 0 | ||||||||||||
4116 | - | |||||||||||||
4117 | /*! | - | ||||||||||||
4118 | Sets the color red to \a {r}, green to \a {g}, blue to \a {b}, and \a {a} to the | - | ||||||||||||
4119 | alpha value. | - | ||||||||||||
4120 | \overload | - | ||||||||||||
4121 | */ | - | ||||||||||||
4122 | void QOpenGLTexture::setBorderColor(float r, float g, float b, float a) | - | ||||||||||||
4123 | { | - | ||||||||||||
4124 | #if !defined(QT_OPENGL_ES_2) | - | ||||||||||||
4125 | if (!QOpenGLContext::currentContext()->isOpenGLES()) { | - | ||||||||||||
4126 | Q_D(QOpenGLTexture); | - | ||||||||||||
4127 | d->create(); | - | ||||||||||||
4128 | Q_ASSERT(d->texFuncs); | - | ||||||||||||
4129 | Q_ASSERT(d->textureId); | - | ||||||||||||
4130 | float values[4]; | - | ||||||||||||
4131 | values[0] = r; | - | ||||||||||||
4132 | values[1] = g; | - | ||||||||||||
4133 | values[2] = b; | - | ||||||||||||
4134 | values[3] = a; | - | ||||||||||||
4135 | d->borderColor.clear(); | - | ||||||||||||
4136 | for (int i = 0; i < 4; ++i) | - | ||||||||||||
4137 | d->borderColor.append(QVariant(values[i])); | - | ||||||||||||
4138 | d->texFuncs->glTextureParameterfv(d->textureId, d->target, d->bindingTarget, GL_TEXTURE_BORDER_COLOR, values); | - | ||||||||||||
4139 | return; | - | ||||||||||||
4140 | } | - | ||||||||||||
4141 | #else | - | ||||||||||||
4142 | Q_UNUSED(r); | - | ||||||||||||
4143 | Q_UNUSED(g); | - | ||||||||||||
4144 | Q_UNUSED(b); | - | ||||||||||||
4145 | Q_UNUSED(a); | - | ||||||||||||
4146 | #endif | - | ||||||||||||
4147 | qWarning("QOpenGLTexture: Border color is not supported"); | - | ||||||||||||
4148 | } | - | ||||||||||||
4149 | - | |||||||||||||
4150 | /*! | - | ||||||||||||
4151 | Sets the color red to \a {r}, green to \a {g}, blue to \a {b}, and the alpha | - | ||||||||||||
4152 | value to \a {a}. | - | ||||||||||||
4153 | \overload | - | ||||||||||||
4154 | */ | - | ||||||||||||
4155 | void QOpenGLTexture::setBorderColor(int r, int g, int b, int a) | - | ||||||||||||
4156 | { | - | ||||||||||||
4157 | #if !defined(QT_OPENGL_ES_2) | - | ||||||||||||
4158 | if (!QOpenGLContext::currentContext()->isOpenGLES()) { | - | ||||||||||||
4159 | Q_D(QOpenGLTexture); | - | ||||||||||||
4160 | d->create(); | - | ||||||||||||
4161 | Q_ASSERT(d->texFuncs); | - | ||||||||||||
4162 | Q_ASSERT(d->textureId); | - | ||||||||||||
4163 | int values[4]; | - | ||||||||||||
4164 | values[0] = r; | - | ||||||||||||
4165 | values[1] = g; | - | ||||||||||||
4166 | values[2] = b; | - | ||||||||||||
4167 | values[3] = a; | - | ||||||||||||
4168 | d->borderColor.clear(); | - | ||||||||||||
4169 | for (int i = 0; i < 4; ++i) | - | ||||||||||||
4170 | d->borderColor.append(QVariant(values[i])); | - | ||||||||||||
4171 | d->texFuncs->glTextureParameteriv(d->textureId, d->target, d->bindingTarget, GL_TEXTURE_BORDER_COLOR, values); | - | ||||||||||||
4172 | return; | - | ||||||||||||
4173 | } | - | ||||||||||||
4174 | #else | - | ||||||||||||
4175 | Q_UNUSED(r); | - | ||||||||||||
4176 | Q_UNUSED(g); | - | ||||||||||||
4177 | Q_UNUSED(b); | - | ||||||||||||
4178 | Q_UNUSED(a); | - | ||||||||||||
4179 | #endif | - | ||||||||||||
4180 | qWarning("QOpenGLTexture: Border color is not supported"); | - | ||||||||||||
4181 | - | |||||||||||||
4182 | // TODO Handle case of using glTextureParameterIiv() based on format | - | ||||||||||||
4183 | } | - | ||||||||||||
4184 | - | |||||||||||||
4185 | /*! | - | ||||||||||||
4186 | Sets the color red to \a {r}, green to \a {g}, blue to \a {b}, and the alpha | - | ||||||||||||
4187 | value to \a {a}. | - | ||||||||||||
4188 | \overload | - | ||||||||||||
4189 | */ | - | ||||||||||||
4190 | void QOpenGLTexture::setBorderColor(uint r, uint g, uint b, uint a) | - | ||||||||||||
4191 | { | - | ||||||||||||
4192 | #if !defined(QT_OPENGL_ES_2) | - | ||||||||||||
4193 | if (!QOpenGLContext::currentContext()->isOpenGLES()) { | - | ||||||||||||
4194 | Q_D(QOpenGLTexture); | - | ||||||||||||
4195 | d->create(); | - | ||||||||||||
4196 | Q_ASSERT(d->texFuncs); | - | ||||||||||||
4197 | Q_ASSERT(d->textureId); | - | ||||||||||||
4198 | int values[4]; | - | ||||||||||||
4199 | values[0] = int(r); | - | ||||||||||||
4200 | values[1] = int(g); | - | ||||||||||||
4201 | values[2] = int(b); | - | ||||||||||||
4202 | values[3] = int(a); | - | ||||||||||||
4203 | d->borderColor.clear(); | - | ||||||||||||
4204 | for (int i = 0; i < 4; ++i) | - | ||||||||||||
4205 | d->borderColor.append(QVariant(values[i])); | - | ||||||||||||
4206 | d->texFuncs->glTextureParameteriv(d->textureId, d->target, d->bindingTarget, GL_TEXTURE_BORDER_COLOR, values); | - | ||||||||||||
4207 | return; | - | ||||||||||||
4208 | } | - | ||||||||||||
4209 | #else | - | ||||||||||||
4210 | Q_UNUSED(r); | - | ||||||||||||
4211 | Q_UNUSED(g); | - | ||||||||||||
4212 | Q_UNUSED(b); | - | ||||||||||||
4213 | Q_UNUSED(a); | - | ||||||||||||
4214 | #endif | - | ||||||||||||
4215 | qWarning("QOpenGLTexture: Border color is not supported"); | - | ||||||||||||
4216 | - | |||||||||||||
4217 | // TODO Handle case of using glTextureParameterIuiv() based on format | - | ||||||||||||
4218 | } | - | ||||||||||||
4219 | - | |||||||||||||
4220 | /*! | - | ||||||||||||
4221 | Returns the borderColor of this texture. | - | ||||||||||||
4222 | - | |||||||||||||
4223 | \sa setBorderColor() | - | ||||||||||||
4224 | */ | - | ||||||||||||
4225 | QColor QOpenGLTexture::borderColor() const | - | ||||||||||||
4226 | { | - | ||||||||||||
4227 | Q_D(const QOpenGLTexture); | - | ||||||||||||
4228 | QColor c(0.0f, 0.0f, 0.0f, 0.0f); | - | ||||||||||||
4229 | if (!d->borderColor.isEmpty()) { | - | ||||||||||||
4230 | c.setRedF(d->borderColor.at(0).toFloat()); | - | ||||||||||||
4231 | c.setGreenF(d->borderColor.at(1).toFloat()); | - | ||||||||||||
4232 | c.setBlueF(d->borderColor.at(2).toFloat()); | - | ||||||||||||
4233 | c.setAlphaF(d->borderColor.at(3).toFloat()); | - | ||||||||||||
4234 | } | - | ||||||||||||
4235 | return c; | - | ||||||||||||
4236 | } | - | ||||||||||||
4237 | - | |||||||||||||
4238 | /*! | - | ||||||||||||
4239 | Writes the texture border color into the first four elements | - | ||||||||||||
4240 | of the array pointed to by \a border. | - | ||||||||||||
4241 | - | |||||||||||||
4242 | \sa setBorderColor() | - | ||||||||||||
4243 | */ | - | ||||||||||||
4244 | void QOpenGLTexture::borderColor(float *border) const | - | ||||||||||||
4245 | { | - | ||||||||||||
4246 | Q_D(const QOpenGLTexture); | - | ||||||||||||
4247 | Q_ASSERT(border); | - | ||||||||||||
4248 | if (d->borderColor.isEmpty()) { | - | ||||||||||||
4249 | for (int i = 0; i < 4; ++i) | - | ||||||||||||
4250 | border[i] = 0.0f; | - | ||||||||||||
4251 | } else { | - | ||||||||||||
4252 | for (int i = 0; i < 4; ++i) | - | ||||||||||||
4253 | border[i] = d->borderColor.at(i).toFloat(); | - | ||||||||||||
4254 | } | - | ||||||||||||
4255 | } | - | ||||||||||||
4256 | - | |||||||||||||
4257 | /*! | - | ||||||||||||
4258 | Writes the texture border color into the first four elements | - | ||||||||||||
4259 | of the array pointed to by \a border. | - | ||||||||||||
4260 | - | |||||||||||||
4261 | \overload | - | ||||||||||||
4262 | */ | - | ||||||||||||
4263 | void QOpenGLTexture::borderColor(int *border) const | - | ||||||||||||
4264 | { | - | ||||||||||||
4265 | Q_D(const QOpenGLTexture); | - | ||||||||||||
4266 | Q_ASSERT(border); | - | ||||||||||||
4267 | if (d->borderColor.isEmpty()) { | - | ||||||||||||
4268 | for (int i = 0; i < 4; ++i) | - | ||||||||||||
4269 | border[i] = 0; | - | ||||||||||||
4270 | } else { | - | ||||||||||||
4271 | for (int i = 0; i < 4; ++i) | - | ||||||||||||
4272 | border[i] = d->borderColor.at(i).toInt(); | - | ||||||||||||
4273 | } | - | ||||||||||||
4274 | } | - | ||||||||||||
4275 | - | |||||||||||||
4276 | /*! | - | ||||||||||||
4277 | Writes the texture border color into the first four elements | - | ||||||||||||
4278 | of the array pointed to by \a border. | - | ||||||||||||
4279 | - | |||||||||||||
4280 | \overload | - | ||||||||||||
4281 | */ | - | ||||||||||||
4282 | void QOpenGLTexture::borderColor(unsigned int *border) const | - | ||||||||||||
4283 | { | - | ||||||||||||
4284 | Q_D(const QOpenGLTexture); | - | ||||||||||||
4285 | Q_ASSERT(border); | - | ||||||||||||
4286 | if (d->borderColor.isEmpty()) { | - | ||||||||||||
4287 | for (int i = 0; i < 4; ++i) | - | ||||||||||||
4288 | border[i] = 0; | - | ||||||||||||
4289 | } else { | - | ||||||||||||
4290 | for (int i = 0; i < 4; ++i) | - | ||||||||||||
4291 | border[i] = d->borderColor.at(i).toUInt(); | - | ||||||||||||
4292 | } | - | ||||||||||||
4293 | } | - | ||||||||||||
4294 | - | |||||||||||||
4295 | /*! | - | ||||||||||||
4296 | Sets the minimum level of detail to \a value. This limits the selection of highest | - | ||||||||||||
4297 | resolution mipmap (lowest mipmap level). The default value is -1000. | - | ||||||||||||
4298 | - | |||||||||||||
4299 | \note This function has no effect on Qt built for OpenGL ES 2. | - | ||||||||||||
4300 | \sa minimumLevelOfDetail(), setMaximumLevelOfDetail(), setLevelOfDetailRange() | - | ||||||||||||
4301 | */ | - | ||||||||||||
4302 | void QOpenGLTexture::setMinimumLevelOfDetail(float value) | - | ||||||||||||
4303 | { | - | ||||||||||||
4304 | #if !defined(QT_OPENGL_ES_2) | - | ||||||||||||
4305 | if (!QOpenGLContext::currentContext()->isOpenGLES()) { | - | ||||||||||||
4306 | Q_D(QOpenGLTexture); | - | ||||||||||||
4307 | d->create(); | - | ||||||||||||
4308 | Q_ASSERT(d->texFuncs); | - | ||||||||||||
4309 | Q_ASSERT(d->textureId); | - | ||||||||||||
4310 | Q_ASSERT(value < d->maxLevelOfDetail); | - | ||||||||||||
4311 | d->minLevelOfDetail = value; | - | ||||||||||||
4312 | d->texFuncs->glTextureParameterf(d->textureId, d->target, d->bindingTarget, GL_TEXTURE_MIN_LOD, value); | - | ||||||||||||
4313 | return; | - | ||||||||||||
4314 | } | - | ||||||||||||
4315 | #else | - | ||||||||||||
4316 | Q_UNUSED(value); | - | ||||||||||||
4317 | #endif | - | ||||||||||||
4318 | qWarning("QOpenGLTexture: Detail level is not supported"); | - | ||||||||||||
4319 | } | - | ||||||||||||
4320 | - | |||||||||||||
4321 | /*! | - | ||||||||||||
4322 | Returns the minimum level of detail parameter. | - | ||||||||||||
4323 | - | |||||||||||||
4324 | \sa setMinimumLevelOfDetail(), maximumLevelOfDetail(), levelOfDetailRange() | - | ||||||||||||
4325 | */ | - | ||||||||||||
4326 | float QOpenGLTexture::minimumLevelOfDetail() const | - | ||||||||||||
4327 | { | - | ||||||||||||
4328 | Q_D(const QOpenGLTexture); | - | ||||||||||||
4329 | return d->minLevelOfDetail; | - | ||||||||||||
4330 | } | - | ||||||||||||
4331 | - | |||||||||||||
4332 | /*! | - | ||||||||||||
4333 | Sets the maximum level of detail to \a value. This limits the selection of lowest | - | ||||||||||||
4334 | resolution mipmap (highest mipmap level). The default value is 1000. | - | ||||||||||||
4335 | - | |||||||||||||
4336 | \note This function has no effect on Qt built for OpenGL ES 2. | - | ||||||||||||
4337 | \sa maximumLevelOfDetail(), setMinimumLevelOfDetail(), setLevelOfDetailRange() | - | ||||||||||||
4338 | */ | - | ||||||||||||
4339 | void QOpenGLTexture::setMaximumLevelOfDetail(float value) | - | ||||||||||||
4340 | { | - | ||||||||||||
4341 | #if !defined(QT_OPENGL_ES_2) | - | ||||||||||||
4342 | if (!QOpenGLContext::currentContext()->isOpenGLES()) { | - | ||||||||||||
4343 | Q_D(QOpenGLTexture); | - | ||||||||||||
4344 | d->create(); | - | ||||||||||||
4345 | Q_ASSERT(d->texFuncs); | - | ||||||||||||
4346 | Q_ASSERT(d->textureId); | - | ||||||||||||
4347 | Q_ASSERT(value > d->minLevelOfDetail); | - | ||||||||||||
4348 | d->maxLevelOfDetail = value; | - | ||||||||||||
4349 | d->texFuncs->glTextureParameterf(d->textureId, d->target, d->bindingTarget, GL_TEXTURE_MAX_LOD, value); | - | ||||||||||||
4350 | return; | - | ||||||||||||
4351 | } | - | ||||||||||||
4352 | #else | - | ||||||||||||
4353 | Q_UNUSED(value); | - | ||||||||||||
4354 | #endif | - | ||||||||||||
4355 | qWarning("QOpenGLTexture: Detail level is not supported"); | - | ||||||||||||
4356 | } | - | ||||||||||||
4357 | - | |||||||||||||
4358 | /*! | - | ||||||||||||
4359 | Returns the maximum level of detail parameter. | - | ||||||||||||
4360 | - | |||||||||||||
4361 | \sa setMaximumLevelOfDetail(), minimumLevelOfDetail(), levelOfDetailRange() | - | ||||||||||||
4362 | */ | - | ||||||||||||
4363 | float QOpenGLTexture::maximumLevelOfDetail() const | - | ||||||||||||
4364 | { | - | ||||||||||||
4365 | Q_D(const QOpenGLTexture); | - | ||||||||||||
4366 | return d->maxLevelOfDetail; | - | ||||||||||||
4367 | } | - | ||||||||||||
4368 | - | |||||||||||||
4369 | /*! | - | ||||||||||||
4370 | Sets the minimum level of detail parameters to \a min and the maximum level | - | ||||||||||||
4371 | to \a max. | - | ||||||||||||
4372 | \note This function has no effect on Qt built for OpenGL ES 2. | - | ||||||||||||
4373 | \sa levelOfDetailRange(), setMinimumLevelOfDetail(), setMaximumLevelOfDetail() | - | ||||||||||||
4374 | */ | - | ||||||||||||
4375 | void QOpenGLTexture::setLevelOfDetailRange(float min, float max) | - | ||||||||||||
4376 | { | - | ||||||||||||
4377 | #if !defined(QT_OPENGL_ES_2) | - | ||||||||||||
4378 | if (!QOpenGLContext::currentContext()->isOpenGLES()) { | - | ||||||||||||
4379 | Q_D(QOpenGLTexture); | - | ||||||||||||
4380 | d->create(); | - | ||||||||||||
4381 | Q_ASSERT(d->texFuncs); | - | ||||||||||||
4382 | Q_ASSERT(d->textureId); | - | ||||||||||||
4383 | Q_ASSERT(min < max); | - | ||||||||||||
4384 | d->minLevelOfDetail = min; | - | ||||||||||||
4385 | d->maxLevelOfDetail = max; | - | ||||||||||||
4386 | d->texFuncs->glTextureParameterf(d->textureId, d->target, d->bindingTarget, GL_TEXTURE_MIN_LOD, min); | - | ||||||||||||
4387 | d->texFuncs->glTextureParameterf(d->textureId, d->target, d->bindingTarget, GL_TEXTURE_MAX_LOD, max); | - | ||||||||||||
4388 | return; | - | ||||||||||||
4389 | } | - | ||||||||||||
4390 | #else | - | ||||||||||||
4391 | Q_UNUSED(min); | - | ||||||||||||
4392 | Q_UNUSED(max); | - | ||||||||||||
4393 | #endif | - | ||||||||||||
4394 | qWarning("QOpenGLTexture: Detail level is not supported"); | - | ||||||||||||
4395 | } | - | ||||||||||||
4396 | - | |||||||||||||
4397 | /*! | - | ||||||||||||
4398 | Returns the minimum and maximum level of detail parameters. | - | ||||||||||||
4399 | - | |||||||||||||
4400 | \sa setLevelOfDetailRange(), minimumLevelOfDetail(), maximumLevelOfDetail() | - | ||||||||||||
4401 | */ | - | ||||||||||||
4402 | QPair<float, float> QOpenGLTexture::levelOfDetailRange() const | - | ||||||||||||
4403 | { | - | ||||||||||||
4404 | Q_D(const QOpenGLTexture); | - | ||||||||||||
4405 | return qMakePair(d->minLevelOfDetail, d->maxLevelOfDetail); | - | ||||||||||||
4406 | } | - | ||||||||||||
4407 | - | |||||||||||||
4408 | /*! | - | ||||||||||||
4409 | Sets the level of detail bias to \a bias. | - | ||||||||||||
4410 | Level of detail bias affects the point at which mipmapping levels change. | - | ||||||||||||
4411 | Increasing values for level of detail bias makes the overall images blurrier | - | ||||||||||||
4412 | or smoother. Decreasing values make the overall images sharper. | - | ||||||||||||
4413 | - | |||||||||||||
4414 | \note This function has no effect on Qt built for OpenGL ES 2. | - | ||||||||||||
4415 | \sa levelofDetailBias() | - | ||||||||||||
4416 | */ | - | ||||||||||||
4417 | void QOpenGLTexture::setLevelofDetailBias(float bias) | - | ||||||||||||
4418 | { | - | ||||||||||||
4419 | #if !defined(QT_OPENGL_ES_2) | - | ||||||||||||
4420 | if (!QOpenGLContext::currentContext()->isOpenGLES()) { | - | ||||||||||||
4421 | Q_D(QOpenGLTexture); | - | ||||||||||||
4422 | d->create(); | - | ||||||||||||
4423 | Q_ASSERT(d->texFuncs); | - | ||||||||||||
4424 | Q_ASSERT(d->textureId); | - | ||||||||||||
4425 | d->levelOfDetailBias = bias; | - | ||||||||||||
4426 | d->texFuncs->glTextureParameterf(d->textureId, d->target, d->bindingTarget, GL_TEXTURE_LOD_BIAS, bias); | - | ||||||||||||
4427 | return; | - | ||||||||||||
4428 | } | - | ||||||||||||
4429 | #else | - | ||||||||||||
4430 | Q_UNUSED(bias); | - | ||||||||||||
4431 | #endif | - | ||||||||||||
4432 | qWarning("QOpenGLTexture: Detail level is not supported"); | - | ||||||||||||
4433 | } | - | ||||||||||||
4434 | - | |||||||||||||
4435 | /*! | - | ||||||||||||
4436 | Returns the level of detail bias parameter. | - | ||||||||||||
4437 | - | |||||||||||||
4438 | \sa setLevelofDetailBias() | - | ||||||||||||
4439 | */ | - | ||||||||||||
4440 | float QOpenGLTexture::levelofDetailBias() const | - | ||||||||||||
4441 | { | - | ||||||||||||
4442 | Q_D(const QOpenGLTexture); | - | ||||||||||||
4443 | return d->levelOfDetailBias; | - | ||||||||||||
4444 | } | - | ||||||||||||
4445 | - | |||||||||||||
4446 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |