1/****************************************************************************
2**
3** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB).
4** Copyright (C) 2020 The Qt Company Ltd.
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#include "qopengltexture.h"
42#include "qopengltexture_p.h"
43#include "qopengltexturehelper_p.h"
44#include "qopenglfunctions.h"
45#include <QtGui/qcolor.h>
46#include <QtGui/qopenglcontext.h>
47#include <QtCore/qdebug.h>
48#include <private/qobject_p.h>
49#include <private/qopenglcontext_p.h>
50
51QT_BEGIN_NAMESPACE
52
53//this is to work around GL_TEXTURE_WRAP_R_OES which also has 0x8072 as value
54#if !defined(GL_TEXTURE_WRAP_R)
55 #define GL_TEXTURE_WRAP_R 0x8072
56#endif
57
58QOpenGLTexturePrivate::QOpenGLTexturePrivate(QOpenGLTexture::Target textureTarget,
59 QOpenGLTexture *qq)
60 : q_ptr(qq),
61 context(nullptr),
62 target(textureTarget),
63 textureId(0),
64 format(QOpenGLTexture::NoFormat),
65 formatClass(QOpenGLTexture::NoFormatClass),
66 requestedMipLevels(1),
67 mipLevels(-1),
68 layers(1),
69 faces(1),
70 samples(0),
71 fixedSamplePositions(true),
72 baseLevel(0),
73 maxLevel(1000),
74 depthStencilMode(QOpenGLTexture::DepthMode),
75 comparisonFunction(QOpenGLTexture::CompareLessEqual),
76 comparisonMode(QOpenGLTexture::CompareNone),
77 minFilter(QOpenGLTexture::Nearest),
78 magFilter(QOpenGLTexture::Nearest),
79 maxAnisotropy(1.0f),
80 minLevelOfDetail(-1000.0f),
81 maxLevelOfDetail(1000.0f),
82 levelOfDetailBias(0.0f),
83 textureView(false),
84 autoGenerateMipMaps(true),
85 storageAllocated(false),
86 texFuncs(nullptr),
87 functions(nullptr)
88{
89 dimensions[0] = dimensions[1] = dimensions[2] = 1;
90
91 switch (target) {
92 case QOpenGLTexture::Target1D:
93 bindingTarget = QOpenGLTexture::BindingTarget1D;
94 break;
95 case QOpenGLTexture::Target1DArray:
96 bindingTarget = QOpenGLTexture::BindingTarget1DArray;
97 break;
98 case QOpenGLTexture::Target2D:
99 bindingTarget = QOpenGLTexture::BindingTarget2D;
100 break;
101 case QOpenGLTexture::Target2DArray:
102 bindingTarget = QOpenGLTexture::BindingTarget2DArray;
103 break;
104 case QOpenGLTexture::Target3D:
105 bindingTarget = QOpenGLTexture::BindingTarget3D;
106 break;
107 case QOpenGLTexture::TargetCubeMap:
108 bindingTarget = QOpenGLTexture::BindingTargetCubeMap;
109 faces = 6;
110 break;
111 case QOpenGLTexture::TargetCubeMapArray:
112 bindingTarget = QOpenGLTexture::BindingTargetCubeMapArray;
113 faces = 6;
114 break;
115 case QOpenGLTexture::Target2DMultisample:
116 bindingTarget = QOpenGLTexture::BindingTarget2DMultisample;
117 break;
118 case QOpenGLTexture::Target2DMultisampleArray:
119 bindingTarget = QOpenGLTexture::BindingTarget2DMultisampleArray;
120 break;
121 case QOpenGLTexture::TargetRectangle:
122 bindingTarget = QOpenGLTexture::BindingTargetRectangle;
123 break;
124 case QOpenGLTexture::TargetBuffer:
125 bindingTarget = QOpenGLTexture::BindingTargetBuffer;
126 break;
127 }
128
129 swizzleMask[0] = QOpenGLTexture::RedValue;
130 swizzleMask[1] = QOpenGLTexture::GreenValue;
131 swizzleMask[2] = QOpenGLTexture::BlueValue;
132 swizzleMask[3] = QOpenGLTexture::AlphaValue;
133
134 wrapModes[0] = wrapModes[1] = wrapModes[2] = target == QOpenGLTexture::TargetRectangle
135 ? QOpenGLTexture::ClampToEdge : QOpenGLTexture::Repeat;
136}
137
138QOpenGLTexturePrivate::~QOpenGLTexturePrivate()
139{
140 destroy();
141}
142
143void QOpenGLTexturePrivate::initializeOpenGLFunctions()
144{
145 // If we already have a functions object, there is nothing to do
146 if (texFuncs)
147 return;
148
149 // See if the context already has a suitable resource we can use.
150 // If not create a functions object and add it to the context in case
151 // others wish to use it too
152 texFuncs = context->textureFunctions();
153 if (!texFuncs) {
154 texFuncs = new QOpenGLTextureHelper(context);
155 auto *funcs = texFuncs; // lets us capture by pointer value below
156 context->setTextureFunctions(funcs, [funcs] { delete funcs; });
157 }
158}
159
160bool QOpenGLTexturePrivate::create()
161{
162 if (textureId != 0)
163 return true;
164
165 QOpenGLContext *ctx = QOpenGLContext::currentContext();
166 if (!ctx) {
167 qWarning("Requires a valid current OpenGL context.\n"
168 "Texture has not been created");
169 return false;
170 }
171 context = ctx;
172 functions = ctx->functions();
173
174 // Resolve any functions we will need based upon context version and create the texture
175 initializeOpenGLFunctions();
176
177 // What features do we have?
178 QOpenGLTexture::Feature feature = QOpenGLTexture::ImmutableStorage;
179 while (feature != QOpenGLTexture::MaxFeatureFlag) {
180 if (QOpenGLTexture::hasFeature(feature))
181 features |= feature;
182 feature = static_cast<QOpenGLTexture::Feature>(feature << 1);
183 }
184
185 functions->glGenTextures(1, &textureId);
186 return textureId != 0;
187}
188
189void QOpenGLTexturePrivate::destroy()
190{
191 if (!textureId) {
192 // not created or already destroyed
193 return;
194 }
195 QOpenGLContext *currentContext = QOpenGLContext::currentContext();
196 if (!currentContext) {
197 qWarning("QOpenGLTexturePrivate::destroy() called without a current context.\n"
198 "Texture has not been destroyed");
199 return;
200 }
201 if (!QOpenGLContext::areSharing(currentContext, context)) {
202
203 qWarning("QOpenGLTexturePrivate::destroy() called but texture context %p"
204 " is not shared with current context %p.\n"
205 "Texture has not been destroyed",
206 static_cast<const void *>(context),
207 static_cast<const void *>(currentContext));
208 return;
209 }
210
211 functions->glDeleteTextures(1, &textureId);
212
213 context = nullptr;
214 functions = nullptr;
215 textureId = 0;
216 format = QOpenGLTexture::NoFormat;
217 formatClass = QOpenGLTexture::NoFormatClass;
218 requestedMipLevels = 1;
219 mipLevels = -1;
220 layers = 1;
221 faces = 1;
222 samples = 0;
223 fixedSamplePositions = true,
224 baseLevel = 0;
225 maxLevel = 1000;
226 depthStencilMode = QOpenGLTexture::DepthMode;
227 minFilter = QOpenGLTexture::Nearest;
228 magFilter = QOpenGLTexture::Nearest;
229 maxAnisotropy = 1.0f;
230 minLevelOfDetail = -1000.0f;
231 maxLevelOfDetail = 1000.0f;
232 levelOfDetailBias = 0.0f;
233 textureView = false;
234 autoGenerateMipMaps = true;
235 storageAllocated = false;
236 texFuncs = nullptr;
237
238 swizzleMask[0] = QOpenGLTexture::RedValue;
239 swizzleMask[1] = QOpenGLTexture::GreenValue;
240 swizzleMask[2] = QOpenGLTexture::BlueValue;
241 swizzleMask[3] = QOpenGLTexture::AlphaValue;
242
243 wrapModes[0] = wrapModes[1] = wrapModes[2] = target == QOpenGLTexture::TargetRectangle
244 ? QOpenGLTexture::ClampToEdge : QOpenGLTexture::Repeat;
245}
246
247void QOpenGLTexturePrivate::bind()
248{
249 functions->glBindTexture(target, textureId);
250}
251
252void QOpenGLTexturePrivate::bind(uint unit, QOpenGLTexture::TextureUnitReset reset)
253{
254 GLint oldTextureUnit = 0;
255 if (reset == QOpenGLTexture::ResetTextureUnit)
256 functions->glGetIntegerv(GL_ACTIVE_TEXTURE, &oldTextureUnit);
257
258 texFuncs->glActiveTexture(GL_TEXTURE0 + unit);
259 functions->glBindTexture(target, textureId);
260
261 if (reset == QOpenGLTexture::ResetTextureUnit)
262 texFuncs->glActiveTexture(GL_TEXTURE0 + oldTextureUnit);
263}
264
265void QOpenGLTexturePrivate::release()
266{
267 functions->glBindTexture(target, 0);
268}
269
270void QOpenGLTexturePrivate::release(uint unit, QOpenGLTexture::TextureUnitReset reset)
271{
272 GLint oldTextureUnit = 0;
273 if (reset == QOpenGLTexture::ResetTextureUnit)
274 functions->glGetIntegerv(GL_ACTIVE_TEXTURE, &oldTextureUnit);
275
276 texFuncs->glActiveTexture(GL_TEXTURE0 + unit);
277 functions->glBindTexture(target, 0);
278
279 if (reset == QOpenGLTexture::ResetTextureUnit)
280 texFuncs->glActiveTexture(GL_TEXTURE0 + oldTextureUnit);
281}
282
283bool QOpenGLTexturePrivate::isBound() const
284{
285 GLint boundTextureId = 0;
286 functions->glGetIntegerv(bindingTarget, &boundTextureId);
287 return (static_cast<GLuint>(boundTextureId) == textureId);
288}
289
290bool QOpenGLTexturePrivate::isBound(uint unit) const
291{
292 GLint oldTextureUnit = 0;
293 functions->glGetIntegerv(GL_ACTIVE_TEXTURE, &oldTextureUnit);
294
295 GLint boundTextureId = 0;
296 texFuncs->glActiveTexture(GL_TEXTURE0 + unit);
297 functions->glGetIntegerv(bindingTarget, &boundTextureId);
298 bool result = (static_cast<GLuint>(boundTextureId) == textureId);
299
300 texFuncs->glActiveTexture(GL_TEXTURE0 + oldTextureUnit);
301 return result;
302}
303
304int QOpenGLTexturePrivate::evaluateMipLevels() const
305{
306 switch (target) {
307 case QOpenGLTexture::Target1D:
308 case QOpenGLTexture::Target1DArray:
309 case QOpenGLTexture::Target2D:
310 case QOpenGLTexture::Target2DArray:
311 case QOpenGLTexture::Target3D:
312 case QOpenGLTexture::TargetCubeMap:
313 case QOpenGLTexture::TargetCubeMapArray:
314 return qMin(maximumMipLevelCount(), qMax(1, requestedMipLevels));
315
316 case QOpenGLTexture::TargetRectangle:
317 case QOpenGLTexture::Target2DMultisample:
318 case QOpenGLTexture::Target2DMultisampleArray:
319 case QOpenGLTexture::TargetBuffer:
320 default:
321 return 1;
322 }
323}
324
325static bool isSizedTextureFormat(QOpenGLTexture::TextureFormat internalFormat)
326{
327 switch (internalFormat) {
328 case QOpenGLTexture::NoFormat:
329 return false;
330
331 case QOpenGLTexture::R8_UNorm:
332 case QOpenGLTexture::RG8_UNorm:
333 case QOpenGLTexture::RGB8_UNorm:
334 case QOpenGLTexture::RGBA8_UNorm:
335 case QOpenGLTexture::R16_UNorm:
336 case QOpenGLTexture::RG16_UNorm:
337 case QOpenGLTexture::RGB16_UNorm:
338 case QOpenGLTexture::RGBA16_UNorm:
339 case QOpenGLTexture::R8_SNorm:
340 case QOpenGLTexture::RG8_SNorm:
341 case QOpenGLTexture::RGB8_SNorm:
342 case QOpenGLTexture::RGBA8_SNorm:
343 case QOpenGLTexture::R16_SNorm:
344 case QOpenGLTexture::RG16_SNorm:
345 case QOpenGLTexture::RGB16_SNorm:
346 case QOpenGLTexture::RGBA16_SNorm:
347 case QOpenGLTexture::R8U:
348 case QOpenGLTexture::RG8U:
349 case QOpenGLTexture::RGB8U:
350 case QOpenGLTexture::RGBA8U:
351 case QOpenGLTexture::R16U:
352 case QOpenGLTexture::RG16U:
353 case QOpenGLTexture::RGB16U:
354 case QOpenGLTexture::RGBA16U:
355 case QOpenGLTexture::R32U:
356 case QOpenGLTexture::RG32U:
357 case QOpenGLTexture::RGB32U:
358 case QOpenGLTexture::RGBA32U:
359 case QOpenGLTexture::R8I:
360 case QOpenGLTexture::RG8I:
361 case QOpenGLTexture::RGB8I:
362 case QOpenGLTexture::RGBA8I:
363 case QOpenGLTexture::R16I:
364 case QOpenGLTexture::RG16I:
365 case QOpenGLTexture::RGB16I:
366 case QOpenGLTexture::RGBA16I:
367 case QOpenGLTexture::R32I:
368 case QOpenGLTexture::RG32I:
369 case QOpenGLTexture::RGB32I:
370 case QOpenGLTexture::RGBA32I:
371 case QOpenGLTexture::R16F:
372 case QOpenGLTexture::RG16F:
373 case QOpenGLTexture::RGB16F:
374 case QOpenGLTexture::RGBA16F:
375 case QOpenGLTexture::R32F:
376 case QOpenGLTexture::RG32F:
377 case QOpenGLTexture::RGB32F:
378 case QOpenGLTexture::RGBA32F:
379 case QOpenGLTexture::RGB9E5:
380 case QOpenGLTexture::RG11B10F:
381 case QOpenGLTexture::RG3B2:
382 case QOpenGLTexture::R5G6B5:
383 case QOpenGLTexture::RGB5A1:
384 case QOpenGLTexture::RGBA4:
385 case QOpenGLTexture::RGB10A2:
386
387 case QOpenGLTexture::D16:
388 case QOpenGLTexture::D24:
389 case QOpenGLTexture::D32:
390 case QOpenGLTexture::D32F:
391
392 case QOpenGLTexture::D24S8:
393 case QOpenGLTexture::D32FS8X24:
394
395 case QOpenGLTexture::S8:
396
397 case QOpenGLTexture::RGB_DXT1:
398 case QOpenGLTexture::RGBA_DXT1:
399 case QOpenGLTexture::RGBA_DXT3:
400 case QOpenGLTexture::RGBA_DXT5:
401 case QOpenGLTexture::R_ATI1N_UNorm:
402 case QOpenGLTexture::R_ATI1N_SNorm:
403 case QOpenGLTexture::RG_ATI2N_UNorm:
404 case QOpenGLTexture::RG_ATI2N_SNorm:
405 case QOpenGLTexture::RGB_BP_UNSIGNED_FLOAT:
406 case QOpenGLTexture::RGB_BP_SIGNED_FLOAT:
407 case QOpenGLTexture::RGB_BP_UNorm:
408 case QOpenGLTexture::SRGB8:
409 case QOpenGLTexture::SRGB8_Alpha8:
410 case QOpenGLTexture::SRGB_DXT1:
411 case QOpenGLTexture::SRGB_Alpha_DXT1:
412 case QOpenGLTexture::SRGB_Alpha_DXT3:
413 case QOpenGLTexture::SRGB_Alpha_DXT5:
414 case QOpenGLTexture::SRGB_BP_UNorm:
415 case QOpenGLTexture::R11_EAC_UNorm:
416 case QOpenGLTexture::R11_EAC_SNorm:
417 case QOpenGLTexture::RG11_EAC_UNorm:
418 case QOpenGLTexture::RG11_EAC_SNorm:
419 case QOpenGLTexture::RGB8_ETC2:
420 case QOpenGLTexture::SRGB8_ETC2:
421 case QOpenGLTexture::RGB8_PunchThrough_Alpha1_ETC2:
422 case QOpenGLTexture::SRGB8_PunchThrough_Alpha1_ETC2:
423 case QOpenGLTexture::RGBA8_ETC2_EAC:
424 case QOpenGLTexture::SRGB8_Alpha8_ETC2_EAC:
425 case QOpenGLTexture::RGBA_ASTC_4x4:
426 case QOpenGLTexture::RGBA_ASTC_5x4:
427 case QOpenGLTexture::RGBA_ASTC_5x5:
428 case QOpenGLTexture::RGBA_ASTC_6x5:
429 case QOpenGLTexture::RGBA_ASTC_6x6:
430 case QOpenGLTexture::RGBA_ASTC_8x5:
431 case QOpenGLTexture::RGBA_ASTC_8x6:
432 case QOpenGLTexture::RGBA_ASTC_8x8:
433 case QOpenGLTexture::RGBA_ASTC_10x5:
434 case QOpenGLTexture::RGBA_ASTC_10x6:
435 case QOpenGLTexture::RGBA_ASTC_10x8:
436 case QOpenGLTexture::RGBA_ASTC_10x10:
437 case QOpenGLTexture::RGBA_ASTC_12x10:
438 case QOpenGLTexture::RGBA_ASTC_12x12:
439 case QOpenGLTexture::SRGB8_Alpha8_ASTC_4x4:
440 case QOpenGLTexture::SRGB8_Alpha8_ASTC_5x4:
441 case QOpenGLTexture::SRGB8_Alpha8_ASTC_5x5:
442 case QOpenGLTexture::SRGB8_Alpha8_ASTC_6x5:
443 case QOpenGLTexture::SRGB8_Alpha8_ASTC_6x6:
444 case QOpenGLTexture::SRGB8_Alpha8_ASTC_8x5:
445 case QOpenGLTexture::SRGB8_Alpha8_ASTC_8x6:
446 case QOpenGLTexture::SRGB8_Alpha8_ASTC_8x8:
447 case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x5:
448 case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x6:
449 case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x8:
450 case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x10:
451 case QOpenGLTexture::SRGB8_Alpha8_ASTC_12x10:
452 case QOpenGLTexture::SRGB8_Alpha8_ASTC_12x12:
453 return true;
454
455 case QOpenGLTexture::RGB8_ETC1:
456 return false;
457
458 case QOpenGLTexture::DepthFormat:
459 case QOpenGLTexture::AlphaFormat:
460
461 case QOpenGLTexture::RGBFormat:
462 case QOpenGLTexture::RGBAFormat:
463
464 case QOpenGLTexture::LuminanceFormat:
465
466 case QOpenGLTexture::LuminanceAlphaFormat:
467 return false;
468 }
469
470 Q_UNREACHABLE();
471 return false;
472}
473
474static bool isTextureTargetMultisample(QOpenGLTexture::Target target)
475{
476 switch (target) {
477 case QOpenGLTexture::Target1D:
478 case QOpenGLTexture::Target1DArray:
479 case QOpenGLTexture::Target2D:
480 case QOpenGLTexture::Target2DArray:
481 case QOpenGLTexture::Target3D:
482 case QOpenGLTexture::TargetCubeMap:
483 case QOpenGLTexture::TargetCubeMapArray:
484 return false;
485
486 case QOpenGLTexture::Target2DMultisample:
487 case QOpenGLTexture::Target2DMultisampleArray:
488 return true;
489
490 case QOpenGLTexture::TargetRectangle:
491 case QOpenGLTexture::TargetBuffer:
492 return false;
493 }
494
495 Q_UNREACHABLE();
496 return false;
497}
498
499bool QOpenGLTexturePrivate::isUsingImmutableStorage() const
500{
501 // Use immutable storage whenever possible, falling back to mutable
502 // Note that if multisample textures are not supported at all, we'll still fail into
503 // the mutable storage allocation
504 return isSizedTextureFormat(format)
505 && (isTextureTargetMultisample(target)
506 ? features.testFlag(QOpenGLTexture::ImmutableMultisampleStorage)
507 : features.testFlag(QOpenGLTexture::ImmutableStorage));
508}
509
510void QOpenGLTexturePrivate::allocateStorage(QOpenGLTexture::PixelFormat pixelFormat, QOpenGLTexture::PixelType pixelType)
511{
512 // Resolve the actual number of mipmap levels we can use
513 mipLevels = evaluateMipLevels();
514
515 if (isUsingImmutableStorage())
516 allocateImmutableStorage();
517 else
518 allocateMutableStorage(pixelFormat, pixelType);
519}
520
521static QOpenGLTexture::PixelFormat pixelFormatCompatibleWithInternalFormat(QOpenGLTexture::TextureFormat internalFormat)
522{
523 switch (internalFormat) {
524 case QOpenGLTexture::NoFormat:
525 return QOpenGLTexture::NoSourceFormat;
526
527 case QOpenGLTexture::R8_UNorm:
528 return QOpenGLTexture::Red;
529
530 case QOpenGLTexture::RG8_UNorm:
531 return QOpenGLTexture::RG;
532
533 case QOpenGLTexture::RGB8_UNorm:
534 return QOpenGLTexture::RGB;
535
536 case QOpenGLTexture::RGBA8_UNorm:
537 return QOpenGLTexture::RGBA;
538
539 case QOpenGLTexture::R16_UNorm:
540 return QOpenGLTexture::Red;
541
542 case QOpenGLTexture::RG16_UNorm:
543 return QOpenGLTexture::RG;
544
545 case QOpenGLTexture::RGB16_UNorm:
546 return QOpenGLTexture::RGB;
547
548 case QOpenGLTexture::RGBA16_UNorm:
549 return QOpenGLTexture::RGBA;
550
551 case QOpenGLTexture::R8_SNorm:
552 return QOpenGLTexture::Red;
553
554 case QOpenGLTexture::RG8_SNorm:
555 return QOpenGLTexture::RG;
556
557 case QOpenGLTexture::RGB8_SNorm:
558 return QOpenGLTexture::RGB;
559
560 case QOpenGLTexture::RGBA8_SNorm:
561 return QOpenGLTexture::RGBA;
562
563 case QOpenGLTexture::R16_SNorm:
564 return QOpenGLTexture::Red;
565
566 case QOpenGLTexture::RG16_SNorm:
567 return QOpenGLTexture::RG;
568
569 case QOpenGLTexture::RGB16_SNorm:
570 return QOpenGLTexture::RGB;
571
572 case QOpenGLTexture::RGBA16_SNorm:
573 return QOpenGLTexture::RGBA;
574
575 case QOpenGLTexture::R8U:
576 return QOpenGLTexture::Red_Integer;
577
578 case QOpenGLTexture::RG8U:
579 return QOpenGLTexture::RG_Integer;
580
581 case QOpenGLTexture::RGB8U:
582 return QOpenGLTexture::RGB_Integer;
583
584 case QOpenGLTexture::RGBA8U:
585 return QOpenGLTexture::RGBA_Integer;
586
587 case QOpenGLTexture::R16U:
588 return QOpenGLTexture::Red_Integer;
589
590 case QOpenGLTexture::RG16U:
591 return QOpenGLTexture::RG_Integer;
592
593 case QOpenGLTexture::RGB16U:
594 return QOpenGLTexture::RGB_Integer;
595
596 case QOpenGLTexture::RGBA16U:
597 return QOpenGLTexture::RGBA_Integer;
598
599 case QOpenGLTexture::R32U:
600 return QOpenGLTexture::Red_Integer;
601
602 case QOpenGLTexture::RG32U:
603 return QOpenGLTexture::RG_Integer;
604
605 case QOpenGLTexture::RGB32U:
606 return QOpenGLTexture::RGB_Integer;
607
608 case QOpenGLTexture::RGBA32U:
609 return QOpenGLTexture::RGBA_Integer;
610
611 case QOpenGLTexture::R8I:
612 return QOpenGLTexture::Red_Integer;
613
614 case QOpenGLTexture::RG8I:
615 return QOpenGLTexture::RG_Integer;
616
617 case QOpenGLTexture::RGB8I:
618 return QOpenGLTexture::RGB_Integer;
619
620 case QOpenGLTexture::RGBA8I:
621 return QOpenGLTexture::RGBA_Integer;
622
623 case QOpenGLTexture::R16I:
624 return QOpenGLTexture::Red_Integer;
625
626 case QOpenGLTexture::RG16I:
627 return QOpenGLTexture::RG_Integer;
628
629 case QOpenGLTexture::RGB16I:
630 return QOpenGLTexture::RGB_Integer;
631
632 case QOpenGLTexture::RGBA16I:
633 return QOpenGLTexture::RGBA_Integer;
634
635 case QOpenGLTexture::R32I:
636 return QOpenGLTexture::Red_Integer;
637
638 case QOpenGLTexture::RG32I:
639 return QOpenGLTexture::RG_Integer;
640
641 case QOpenGLTexture::RGB32I:
642 return QOpenGLTexture::RGB_Integer;
643
644 case QOpenGLTexture::RGBA32I:
645 return QOpenGLTexture::RGBA_Integer;
646
647 case QOpenGLTexture::R16F:
648 return QOpenGLTexture::Red;
649
650 case QOpenGLTexture::RG16F:
651 return QOpenGLTexture::RG;
652
653 case QOpenGLTexture::RGB16F:
654 return QOpenGLTexture::RGB;
655
656 case QOpenGLTexture::RGBA16F:
657 return QOpenGLTexture::RGBA;
658
659 case QOpenGLTexture::R32F:
660 return QOpenGLTexture::Red;
661
662 case QOpenGLTexture::RG32F:
663 return QOpenGLTexture::RG;
664
665 case QOpenGLTexture::RGB32F:
666 return QOpenGLTexture::RGB;
667
668 case QOpenGLTexture::RGBA32F:
669 return QOpenGLTexture::RGBA;
670
671 case QOpenGLTexture::RGB9E5:
672 return QOpenGLTexture::RGB;
673
674 case QOpenGLTexture::RG11B10F:
675 return QOpenGLTexture::RGB;
676
677 case QOpenGLTexture::RG3B2:
678 return QOpenGLTexture::RGB;
679
680 case QOpenGLTexture::R5G6B5:
681 return QOpenGLTexture::RGB;
682
683 case QOpenGLTexture::RGB5A1:
684 return QOpenGLTexture::RGBA;
685
686 case QOpenGLTexture::RGBA4:
687 return QOpenGLTexture::RGBA;
688
689 case QOpenGLTexture::RGB10A2:
690 return QOpenGLTexture::RGBA;
691
692 case QOpenGLTexture::D16:
693 case QOpenGLTexture::D24:
694 case QOpenGLTexture::D32:
695 case QOpenGLTexture::D32F:
696 return QOpenGLTexture::Depth;
697
698 case QOpenGLTexture::D24S8:
699 case QOpenGLTexture::D32FS8X24:
700 return QOpenGLTexture::DepthStencil;
701
702 case QOpenGLTexture::S8:
703 return QOpenGLTexture::Stencil;
704
705 case QOpenGLTexture::RGB_DXT1:
706 case QOpenGLTexture::RGBA_DXT1:
707 case QOpenGLTexture::RGBA_DXT3:
708 case QOpenGLTexture::RGBA_DXT5:
709 case QOpenGLTexture::R_ATI1N_UNorm:
710 case QOpenGLTexture::R_ATI1N_SNorm:
711 case QOpenGLTexture::RG_ATI2N_UNorm:
712 case QOpenGLTexture::RG_ATI2N_SNorm:
713 case QOpenGLTexture::RGB_BP_UNSIGNED_FLOAT:
714 case QOpenGLTexture::RGB_BP_SIGNED_FLOAT:
715 case QOpenGLTexture::RGB_BP_UNorm:
716 case QOpenGLTexture::SRGB8:
717 case QOpenGLTexture::SRGB8_Alpha8:
718 case QOpenGLTexture::SRGB_DXT1:
719 case QOpenGLTexture::SRGB_Alpha_DXT1:
720 case QOpenGLTexture::SRGB_Alpha_DXT3:
721 case QOpenGLTexture::SRGB_Alpha_DXT5:
722 case QOpenGLTexture::SRGB_BP_UNorm:
723 case QOpenGLTexture::RGB8_ETC1:
724 return QOpenGLTexture::RGBA;
725
726 case QOpenGLTexture::R11_EAC_UNorm:
727 case QOpenGLTexture::R11_EAC_SNorm:
728 return QOpenGLTexture::Red;
729
730 case QOpenGLTexture::RG11_EAC_UNorm:
731 case QOpenGLTexture::RG11_EAC_SNorm:
732 return QOpenGLTexture::RG;
733
734 case QOpenGLTexture::RGB8_ETC2:
735 case QOpenGLTexture::SRGB8_ETC2:
736 return QOpenGLTexture::RGB;
737
738 case QOpenGLTexture::RGB8_PunchThrough_Alpha1_ETC2:
739 case QOpenGLTexture::SRGB8_PunchThrough_Alpha1_ETC2:
740 return QOpenGLTexture::RGBA;
741
742 case QOpenGLTexture::RGBA8_ETC2_EAC:
743 case QOpenGLTexture::SRGB8_Alpha8_ETC2_EAC:
744 return QOpenGLTexture::RGBA;
745
746 case QOpenGLTexture::RGBA_ASTC_4x4:
747 case QOpenGLTexture::RGBA_ASTC_5x4:
748 case QOpenGLTexture::RGBA_ASTC_5x5:
749 case QOpenGLTexture::RGBA_ASTC_6x5:
750 case QOpenGLTexture::RGBA_ASTC_6x6:
751 case QOpenGLTexture::RGBA_ASTC_8x5:
752 case QOpenGLTexture::RGBA_ASTC_8x6:
753 case QOpenGLTexture::RGBA_ASTC_8x8:
754 case QOpenGLTexture::RGBA_ASTC_10x5:
755 case QOpenGLTexture::RGBA_ASTC_10x6:
756 case QOpenGLTexture::RGBA_ASTC_10x8:
757 case QOpenGLTexture::RGBA_ASTC_10x10:
758 case QOpenGLTexture::RGBA_ASTC_12x10:
759 case QOpenGLTexture::RGBA_ASTC_12x12:
760 case QOpenGLTexture::SRGB8_Alpha8_ASTC_4x4:
761 case QOpenGLTexture::SRGB8_Alpha8_ASTC_5x4:
762 case QOpenGLTexture::SRGB8_Alpha8_ASTC_5x5:
763 case QOpenGLTexture::SRGB8_Alpha8_ASTC_6x5:
764 case QOpenGLTexture::SRGB8_Alpha8_ASTC_6x6:
765 case QOpenGLTexture::SRGB8_Alpha8_ASTC_8x5:
766 case QOpenGLTexture::SRGB8_Alpha8_ASTC_8x6:
767 case QOpenGLTexture::SRGB8_Alpha8_ASTC_8x8:
768 case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x5:
769 case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x6:
770 case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x8:
771 case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x10:
772 case QOpenGLTexture::SRGB8_Alpha8_ASTC_12x10:
773 case QOpenGLTexture::SRGB8_Alpha8_ASTC_12x12:
774 return QOpenGLTexture::RGBA;
775
776 case QOpenGLTexture::DepthFormat:
777 return QOpenGLTexture::Depth;
778
779 case QOpenGLTexture::AlphaFormat:
780 return QOpenGLTexture::Alpha;
781
782 case QOpenGLTexture::RGBFormat:
783 return QOpenGLTexture::RGB;
784
785 case QOpenGLTexture::RGBAFormat:
786 return QOpenGLTexture::RGBA;
787
788 case QOpenGLTexture::LuminanceFormat:
789 return QOpenGLTexture::Luminance;
790
791 case QOpenGLTexture::LuminanceAlphaFormat:
792 return QOpenGLTexture::LuminanceAlpha;
793 }
794
795 Q_UNREACHABLE();
796 return QOpenGLTexture::NoSourceFormat;
797}
798
799static QOpenGLTexture::PixelType pixelTypeCompatibleWithInternalFormat(QOpenGLTexture::TextureFormat internalFormat)
800{
801 switch (internalFormat) {
802 case QOpenGLTexture::NoFormat:
803 return QOpenGLTexture::NoPixelType;
804
805 case QOpenGLTexture::R8_UNorm:
806 case QOpenGLTexture::RG8_UNorm:
807 case QOpenGLTexture::RGB8_UNorm:
808 case QOpenGLTexture::RGBA8_UNorm:
809 case QOpenGLTexture::R16_UNorm:
810 case QOpenGLTexture::RG16_UNorm:
811 case QOpenGLTexture::RGB16_UNorm:
812 case QOpenGLTexture::RGBA16_UNorm:
813 return QOpenGLTexture::UInt8;
814
815 case QOpenGLTexture::R8_SNorm:
816 case QOpenGLTexture::RG8_SNorm:
817 case QOpenGLTexture::RGB8_SNorm:
818 case QOpenGLTexture::RGBA8_SNorm:
819 case QOpenGLTexture::R16_SNorm:
820 case QOpenGLTexture::RG16_SNorm:
821 case QOpenGLTexture::RGB16_SNorm:
822 case QOpenGLTexture::RGBA16_SNorm:
823 return QOpenGLTexture::Int8;
824
825 case QOpenGLTexture::R8U:
826 case QOpenGLTexture::RG8U:
827 case QOpenGLTexture::RGB8U:
828 case QOpenGLTexture::RGBA8U:
829 case QOpenGLTexture::R16U:
830 case QOpenGLTexture::RG16U:
831 case QOpenGLTexture::RGB16U:
832 case QOpenGLTexture::RGBA16U:
833 case QOpenGLTexture::R32U:
834 case QOpenGLTexture::RG32U:
835 case QOpenGLTexture::RGB32U:
836 case QOpenGLTexture::RGBA32U:
837 return QOpenGLTexture::UInt8;
838
839 case QOpenGLTexture::R8I:
840 case QOpenGLTexture::RG8I:
841 case QOpenGLTexture::RGB8I:
842 case QOpenGLTexture::RGBA8I:
843 case QOpenGLTexture::R16I:
844 case QOpenGLTexture::RG16I:
845 case QOpenGLTexture::RGB16I:
846 case QOpenGLTexture::RGBA16I:
847 case QOpenGLTexture::R32I:
848 case QOpenGLTexture::RG32I:
849 case QOpenGLTexture::RGB32I:
850 case QOpenGLTexture::RGBA32I:
851 return QOpenGLTexture::Int8;
852
853 case QOpenGLTexture::R16F:
854 case QOpenGLTexture::RG16F:
855 case QOpenGLTexture::RGB16F:
856 case QOpenGLTexture::RGBA16F:
857 return QOpenGLTexture::Float16;
858
859 case QOpenGLTexture::R32F:
860 case QOpenGLTexture::RG32F:
861 case QOpenGLTexture::RGB32F:
862 case QOpenGLTexture::RGBA32F:
863 return QOpenGLTexture::Float32;
864
865 case QOpenGLTexture::RGB9E5:
866 return QOpenGLTexture::UInt16_RGB5A1_Rev;
867
868 case QOpenGLTexture::RG11B10F:
869 return QOpenGLTexture::UInt32_RG11B10F;
870
871 case QOpenGLTexture::RG3B2:
872 return QOpenGLTexture::UInt8_RG3B2;
873
874 case QOpenGLTexture::R5G6B5:
875 return QOpenGLTexture::UInt16_R5G6B5;
876
877 case QOpenGLTexture::RGB5A1:
878 return QOpenGLTexture::UInt16_RGB5A1;
879
880 case QOpenGLTexture::RGBA4:
881 return QOpenGLTexture::UInt16_RGBA4;
882
883 case QOpenGLTexture::RGB10A2:
884 return QOpenGLTexture::UInt32_RGB10A2;
885
886 case QOpenGLTexture::D16:
887 return QOpenGLTexture::UInt16;
888
889 case QOpenGLTexture::D24:
890 case QOpenGLTexture::D32:
891 return QOpenGLTexture::UInt32;
892
893 case QOpenGLTexture::D32F:
894 return QOpenGLTexture::Float32;
895
896 case QOpenGLTexture::D24S8:
897 return QOpenGLTexture::UInt32_D24S8;
898
899 case QOpenGLTexture::D32FS8X24:
900 return QOpenGLTexture::Float32_D32_UInt32_S8_X24;
901
902 case QOpenGLTexture::S8:
903 return QOpenGLTexture::UInt8;
904
905 case QOpenGLTexture::RGB_DXT1:
906 case QOpenGLTexture::RGBA_DXT1:
907 case QOpenGLTexture::RGBA_DXT3:
908 case QOpenGLTexture::RGBA_DXT5:
909 case QOpenGLTexture::R_ATI1N_UNorm:
910 case QOpenGLTexture::R_ATI1N_SNorm:
911 case QOpenGLTexture::RG_ATI2N_UNorm:
912 case QOpenGLTexture::RG_ATI2N_SNorm:
913 case QOpenGLTexture::RGB_BP_UNSIGNED_FLOAT:
914 case QOpenGLTexture::RGB_BP_SIGNED_FLOAT:
915 case QOpenGLTexture::RGB_BP_UNorm:
916 case QOpenGLTexture::SRGB8:
917 case QOpenGLTexture::SRGB8_Alpha8:
918 case QOpenGLTexture::SRGB_DXT1:
919 case QOpenGLTexture::SRGB_Alpha_DXT1:
920 case QOpenGLTexture::SRGB_Alpha_DXT3:
921 case QOpenGLTexture::SRGB_Alpha_DXT5:
922 case QOpenGLTexture::SRGB_BP_UNorm:
923 case QOpenGLTexture::R11_EAC_UNorm:
924 case QOpenGLTexture::R11_EAC_SNorm:
925 case QOpenGLTexture::RG11_EAC_UNorm:
926 case QOpenGLTexture::RG11_EAC_SNorm:
927 case QOpenGLTexture::RGB8_ETC2:
928 case QOpenGLTexture::SRGB8_ETC2:
929 case QOpenGLTexture::RGB8_PunchThrough_Alpha1_ETC2:
930 case QOpenGLTexture::SRGB8_PunchThrough_Alpha1_ETC2:
931 case QOpenGLTexture::RGBA8_ETC2_EAC:
932 case QOpenGLTexture::SRGB8_Alpha8_ETC2_EAC:
933 case QOpenGLTexture::RGB8_ETC1:
934 case QOpenGLTexture::RGBA_ASTC_4x4:
935 case QOpenGLTexture::RGBA_ASTC_5x4:
936 case QOpenGLTexture::RGBA_ASTC_5x5:
937 case QOpenGLTexture::RGBA_ASTC_6x5:
938 case QOpenGLTexture::RGBA_ASTC_6x6:
939 case QOpenGLTexture::RGBA_ASTC_8x5:
940 case QOpenGLTexture::RGBA_ASTC_8x6:
941 case QOpenGLTexture::RGBA_ASTC_8x8:
942 case QOpenGLTexture::RGBA_ASTC_10x5:
943 case QOpenGLTexture::RGBA_ASTC_10x6:
944 case QOpenGLTexture::RGBA_ASTC_10x8:
945 case QOpenGLTexture::RGBA_ASTC_10x10:
946 case QOpenGLTexture::RGBA_ASTC_12x10:
947 case QOpenGLTexture::RGBA_ASTC_12x12:
948 case QOpenGLTexture::SRGB8_Alpha8_ASTC_4x4:
949 case QOpenGLTexture::SRGB8_Alpha8_ASTC_5x4:
950 case QOpenGLTexture::SRGB8_Alpha8_ASTC_5x5:
951 case QOpenGLTexture::SRGB8_Alpha8_ASTC_6x5:
952 case QOpenGLTexture::SRGB8_Alpha8_ASTC_6x6:
953 case QOpenGLTexture::SRGB8_Alpha8_ASTC_8x5:
954 case QOpenGLTexture::SRGB8_Alpha8_ASTC_8x6:
955 case QOpenGLTexture::SRGB8_Alpha8_ASTC_8x8:
956 case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x5:
957 case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x6:
958 case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x8:
959 case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x10:
960 case QOpenGLTexture::SRGB8_Alpha8_ASTC_12x10:
961 case QOpenGLTexture::SRGB8_Alpha8_ASTC_12x12:
962 return QOpenGLTexture::UInt8;
963
964 case QOpenGLTexture::DepthFormat:
965 return QOpenGLTexture::UInt32;
966
967 case QOpenGLTexture::AlphaFormat:
968 case QOpenGLTexture::RGBFormat:
969 case QOpenGLTexture::RGBAFormat:
970 case QOpenGLTexture::LuminanceFormat:
971 case QOpenGLTexture::LuminanceAlphaFormat:
972 return QOpenGLTexture::UInt8;
973 }
974
975 Q_UNREACHABLE();
976 return QOpenGLTexture::NoPixelType;
977}
978
979static bool isCompressedFormat(QOpenGLTexture::TextureFormat internalFormat)
980{
981 switch (internalFormat) {
982 case QOpenGLTexture::NoFormat:
983
984 case QOpenGLTexture::R8_UNorm:
985 case QOpenGLTexture::RG8_UNorm:
986 case QOpenGLTexture::RGB8_UNorm:
987 case QOpenGLTexture::RGBA8_UNorm:
988 case QOpenGLTexture::R16_UNorm:
989 case QOpenGLTexture::RG16_UNorm:
990 case QOpenGLTexture::RGB16_UNorm:
991 case QOpenGLTexture::RGBA16_UNorm:
992 case QOpenGLTexture::R8_SNorm:
993 case QOpenGLTexture::RG8_SNorm:
994 case QOpenGLTexture::RGB8_SNorm:
995 case QOpenGLTexture::RGBA8_SNorm:
996 case QOpenGLTexture::R16_SNorm:
997 case QOpenGLTexture::RG16_SNorm:
998 case QOpenGLTexture::RGB16_SNorm:
999 case QOpenGLTexture::RGBA16_SNorm:
1000 case QOpenGLTexture::R8U:
1001 case QOpenGLTexture::RG8U:
1002 case QOpenGLTexture::RGB8U:
1003 case QOpenGLTexture::RGBA8U:
1004 case QOpenGLTexture::R16U:
1005 case QOpenGLTexture::RG16U:
1006 case QOpenGLTexture::RGB16U:
1007 case QOpenGLTexture::RGBA16U:
1008 case QOpenGLTexture::R32U:
1009 case QOpenGLTexture::RG32U:
1010 case QOpenGLTexture::RGB32U:
1011 case QOpenGLTexture::RGBA32U:
1012 case QOpenGLTexture::R8I:
1013 case QOpenGLTexture::RG8I:
1014 case QOpenGLTexture::RGB8I:
1015 case QOpenGLTexture::RGBA8I:
1016 case QOpenGLTexture::R16I:
1017 case QOpenGLTexture::RG16I:
1018 case QOpenGLTexture::RGB16I:
1019 case QOpenGLTexture::RGBA16I:
1020 case QOpenGLTexture::R32I:
1021 case QOpenGLTexture::RG32I:
1022 case QOpenGLTexture::RGB32I:
1023 case QOpenGLTexture::RGBA32I:
1024 case QOpenGLTexture::R16F:
1025 case QOpenGLTexture::RG16F:
1026 case QOpenGLTexture::RGB16F:
1027 case QOpenGLTexture::RGBA16F:
1028 case QOpenGLTexture::R32F:
1029 case QOpenGLTexture::RG32F:
1030 case QOpenGLTexture::RGB32F:
1031 case QOpenGLTexture::RGBA32F:
1032 case QOpenGLTexture::RGB9E5:
1033 case QOpenGLTexture::RG11B10F:
1034 case QOpenGLTexture::RG3B2:
1035 case QOpenGLTexture::R5G6B5:
1036 case QOpenGLTexture::RGB5A1:
1037 case QOpenGLTexture::RGBA4:
1038 case QOpenGLTexture::RGB10A2:
1039
1040 case QOpenGLTexture::D16:
1041 case QOpenGLTexture::D24:
1042 case QOpenGLTexture::D32:
1043 case QOpenGLTexture::D32F:
1044
1045 case QOpenGLTexture::D24S8:
1046 case QOpenGLTexture::D32FS8X24:
1047
1048 case QOpenGLTexture::S8:
1049 return false;
1050
1051 case QOpenGLTexture::RGB_DXT1:
1052 case QOpenGLTexture::RGBA_DXT1:
1053 case QOpenGLTexture::RGBA_DXT3:
1054 case QOpenGLTexture::RGBA_DXT5:
1055 case QOpenGLTexture::R_ATI1N_UNorm:
1056 case QOpenGLTexture::R_ATI1N_SNorm:
1057 case QOpenGLTexture::RG_ATI2N_UNorm:
1058 case QOpenGLTexture::RG_ATI2N_SNorm:
1059 case QOpenGLTexture::RGB_BP_UNSIGNED_FLOAT:
1060 case QOpenGLTexture::RGB_BP_SIGNED_FLOAT:
1061 case QOpenGLTexture::RGB_BP_UNorm:
1062 case QOpenGLTexture::SRGB8:
1063 case QOpenGLTexture::SRGB8_Alpha8:
1064 case QOpenGLTexture::SRGB_DXT1:
1065 case QOpenGLTexture::SRGB_Alpha_DXT1:
1066 case QOpenGLTexture::SRGB_Alpha_DXT3:
1067 case QOpenGLTexture::SRGB_Alpha_DXT5:
1068 case QOpenGLTexture::SRGB_BP_UNorm:
1069 case QOpenGLTexture::R11_EAC_UNorm:
1070 case QOpenGLTexture::R11_EAC_SNorm:
1071 case QOpenGLTexture::RG11_EAC_UNorm:
1072 case QOpenGLTexture::RG11_EAC_SNorm:
1073 case QOpenGLTexture::RGB8_ETC2:
1074 case QOpenGLTexture::SRGB8_ETC2:
1075 case QOpenGLTexture::RGB8_PunchThrough_Alpha1_ETC2:
1076 case QOpenGLTexture::SRGB8_PunchThrough_Alpha1_ETC2:
1077 case QOpenGLTexture::RGBA8_ETC2_EAC:
1078 case QOpenGLTexture::SRGB8_Alpha8_ETC2_EAC:
1079 case QOpenGLTexture::RGB8_ETC1:
1080 case QOpenGLTexture::RGBA_ASTC_4x4:
1081 case QOpenGLTexture::RGBA_ASTC_5x4:
1082 case QOpenGLTexture::RGBA_ASTC_5x5:
1083 case QOpenGLTexture::RGBA_ASTC_6x5:
1084 case QOpenGLTexture::RGBA_ASTC_6x6:
1085 case QOpenGLTexture::RGBA_ASTC_8x5:
1086 case QOpenGLTexture::RGBA_ASTC_8x6:
1087 case QOpenGLTexture::RGBA_ASTC_8x8:
1088 case QOpenGLTexture::RGBA_ASTC_10x5:
1089 case QOpenGLTexture::RGBA_ASTC_10x6:
1090 case QOpenGLTexture::RGBA_ASTC_10x8:
1091 case QOpenGLTexture::RGBA_ASTC_10x10:
1092 case QOpenGLTexture::RGBA_ASTC_12x10:
1093 case QOpenGLTexture::RGBA_ASTC_12x12:
1094 case QOpenGLTexture::SRGB8_Alpha8_ASTC_4x4:
1095 case QOpenGLTexture::SRGB8_Alpha8_ASTC_5x4:
1096 case QOpenGLTexture::SRGB8_Alpha8_ASTC_5x5:
1097 case QOpenGLTexture::SRGB8_Alpha8_ASTC_6x5:
1098 case QOpenGLTexture::SRGB8_Alpha8_ASTC_6x6:
1099 case QOpenGLTexture::SRGB8_Alpha8_ASTC_8x5:
1100 case QOpenGLTexture::SRGB8_Alpha8_ASTC_8x6:
1101 case QOpenGLTexture::SRGB8_Alpha8_ASTC_8x8:
1102 case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x5:
1103 case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x6:
1104 case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x8:
1105 case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x10:
1106 case QOpenGLTexture::SRGB8_Alpha8_ASTC_12x10:
1107 case QOpenGLTexture::SRGB8_Alpha8_ASTC_12x12:
1108 return true;
1109
1110 case QOpenGLTexture::DepthFormat:
1111 case QOpenGLTexture::AlphaFormat:
1112 case QOpenGLTexture::RGBFormat:
1113 case QOpenGLTexture::RGBAFormat:
1114 case QOpenGLTexture::LuminanceFormat:
1115 case QOpenGLTexture::LuminanceAlphaFormat:
1116 return false;
1117 }
1118
1119 Q_UNREACHABLE();
1120 return false;
1121}
1122
1123void QOpenGLTexturePrivate::allocateMutableStorage(QOpenGLTexture::PixelFormat pixelFormat, QOpenGLTexture::PixelType pixelType)
1124{
1125 // There is no way to allocate mutable storage for compressed textures in in
1126 // versions older than OpenGL 3.1 and OpenGL ES 3.0, because the older specs
1127 // do not mandate accepting null data pointers for glCompressedTexImage*D,
1128 // unlike glTexImage*D (which in turn does not accept compressed formats).
1129 if (isCompressedFormat(format)) {
1130 storageAllocated = true;
1131 return;
1132 }
1133
1134 switch (target) {
1135 case QOpenGLTexture::TargetBuffer:
1136 // Buffer textures get their storage from an external OpenGL buffer
1137 qWarning("Buffer textures do not allocate storage");
1138 return;
1139
1140 case QOpenGLTexture::Target1D:
1141 if (features.testFlag(QOpenGLTexture::Texture1D)) {
1142 for (int level = 0; level < mipLevels; ++level)
1143 texFuncs->glTextureImage1D(textureId, target, bindingTarget, level, format,
1144 mipLevelSize(level, dimensions[0]),
1145 0,
1146 pixelFormat, pixelType, nullptr);
1147 } else {
1148 qWarning("1D textures are not supported");
1149 return;
1150 }
1151 break;
1152
1153 case QOpenGLTexture::Target1DArray:
1154 if (features.testFlag(QOpenGLTexture::Texture1D)
1155 && features.testFlag(QOpenGLTexture::TextureArrays)) {
1156 for (int level = 0; level < mipLevels; ++level)
1157 texFuncs->glTextureImage2D(textureId, target, bindingTarget, level, format,
1158 mipLevelSize(level, dimensions[0]),
1159 layers,
1160 0,
1161 pixelFormat, pixelType, nullptr);
1162 } else {
1163 qWarning("1D array textures are not supported");
1164 return;
1165 }
1166 break;
1167
1168 case QOpenGLTexture::Target2D:
1169 case QOpenGLTexture::TargetRectangle:
1170 for (int level = 0; level < mipLevels; ++level)
1171 texFuncs->glTextureImage2D(textureId, target, bindingTarget, level, format,
1172 mipLevelSize(level, dimensions[0]),
1173 mipLevelSize(level, dimensions[1]),
1174 0,
1175 pixelFormat, pixelType, nullptr);
1176 break;
1177
1178 case QOpenGLTexture::TargetCubeMap: {
1179 // Cubemaps are the odd one out. We have to allocate storage for each
1180 // face and miplevel using the special cubemap face targets rather than
1181 // GL_TARGET_CUBEMAP.
1182 const QOpenGLTexture::CubeMapFace faceTargets[] = {
1183 QOpenGLTexture::CubeMapPositiveX, QOpenGLTexture::CubeMapNegativeX,
1184 QOpenGLTexture::CubeMapPositiveY, QOpenGLTexture::CubeMapNegativeY,
1185 QOpenGLTexture::CubeMapPositiveZ, QOpenGLTexture::CubeMapNegativeZ
1186 };
1187
1188 for (int faceTarget = 0; faceTarget < 6; ++faceTarget) {
1189 for (int level = 0; level < mipLevels; ++level) {
1190 texFuncs->glTextureImage2D(textureId, faceTargets[faceTarget], bindingTarget,
1191 level, format,
1192 mipLevelSize(level, dimensions[0]),
1193 mipLevelSize(level, dimensions[1]),
1194 0,
1195 pixelFormat, pixelType, nullptr);
1196 }
1197 }
1198 break;
1199 }
1200
1201 case QOpenGLTexture::Target2DArray:
1202 if (features.testFlag(QOpenGLTexture::TextureArrays)) {
1203 for (int level = 0; level < mipLevels; ++level)
1204 texFuncs->glTextureImage3D(textureId, target, bindingTarget, level, format,
1205 mipLevelSize(level, dimensions[0]),
1206 mipLevelSize(level, dimensions[1]),
1207 layers,
1208 0,
1209 pixelFormat, pixelType, nullptr);
1210 } else {
1211 qWarning("Array textures are not supported");
1212 return;
1213 }
1214 break;
1215
1216 case QOpenGLTexture::TargetCubeMapArray:
1217 // Cubemap arrays must specify number of layer-faces (6 * layers) as depth parameter
1218 if (features.testFlag(QOpenGLTexture::TextureCubeMapArrays)) {
1219 for (int level = 0; level < mipLevels; ++level)
1220 texFuncs->glTextureImage3D(textureId, target, bindingTarget, level, format,
1221 mipLevelSize(level, dimensions[0]),
1222 mipLevelSize(level, dimensions[1]),
1223 6 * layers,
1224 0,
1225 pixelFormat, pixelType, nullptr);
1226 } else {
1227 qWarning("Cubemap Array textures are not supported");
1228 return;
1229 }
1230 break;
1231
1232 case QOpenGLTexture::Target3D:
1233 if (features.testFlag(QOpenGLTexture::Texture3D)) {
1234 for (int level = 0; level < mipLevels; ++level)
1235 texFuncs->glTextureImage3D(textureId, target, bindingTarget, level, format,
1236 mipLevelSize(level, dimensions[0]),
1237 mipLevelSize(level, dimensions[1]),
1238 mipLevelSize(level, dimensions[2]),
1239 0,
1240 pixelFormat, pixelType, nullptr);
1241 } else {
1242 qWarning("3D textures are not supported");
1243 return;
1244 }
1245 break;
1246
1247 case QOpenGLTexture::Target2DMultisample:
1248 if (features.testFlag(QOpenGLTexture::TextureMultisample)) {
1249 texFuncs->glTextureImage2DMultisample(textureId, target, bindingTarget, samples, format,
1250 dimensions[0], dimensions[1],
1251 fixedSamplePositions);
1252 } else {
1253 qWarning("Multisample textures are not supported");
1254 return;
1255 }
1256 break;
1257
1258 case QOpenGLTexture::Target2DMultisampleArray:
1259 if (features.testFlag(QOpenGLTexture::TextureMultisample)
1260 && features.testFlag(QOpenGLTexture::TextureArrays)) {
1261 texFuncs->glTextureImage3DMultisample(textureId, target, bindingTarget, samples, format,
1262 dimensions[0], dimensions[1], layers,
1263 fixedSamplePositions);
1264 } else {
1265 qWarning("Multisample array textures are not supported");
1266 return;
1267 }
1268 break;
1269 }
1270
1271 storageAllocated = true;
1272}
1273
1274void QOpenGLTexturePrivate::allocateImmutableStorage()
1275{
1276 switch (target) {
1277 case QOpenGLTexture::TargetBuffer:
1278 // Buffer textures get their storage from an external OpenGL buffer
1279 qWarning("Buffer textures do not allocate storage");
1280 return;
1281
1282 case QOpenGLTexture::Target1D:
1283 if (features.testFlag(QOpenGLTexture::Texture1D)) {
1284 texFuncs->glTextureStorage1D(textureId, target, bindingTarget, mipLevels, format,
1285 dimensions[0]);
1286 } else {
1287 qWarning("1D textures are not supported");
1288 return;
1289 }
1290 break;
1291
1292 case QOpenGLTexture::Target1DArray:
1293 if (features.testFlag(QOpenGLTexture::Texture1D)
1294 && features.testFlag(QOpenGLTexture::TextureArrays)) {
1295 texFuncs->glTextureStorage2D(textureId, target, bindingTarget, mipLevels, format,
1296 dimensions[0], layers);
1297 } else {
1298 qWarning("1D array textures are not supported");
1299 return;
1300 }
1301 break;
1302
1303 case QOpenGLTexture::Target2D:
1304 case QOpenGLTexture::TargetCubeMap:
1305 case QOpenGLTexture::TargetRectangle:
1306 texFuncs->glTextureStorage2D(textureId, target, bindingTarget, mipLevels, format,
1307 dimensions[0], dimensions[1]);
1308 break;
1309
1310 case QOpenGLTexture::Target2DArray:
1311 if (features.testFlag(QOpenGLTexture::TextureArrays)) {
1312 texFuncs->glTextureStorage3D(textureId, target, bindingTarget, mipLevels, format,
1313 dimensions[0], dimensions[1], layers);
1314 } else {
1315 qWarning("Array textures are not supported");
1316 return;
1317 }
1318 break;
1319
1320 case QOpenGLTexture::TargetCubeMapArray:
1321 // Cubemap arrays must specify number of layer-faces (6 * layers) as depth parameter
1322 if (features.testFlag(QOpenGLTexture::TextureCubeMapArrays)) {
1323 texFuncs->glTextureStorage3D(textureId, target, bindingTarget, mipLevels, format,
1324 dimensions[0], dimensions[1], 6 * layers);
1325 } else {
1326 qWarning("Cubemap Array textures are not supported");
1327 return;
1328 }
1329 break;
1330
1331 case QOpenGLTexture::Target3D:
1332 if (features.testFlag(QOpenGLTexture::Texture3D)) {
1333 texFuncs->glTextureStorage3D(textureId, target, bindingTarget, mipLevels, format,
1334 dimensions[0], dimensions[1], dimensions[2]);
1335 } else {
1336 qWarning("3D textures are not supported");
1337 return;
1338 }
1339 break;
1340
1341 case QOpenGLTexture::Target2DMultisample:
1342 if (features.testFlag(QOpenGLTexture::ImmutableMultisampleStorage)) {
1343 texFuncs->glTextureStorage2DMultisample(textureId, target, bindingTarget, samples, format,
1344 dimensions[0], dimensions[1],
1345 fixedSamplePositions);
1346 } else {
1347 qWarning("Multisample textures are not supported");
1348 return;
1349 }
1350 break;
1351
1352 case QOpenGLTexture::Target2DMultisampleArray:
1353 if (features.testFlag(QOpenGLTexture::ImmutableMultisampleStorage)
1354 && features.testFlag(QOpenGLTexture::TextureArrays)) {
1355 texFuncs->glTextureStorage3DMultisample(textureId, target, bindingTarget, samples, format,
1356 dimensions[0], dimensions[1], layers,
1357 fixedSamplePositions);
1358 } else {
1359 qWarning("Multisample array textures are not supported");
1360 return;
1361 }
1362 break;
1363 }
1364
1365 storageAllocated = true;
1366}
1367
1368void QOpenGLTexturePrivate::setData(int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace,
1369 QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType,
1370 const void *data, const QOpenGLPixelTransferOptions * const options)
1371{
1372 switch (target) {
1373 case QOpenGLTexture::Target1D:
1374 Q_UNUSED(layer);
1375 Q_UNUSED(cubeFace);
1376 Q_UNUSED(layerCount);
1377 texFuncs->glTextureSubImage1D(textureId, target, bindingTarget, mipLevel,
1378 0, mipLevelSize( mipLevel, dimensions[0] ),
1379 sourceFormat, sourceType, data, options);
1380 break;
1381
1382 case QOpenGLTexture::Target1DArray:
1383 Q_UNUSED(cubeFace);
1384 texFuncs->glTextureSubImage2D(textureId, target, bindingTarget, mipLevel,
1385 0, layer,
1386 mipLevelSize(mipLevel, dimensions[0]),
1387 layerCount,
1388 sourceFormat, sourceType, data, options);
1389 break;
1390
1391 case QOpenGLTexture::Target2D:
1392 Q_UNUSED(layer);
1393 Q_UNUSED(cubeFace);
1394 Q_UNUSED(layerCount);
1395 texFuncs->glTextureSubImage2D(textureId, target, bindingTarget, mipLevel,
1396 0, 0,
1397 mipLevelSize(mipLevel, dimensions[0]),
1398 mipLevelSize(mipLevel, dimensions[1]),
1399 sourceFormat, sourceType, data, options);
1400 break;
1401
1402 case QOpenGLTexture::Target2DArray:
1403 Q_UNUSED(cubeFace);
1404 texFuncs->glTextureSubImage3D(textureId, target, bindingTarget, mipLevel,
1405 0, 0, layer,
1406 mipLevelSize(mipLevel, dimensions[0]),
1407 mipLevelSize(mipLevel, dimensions[1]),
1408 layerCount,
1409 sourceFormat, sourceType, data, options);
1410 break;
1411
1412 case QOpenGLTexture::Target3D:
1413 Q_UNUSED(cubeFace);
1414 Q_UNUSED(layerCount);
1415 texFuncs->glTextureSubImage3D(textureId, target, bindingTarget, mipLevel,
1416 0, 0, layer,
1417 mipLevelSize(mipLevel, dimensions[0]),
1418 mipLevelSize(mipLevel, dimensions[1]),
1419 mipLevelSize(mipLevel, dimensions[2]),
1420 sourceFormat, sourceType, data, options);
1421 break;
1422
1423 case QOpenGLTexture::TargetCubeMap:
1424 Q_UNUSED(layer);
1425 Q_UNUSED(layerCount);
1426 texFuncs->glTextureSubImage2D(textureId, cubeFace, bindingTarget, mipLevel,
1427 0, 0,
1428 mipLevelSize(mipLevel, dimensions[0]),
1429 mipLevelSize(mipLevel, dimensions[1]),
1430 sourceFormat, sourceType, data, options);
1431 break;
1432
1433 case QOpenGLTexture::TargetCubeMapArray: {
1434 int faceIndex = cubeFace - QOpenGLTexture::CubeMapPositiveX;
1435 int layerFace = 6 * layer + faceIndex;
1436 texFuncs->glTextureSubImage3D(textureId, target, bindingTarget, mipLevel,
1437 0, 0, layerFace,
1438 mipLevelSize(mipLevel, dimensions[0]),
1439 mipLevelSize(mipLevel, dimensions[1]),
1440 layerCount,
1441 sourceFormat, sourceType, data, options);
1442 break;
1443 }
1444
1445 case QOpenGLTexture::TargetRectangle:
1446 Q_UNUSED(mipLevel);
1447 Q_UNUSED(layer);
1448 Q_UNUSED(cubeFace);
1449 Q_UNUSED(layerCount);
1450 texFuncs->glTextureSubImage2D(textureId, target, bindingTarget, 0,
1451 0, 0,
1452 dimensions[0],
1453 dimensions[1],
1454 sourceFormat, sourceType, data, options);
1455 break;
1456
1457 case QOpenGLTexture::Target2DMultisample:
1458 case QOpenGLTexture::Target2DMultisampleArray:
1459 case QOpenGLTexture::TargetBuffer:
1460 // We don't upload pixel data for these targets
1461 qWarning("QOpenGLTexture::setData(): Texture target does not support pixel data upload");
1462 break;
1463 }
1464
1465 // If requested perform automatic mip map generation
1466 if (mipLevel == 0 && autoGenerateMipMaps && mipLevels > 1) {
1467 Q_Q(QOpenGLTexture);
1468 q->generateMipMaps();
1469 }
1470}
1471
1472void QOpenGLTexturePrivate::setData(int xOffset, int yOffset, int zOffset, int width, int height, int depth,
1473 int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace,
1474 QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType,
1475 const void *data, const QOpenGLPixelTransferOptions * const options)
1476{
1477 switch (target) {
1478 case QOpenGLTexture::Target1D:
1479 Q_UNUSED(layer);
1480 Q_UNUSED(cubeFace);
1481 Q_UNUSED(layerCount);
1482 Q_UNUSED(yOffset);
1483 Q_UNUSED(zOffset);
1484 Q_UNUSED(height);
1485 Q_UNUSED(depth);
1486 texFuncs->glTextureSubImage1D(textureId, target, bindingTarget, mipLevel,
1487 xOffset, width,
1488 sourceFormat, sourceType, data, options);
1489 break;
1490
1491 case QOpenGLTexture::Target1DArray:
1492 Q_UNUSED(cubeFace);
1493 Q_UNUSED(yOffset);
1494 Q_UNUSED(zOffset);
1495 Q_UNUSED(height);
1496 Q_UNUSED(depth);
1497 texFuncs->glTextureSubImage2D(textureId, target, bindingTarget, mipLevel,
1498 xOffset, layer,
1499 width,
1500 layerCount,
1501 sourceFormat, sourceType, data, options);
1502 break;
1503
1504 case QOpenGLTexture::Target2D:
1505 Q_UNUSED(layer);
1506 Q_UNUSED(cubeFace);
1507 Q_UNUSED(layerCount);
1508 Q_UNUSED(zOffset);
1509 Q_UNUSED(depth);
1510 texFuncs->glTextureSubImage2D(textureId, target, bindingTarget, mipLevel,
1511 xOffset, yOffset,
1512 width, height,
1513 sourceFormat, sourceType, data, options);
1514 break;
1515
1516 case QOpenGLTexture::Target2DArray:
1517 Q_UNUSED(cubeFace);
1518 Q_UNUSED(zOffset);
1519 Q_UNUSED(depth);
1520 texFuncs->glTextureSubImage3D(textureId, target, bindingTarget, mipLevel,
1521 xOffset, yOffset, layer,
1522 width, height, layerCount,
1523 sourceFormat, sourceType, data, options);
1524 break;
1525
1526 case QOpenGLTexture::Target3D:
1527 Q_UNUSED(cubeFace);
1528 Q_UNUSED(layerCount);
1529 texFuncs->glTextureSubImage3D(textureId, target, bindingTarget, mipLevel,
1530 xOffset, yOffset, zOffset,
1531 width, height, depth,
1532 sourceFormat, sourceType, data, options);
1533 break;
1534
1535 case QOpenGLTexture::TargetCubeMap:
1536 Q_UNUSED(layer);
1537 Q_UNUSED(layerCount);
1538 Q_UNUSED(zOffset);
1539 Q_UNUSED(depth);
1540 texFuncs->glTextureSubImage2D(textureId, cubeFace, bindingTarget, mipLevel,
1541 xOffset, yOffset,
1542 width, height,
1543 sourceFormat, sourceType, data, options);
1544 break;
1545
1546 case QOpenGLTexture::TargetCubeMapArray: {
1547 Q_UNUSED(zOffset);
1548 Q_UNUSED(depth);
1549 int faceIndex = cubeFace - QOpenGLTexture::CubeMapPositiveX;
1550 int layerFace = 6 * layer + faceIndex;
1551 texFuncs->glTextureSubImage3D(textureId, target, bindingTarget, mipLevel,
1552 xOffset, yOffset, layerFace,
1553 width, height,
1554 layerCount,
1555 sourceFormat, sourceType, data, options);
1556 break;
1557 }
1558
1559 case QOpenGLTexture::TargetRectangle:
1560 Q_UNUSED(mipLevel);
1561 Q_UNUSED(layer);
1562 Q_UNUSED(cubeFace);
1563 Q_UNUSED(layerCount);
1564 Q_UNUSED(zOffset);
1565 Q_UNUSED(depth);
1566 texFuncs->glTextureSubImage2D(textureId, target, bindingTarget, 0,
1567 xOffset, yOffset,
1568 width, height,
1569 sourceFormat, sourceType, data, options);
1570 break;
1571
1572 case QOpenGLTexture::Target2DMultisample:
1573 case QOpenGLTexture::Target2DMultisampleArray:
1574 case QOpenGLTexture::TargetBuffer:
1575 // We don't upload pixel data for these targets
1576 qWarning("QOpenGLTexture::setData(): Texture target does not support pixel data upload");
1577 break;
1578 }
1579
1580 // If requested perform automatic mip map generation
1581 if (mipLevel == 0 && autoGenerateMipMaps && mipLevels > 1) {
1582 Q_Q(QOpenGLTexture);
1583 q->generateMipMaps();
1584 }
1585}
1586
1587
1588void QOpenGLTexturePrivate::setCompressedData(int mipLevel, int layer, int layerCount,
1589 QOpenGLTexture::CubeMapFace cubeFace,
1590 int dataSize, const void *data,
1591 const QOpenGLPixelTransferOptions * const options)
1592{
1593 if (!isCompressedFormat(format)) {
1594 qWarning("Cannot set compressed data for non-compressed format 0x%x", format);
1595 return;
1596 }
1597
1598 const bool needsFullSpec = !isUsingImmutableStorage(); // was allocateStorage() a no-op?
1599
1600 switch (target) {
1601 case QOpenGLTexture::Target1D:
1602 Q_UNUSED(layer);
1603 Q_UNUSED(cubeFace);
1604 Q_UNUSED(layerCount);
1605 if (needsFullSpec) {
1606 texFuncs->glCompressedTextureImage1D(textureId, target, bindingTarget, mipLevel,
1607 format,
1608 mipLevelSize(mipLevel, dimensions[0]),
1609 0, dataSize, data, options);
1610 } else {
1611 texFuncs->glCompressedTextureSubImage1D(textureId, target, bindingTarget, mipLevel,
1612 0, mipLevelSize( mipLevel, dimensions[0] ),
1613 format, dataSize, data, options);
1614 }
1615 break;
1616
1617 case QOpenGLTexture::Target1DArray:
1618 Q_UNUSED(cubeFace);
1619 if (!needsFullSpec) {
1620 texFuncs->glCompressedTextureSubImage2D(textureId, target, bindingTarget, mipLevel,
1621 0, layer,
1622 mipLevelSize(mipLevel, dimensions[0]),
1623 layerCount,
1624 format, dataSize, data, options);
1625 }
1626 break;
1627
1628 case QOpenGLTexture::Target2D:
1629 Q_UNUSED(layer);
1630 Q_UNUSED(cubeFace);
1631 Q_UNUSED(layerCount);
1632 if (needsFullSpec) {
1633 texFuncs->glCompressedTextureImage2D(textureId, target, bindingTarget, mipLevel,
1634 format,
1635 mipLevelSize(mipLevel, dimensions[0]),
1636 mipLevelSize(mipLevel, dimensions[1]),
1637 0, dataSize, data, options);
1638 } else {
1639 texFuncs->glCompressedTextureSubImage2D(textureId, target, bindingTarget, mipLevel,
1640 0, 0,
1641 mipLevelSize(mipLevel, dimensions[0]),
1642 mipLevelSize(mipLevel, dimensions[1]),
1643 format, dataSize, data, options);
1644 }
1645 break;
1646
1647 case QOpenGLTexture::Target2DArray:
1648 Q_UNUSED(cubeFace);
1649 if (!needsFullSpec) {
1650 texFuncs->glCompressedTextureSubImage3D(textureId, target, bindingTarget, mipLevel,
1651 0, 0, layer,
1652 mipLevelSize(mipLevel, dimensions[0]),
1653 mipLevelSize(mipLevel, dimensions[1]),
1654 layerCount,
1655 format, dataSize, data, options);
1656 }
1657 break;
1658
1659 case QOpenGLTexture::Target3D:
1660 Q_UNUSED(cubeFace);
1661 Q_UNUSED(layerCount);
1662 if (needsFullSpec) {
1663 texFuncs->glCompressedTextureImage3D(textureId, target, bindingTarget, mipLevel,
1664 format,
1665 mipLevelSize(mipLevel, dimensions[0]),
1666 mipLevelSize(mipLevel, dimensions[1]),
1667 mipLevelSize(mipLevel, dimensions[2]),
1668 0, dataSize, data, options);
1669 } else {
1670 texFuncs->glCompressedTextureSubImage3D(textureId, target, bindingTarget, mipLevel,
1671 0, 0, layer,
1672 mipLevelSize(mipLevel, dimensions[0]),
1673 mipLevelSize(mipLevel, dimensions[1]),
1674 mipLevelSize(mipLevel, dimensions[2]),
1675 format, dataSize, data, options);
1676 }
1677 break;
1678
1679 case QOpenGLTexture::TargetCubeMap:
1680 Q_UNUSED(layer);
1681 Q_UNUSED(layerCount);
1682 if (needsFullSpec) {
1683 texFuncs->glCompressedTextureImage2D(textureId, cubeFace, bindingTarget, mipLevel,
1684 format,
1685 mipLevelSize(mipLevel, dimensions[0]),
1686 mipLevelSize(mipLevel, dimensions[1]),
1687 0, dataSize, data, options);
1688 } else {
1689 texFuncs->glCompressedTextureSubImage2D(textureId, cubeFace, bindingTarget, mipLevel,
1690 0, 0,
1691 mipLevelSize(mipLevel, dimensions[0]),
1692 mipLevelSize(mipLevel, dimensions[1]),
1693 format, dataSize, data, options);
1694 }
1695 break;
1696
1697 case QOpenGLTexture::TargetCubeMapArray: {
1698 int faceIndex = cubeFace - QOpenGLTexture::CubeMapPositiveX;
1699 int layerFace = 6 * layer + faceIndex;
1700 if (!needsFullSpec) {
1701 texFuncs->glCompressedTextureSubImage3D(textureId, target, bindingTarget, mipLevel,
1702 0, 0, layerFace,
1703 mipLevelSize(mipLevel, dimensions[0]),
1704 mipLevelSize(mipLevel, dimensions[1]),
1705 layerCount,
1706 format, dataSize, data, options);
1707 }
1708 break;
1709 }
1710
1711 case QOpenGLTexture::TargetRectangle:
1712 case QOpenGLTexture::Target2DMultisample:
1713 case QOpenGLTexture::Target2DMultisampleArray:
1714 case QOpenGLTexture::TargetBuffer:
1715 // We don't upload pixel data for these targets
1716 qWarning("QOpenGLTexture::setCompressedData(): Texture target does not support pixel data upload");
1717 break;
1718 }
1719
1720 // If requested perform automatic mip map generation
1721 if (mipLevel == 0 && autoGenerateMipMaps && mipLevels > 1) {
1722 Q_Q(QOpenGLTexture);
1723 q->generateMipMaps();
1724 }
1725}
1726
1727void QOpenGLTexturePrivate::setWrapMode(QOpenGLTexture::WrapMode mode)
1728{
1729 switch (target) {
1730 case QOpenGLTexture::Target1D:
1731 case QOpenGLTexture::Target1DArray:
1732 case QOpenGLTexture::TargetBuffer:
1733 wrapModes[0] = mode;
1734 texFuncs->glTextureParameteri(textureId, target, bindingTarget, GL_TEXTURE_WRAP_S, mode);
1735 break;
1736
1737 case QOpenGLTexture::Target2D:
1738 case QOpenGLTexture::Target2DArray:
1739 case QOpenGLTexture::TargetCubeMap:
1740 case QOpenGLTexture::TargetCubeMapArray:
1741 case QOpenGLTexture::Target2DMultisample:
1742 case QOpenGLTexture::Target2DMultisampleArray:
1743 case QOpenGLTexture::TargetRectangle:
1744 wrapModes[0] = wrapModes[1] = mode;
1745 texFuncs->glTextureParameteri(textureId, target, bindingTarget, GL_TEXTURE_WRAP_S, mode);
1746 texFuncs->glTextureParameteri(textureId, target, bindingTarget, GL_TEXTURE_WRAP_T, mode);
1747 break;
1748
1749 case QOpenGLTexture::Target3D:
1750 wrapModes[0] = wrapModes[1] = wrapModes[2] = mode;
1751 texFuncs->glTextureParameteri(textureId, target, bindingTarget, GL_TEXTURE_WRAP_S, mode);
1752 texFuncs->glTextureParameteri(textureId, target, bindingTarget, GL_TEXTURE_WRAP_T, mode);
1753 texFuncs->glTextureParameteri(textureId, target, bindingTarget, GL_TEXTURE_WRAP_R, mode);
1754 break;
1755 }
1756}
1757
1758void QOpenGLTexturePrivate::setWrapMode(QOpenGLTexture::CoordinateDirection direction, QOpenGLTexture::WrapMode mode)
1759{
1760 switch (target) {
1761 case QOpenGLTexture::Target1D:
1762 case QOpenGLTexture::Target1DArray:
1763 case QOpenGLTexture::TargetBuffer:
1764 switch (direction) {
1765 case QOpenGLTexture::DirectionS:
1766 wrapModes[0] = mode;
1767 texFuncs->glTextureParameteri(textureId, target, bindingTarget, GL_TEXTURE_WRAP_S, mode);
1768 break;
1769
1770 case QOpenGLTexture::DirectionT:
1771 case QOpenGLTexture::DirectionR:
1772 qWarning("QOpenGLTexture::setWrapMode() direction not valid for this texture target");
1773 break;
1774 }
1775 break;
1776
1777 case QOpenGLTexture::Target2D:
1778 case QOpenGLTexture::Target2DArray:
1779 case QOpenGLTexture::TargetCubeMap:
1780 case QOpenGLTexture::TargetCubeMapArray:
1781 case QOpenGLTexture::Target2DMultisample:
1782 case QOpenGLTexture::Target2DMultisampleArray:
1783 case QOpenGLTexture::TargetRectangle:
1784 switch (direction) {
1785 case QOpenGLTexture::DirectionS:
1786 wrapModes[0] = mode;
1787 texFuncs->glTextureParameteri(textureId, target, bindingTarget, GL_TEXTURE_WRAP_S, mode);
1788 break;
1789
1790 case QOpenGLTexture::DirectionT:
1791 wrapModes[1] = mode;
1792 texFuncs->glTextureParameteri(textureId, target, bindingTarget, GL_TEXTURE_WRAP_T, mode);
1793 break;
1794
1795 case QOpenGLTexture::DirectionR:
1796 qWarning("QOpenGLTexture::setWrapMode() direction not valid for this texture target");
1797 break;
1798 }
1799 break;
1800
1801 case QOpenGLTexture::Target3D:
1802 switch (direction) {
1803 case QOpenGLTexture::DirectionS:
1804 wrapModes[0] = mode;
1805 texFuncs->glTextureParameteri(textureId, target, bindingTarget, direction, mode);
1806 break;
1807
1808 case QOpenGLTexture::DirectionT:
1809 wrapModes[1] = mode;
1810 texFuncs->glTextureParameteri(textureId, target, bindingTarget, direction, mode);
1811 break;
1812
1813 case QOpenGLTexture::DirectionR:
1814 wrapModes[2] = mode;
1815 texFuncs->glTextureParameteri(textureId, target, bindingTarget, direction, mode);
1816 break;
1817 }
1818 break;
1819 }
1820}
1821
1822QOpenGLTexture::WrapMode QOpenGLTexturePrivate::wrapMode(QOpenGLTexture::CoordinateDirection direction) const
1823{
1824 switch (target) {
1825 case QOpenGLTexture::Target1D:
1826 case QOpenGLTexture::Target1DArray:
1827 case QOpenGLTexture::TargetBuffer:
1828 switch (direction) {
1829 case QOpenGLTexture::DirectionS:
1830 return wrapModes[0];
1831
1832 case QOpenGLTexture::DirectionT:
1833 case QOpenGLTexture::DirectionR:
1834 qWarning("QOpenGLTexture::wrapMode() direction not valid for this texture target");
1835 return QOpenGLTexture::Repeat;
1836 }
1837 break;
1838
1839 case QOpenGLTexture::Target2D:
1840 case QOpenGLTexture::Target2DArray:
1841 case QOpenGLTexture::TargetCubeMap:
1842 case QOpenGLTexture::TargetCubeMapArray:
1843 case QOpenGLTexture::Target2DMultisample:
1844 case QOpenGLTexture::Target2DMultisampleArray:
1845 case QOpenGLTexture::TargetRectangle:
1846 switch (direction) {
1847 case QOpenGLTexture::DirectionS:
1848 return wrapModes[0];
1849
1850 case QOpenGLTexture::DirectionT:
1851 return wrapModes[1];
1852
1853 case QOpenGLTexture::DirectionR:
1854 qWarning("QOpenGLTexture::wrapMode() direction not valid for this texture target");
1855 return QOpenGLTexture::Repeat;
1856 }
1857 break;
1858
1859 case QOpenGLTexture::Target3D:
1860 switch (direction) {
1861 case QOpenGLTexture::DirectionS:
1862 return wrapModes[0];
1863
1864 case QOpenGLTexture::DirectionT:
1865 return wrapModes[1];
1866
1867 case QOpenGLTexture::DirectionR:
1868 return wrapModes[2];
1869 }
1870 break;
1871 }
1872 // Should never get here
1873 Q_ASSERT(false);
1874 return QOpenGLTexture::Repeat;
1875}
1876
1877QOpenGLTexture *QOpenGLTexturePrivate::createTextureView(QOpenGLTexture::Target viewTarget,
1878 QOpenGLTexture::TextureFormat viewFormat,
1879 int minimumMipmapLevel, int maximumMipmapLevel,
1880 int minimumLayer, int maximumLayer) const
1881{
1882 // Do sanity checks - see http://www.opengl.org/wiki/GLAPI/glTextureView
1883
1884 // Check the targets are compatible
1885 bool viewTargetCompatible = false;
1886 switch (target) {
1887 case QOpenGLTexture::Target1D:
1888 case QOpenGLTexture::Target1DArray:
1889 viewTargetCompatible = (viewTarget == QOpenGLTexture::Target1D
1890 || viewTarget == QOpenGLTexture::Target1DArray);
1891 break;
1892
1893
1894 case QOpenGLTexture::Target2D:
1895 case QOpenGLTexture::Target2DArray:
1896 viewTargetCompatible = (viewTarget == QOpenGLTexture::Target2D
1897 || viewTarget == QOpenGLTexture::Target2DArray);
1898 break;
1899
1900 case QOpenGLTexture::Target3D:
1901 viewTargetCompatible = (viewTarget == QOpenGLTexture::Target3D);
1902 break;
1903
1904 case QOpenGLTexture::TargetCubeMap:
1905 case QOpenGLTexture::TargetCubeMapArray:
1906 viewTargetCompatible = (viewTarget == QOpenGLTexture::TargetCubeMap
1907 || viewTarget == QOpenGLTexture::Target2D
1908 || viewTarget == QOpenGLTexture::Target2DArray
1909 || viewTarget == QOpenGLTexture::TargetCubeMapArray);
1910 break;
1911
1912 case QOpenGLTexture::Target2DMultisample:
1913 case QOpenGLTexture::Target2DMultisampleArray:
1914 viewTargetCompatible = (viewTarget == QOpenGLTexture::Target2DMultisample
1915 || viewTarget == QOpenGLTexture::Target2DMultisampleArray);
1916 break;
1917
1918 case QOpenGLTexture::TargetRectangle:
1919 viewTargetCompatible = (viewTarget == QOpenGLTexture::TargetRectangle);
1920 break;
1921
1922 case QOpenGLTexture::TargetBuffer:
1923 // Cannot be used with texture views
1924 break;
1925 }
1926
1927 if (!viewTargetCompatible) {
1928 qWarning("QOpenGLTexture::createTextureView(): Incompatible source and view targets");
1929 return nullptr;
1930 }
1931
1932 // Check the formats are compatible
1933 bool viewFormatCompatible = false;
1934 switch (formatClass) {
1935 case QOpenGLTexture::NoFormatClass:
1936 break;
1937
1938 case QOpenGLTexture::FormatClass_128Bit:
1939 viewFormatCompatible = (viewFormat == QOpenGLTexture::RGBA32F
1940 || viewFormat == QOpenGLTexture::RGBA32U
1941 || viewFormat == QOpenGLTexture::RGBA32I);
1942 break;
1943
1944 case QOpenGLTexture::FormatClass_96Bit:
1945 viewFormatCompatible = (viewFormat == QOpenGLTexture::RGB32F
1946 || viewFormat == QOpenGLTexture::RGB32U
1947 || viewFormat == QOpenGLTexture::RGB32I);
1948 break;
1949
1950 case QOpenGLTexture::FormatClass_64Bit:
1951 viewFormatCompatible = (viewFormat == QOpenGLTexture::RGBA16F
1952 || viewFormat == QOpenGLTexture::RG32F
1953 || viewFormat == QOpenGLTexture::RGBA16U
1954 || viewFormat == QOpenGLTexture::RG32U
1955 || viewFormat == QOpenGLTexture::RGBA16I
1956 || viewFormat == QOpenGLTexture::RG32I
1957 || viewFormat == QOpenGLTexture::RGBA16_UNorm
1958 || viewFormat == QOpenGLTexture::RGBA16_SNorm);
1959 break;
1960
1961 case QOpenGLTexture::FormatClass_48Bit:
1962 viewFormatCompatible = (viewFormat == QOpenGLTexture::RGB16_UNorm
1963 || viewFormat == QOpenGLTexture::RGB16_SNorm
1964 || viewFormat == QOpenGLTexture::RGB16F
1965 || viewFormat == QOpenGLTexture::RGB16U
1966 || viewFormat == QOpenGLTexture::RGB16I);
1967 break;
1968
1969 case QOpenGLTexture::FormatClass_32Bit:
1970 viewFormatCompatible = (viewFormat == QOpenGLTexture::RG16F
1971 || viewFormat == QOpenGLTexture::RG11B10F
1972 || viewFormat == QOpenGLTexture::R32F
1973 || viewFormat == QOpenGLTexture::RGB10A2
1974 || viewFormat == QOpenGLTexture::RGBA8U
1975 || viewFormat == QOpenGLTexture::RG16U
1976 || viewFormat == QOpenGLTexture::R32U
1977 || viewFormat == QOpenGLTexture::RGBA8I
1978 || viewFormat == QOpenGLTexture::RG16I
1979 || viewFormat == QOpenGLTexture::R32I
1980 || viewFormat == QOpenGLTexture::RGBA8_UNorm
1981 || viewFormat == QOpenGLTexture::RG16_UNorm
1982 || viewFormat == QOpenGLTexture::RGBA8_SNorm
1983 || viewFormat == QOpenGLTexture::RG16_SNorm
1984 || viewFormat == QOpenGLTexture::SRGB8_Alpha8
1985 || viewFormat == QOpenGLTexture::RGB9E5);
1986 break;
1987
1988 case QOpenGLTexture::FormatClass_24Bit:
1989 viewFormatCompatible = (viewFormat == QOpenGLTexture::RGB8_UNorm
1990 || viewFormat == QOpenGLTexture::RGB8_SNorm
1991 || viewFormat == QOpenGLTexture::SRGB8
1992 || viewFormat == QOpenGLTexture::RGB8U
1993 || viewFormat == QOpenGLTexture::RGB8I);
1994 break;
1995
1996 case QOpenGLTexture::FormatClass_16Bit:
1997 viewFormatCompatible = (viewFormat == QOpenGLTexture::R16F
1998 || viewFormat == QOpenGLTexture::RG8U
1999 || viewFormat == QOpenGLTexture::R16U
2000 || viewFormat == QOpenGLTexture::RG8I
2001 || viewFormat == QOpenGLTexture::R16I
2002 || viewFormat == QOpenGLTexture::RG8_UNorm
2003 || viewFormat == QOpenGLTexture::R16_UNorm
2004 || viewFormat == QOpenGLTexture::RG8_SNorm
2005 || viewFormat == QOpenGLTexture::R16_SNorm);
2006 break;
2007
2008 case QOpenGLTexture::FormatClass_8Bit:
2009 viewFormatCompatible = (viewFormat == QOpenGLTexture::R8U
2010 || viewFormat == QOpenGLTexture::R8I
2011 || viewFormat == QOpenGLTexture::R8_UNorm
2012 || viewFormat == QOpenGLTexture::R8_SNorm);
2013 break;
2014
2015 case QOpenGLTexture::FormatClass_RGTC1_R:
2016 viewFormatCompatible = (viewFormat == QOpenGLTexture::R_ATI1N_UNorm
2017 || viewFormat == QOpenGLTexture::R_ATI1N_SNorm);
2018 break;
2019
2020 case QOpenGLTexture::FormatClass_RGTC2_RG:
2021 viewFormatCompatible = (viewFormat == QOpenGLTexture::RG_ATI2N_UNorm
2022 || viewFormat == QOpenGLTexture::RG_ATI2N_SNorm);
2023 break;
2024
2025 case QOpenGLTexture::FormatClass_BPTC_Unorm:
2026 viewFormatCompatible = (viewFormat == QOpenGLTexture::RGB_BP_UNorm
2027 || viewFormat == QOpenGLTexture::SRGB_BP_UNorm);
2028 break;
2029
2030 case QOpenGLTexture::FormatClass_BPTC_Float:
2031 viewFormatCompatible = (viewFormat == QOpenGLTexture::RGB_BP_UNSIGNED_FLOAT
2032 || viewFormat == QOpenGLTexture::RGB_BP_SIGNED_FLOAT);
2033 break;
2034
2035 case QOpenGLTexture::FormatClass_S3TC_DXT1_RGB:
2036 viewFormatCompatible = (viewFormat == QOpenGLTexture::RGB_DXT1
2037 || viewFormat == QOpenGLTexture::SRGB_DXT1);
2038 break;
2039
2040 case QOpenGLTexture::FormatClass_S3TC_DXT1_RGBA:
2041 viewFormatCompatible = (viewFormat == QOpenGLTexture::RGBA_DXT1
2042 || viewFormat == QOpenGLTexture::SRGB_Alpha_DXT1);
2043 break;
2044
2045 case QOpenGLTexture::FormatClass_S3TC_DXT3_RGBA:
2046 viewFormatCompatible = (viewFormat == QOpenGLTexture::RGBA_DXT3
2047 || viewFormat == QOpenGLTexture::SRGB_Alpha_DXT3);
2048 break;
2049
2050 case QOpenGLTexture::FormatClass_S3TC_DXT5_RGBA:
2051 viewFormatCompatible = (viewFormat == QOpenGLTexture::RGBA_DXT5
2052 || viewFormat == QOpenGLTexture::SRGB_Alpha_DXT5);
2053 break;
2054
2055 case QOpenGLTexture::FormatClass_Unique:
2056 viewFormatCompatible = (viewFormat == format);
2057 break;
2058 }
2059
2060 if (!viewFormatCompatible) {
2061 qWarning("QOpenGLTexture::createTextureView(): Incompatible source and view formats");
2062 return nullptr;
2063 }
2064
2065
2066 // Create a view
2067 QOpenGLTexture *view = new QOpenGLTexture(viewTarget);
2068 view->setFormat(viewFormat);
2069 view->create();
2070 view->d_ptr->textureView = true;
2071 texFuncs->glTextureView(view->textureId(), viewTarget, textureId, viewFormat,
2072 minimumMipmapLevel, maximumMipmapLevel - minimumMipmapLevel + 1,
2073 minimumLayer, maximumLayer - minimumLayer + 1);
2074 return view;
2075}
2076
2077
2078/*!
2079 \class QOpenGLTexture
2080 \inmodule QtGui
2081 \since 5.2
2082 \wrapper
2083 \brief The QOpenGLTexture class encapsulates an OpenGL texture object.
2084
2085 QOpenGLTexture makes it easy to work with OpenGL textures and the myriad features
2086 and targets that they offer depending upon the capabilities of your OpenGL implementation.
2087
2088 The typical usage pattern for QOpenGLTexture is
2089 \list
2090 \li Instantiate the object specifying the texture target type
2091 \li Set properties that affect the storage requirements e.g. storage format, dimensions
2092 \li Allocate the server-side storage
2093 \li Optionally upload pixel data
2094 \li Optionally set any additional properties e.g. filtering and border options
2095 \li Render with texture or render to texture
2096 \endlist
2097
2098 In the common case of simply using a QImage as the source of texture pixel data
2099 most of the above steps are performed automatically.
2100
2101 \code
2102 // Prepare texture
2103 QOpenGLTexture *texture = new QOpenGLTexture(QImage(fileName).mirrored());
2104 texture->setMinificationFilter(QOpenGLTexture::LinearMipMapLinear);
2105 texture->setMagnificationFilter(QOpenGLTexture::Linear);
2106 ...
2107 // Render with texture
2108 texture->bind();
2109 glDrawArrays(...);
2110 \endcode
2111
2112 Note that the QImage is mirrored vertically to account for the fact that
2113 OpenGL and QImage use opposite directions for the y axis. Another option
2114 would be to transform your texture coordinates.
2115*/
2116
2117/*!
2118 \enum QOpenGLTexture::Filter
2119 This enum defines the filtering parameters for a QOpenGLTexture object.
2120 \value Nearest Equivalent to GL_NEAREST
2121 \value Linear Equivalent to GL_LINEAR
2122 \value NearestMipMapNearest Equivalent to GL_NEAREST_MIPMAP_NEAREST
2123 \value NearestMipMapLinear Equivalent to GL_NEAREST_MIPMAP_LINEAR
2124 \value LinearMipMapNearest Equivalent to GL_LINEAR_MIPMAP_NEAREST
2125 \value LinearMipMapLinear Equivalent to GL_LINEAR_MIPMAP_LINEAR
2126*/
2127
2128/*!
2129 \enum QOpenGLTexture::Target
2130 This enum defines the texture target of a QOpenGLTexture object.
2131 For more information on creating array textures, see \l{Array Texture}.
2132
2133 \value Target1D A 1-dimensional texture.
2134 Equivalent to GL_TEXTURE_1D.
2135 \value Target1DArray An array of 1-dimensional textures.
2136 Equivalent to GL_TEXTURE_1D_ARRAY
2137 \value Target2D A 2-dimensional texture.
2138 Equivalent to GL_TEXTURE_2D
2139 \value Target2DArray An array of 2-dimensional textures.
2140 Equivalent to GL_TEXTURE_2D_ARRAY
2141 \value Target3D A 3-dimensional texture.
2142 Equivalent to GL_TEXTURE_3D
2143 \value TargetCubeMap A cubemap texture.
2144 Equivalent to GL_TEXTURE_CUBE_MAP
2145 \value TargetCubeMapArray An array of cubemap textures.
2146 Equivalent to GL_TEXTURE_CUBE_MAP_ARRAY
2147 \value Target2DMultisample A 2-dimensional texture with multisample support.
2148 Equivalent to GL_TEXTURE_2D_MULTISAMPLE
2149 \value Target2DMultisampleArray An array of 2-dimensional textures with multisample support.
2150 Equivalent to GL_TEXTURE_2D_MULTISAMPLE_ARRAY
2151 \value TargetRectangle A rectangular 2-dimensional texture.
2152 Equivalent to GL_TEXTURE_RECTANGLE
2153 \value TargetBuffer A texture with data from an OpenGL buffer object.
2154 Equivalent to GL_TEXTURE_BUFFER
2155*/
2156
2157/*!
2158 \enum QOpenGLTexture::BindingTarget
2159 This enum defines the possible binding targets of texture units.
2160
2161 \value BindingTarget1D Equivalent to GL_TEXTURE_BINDING_1D
2162 \value BindingTarget1DArray Equivalent to GL_TEXTURE_BINDING_1D_ARRAY
2163 \value BindingTarget2D Equivalent to GL_TEXTURE_BINDING_2D
2164 \value BindingTarget2DArray Equivalent to GL_TEXTURE_BINDING_2D_ARRAY
2165 \value BindingTarget3D Equivalent to GL_TEXTURE_BINDING_3D
2166 \value BindingTargetCubeMap Equivalent to GL_TEXTURE_BINDING_CUBE_MAP
2167 \value BindingTargetCubeMapArray Equivalent to GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
2168 \value BindingTarget2DMultisample Equivalent to GL_TEXTURE_BINDING_2D_MULTISAMPLE
2169 \value BindingTarget2DMultisampleArray Equivalent to GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
2170 \value BindingTargetRectangle Equivalent to GL_TEXTURE_BINDING_RECTANGLE
2171 \value BindingTargetBuffer Equivalent to GL_TEXTURE_BINDING_BUFFER
2172*/
2173
2174/*!
2175 \enum QOpenGLTexture::MipMapGeneration
2176 This enum defines the options to control mipmap generation.
2177
2178 \value GenerateMipMaps Mipmaps should be generated
2179 \value DontGenerateMipMaps Mipmaps should not be generated
2180*/
2181
2182/*!
2183 \enum QOpenGLTexture::TextureUnitReset
2184 This enum defines options ot control texture unit activation.
2185
2186 \value ResetTextureUnit The previous active texture unit will be reset
2187 \value DontResetTextureUnit The previous active texture unit will not be rest
2188*/
2189
2190/*!
2191 \enum QOpenGLTexture::TextureFormat
2192 This enum defines the possible texture formats. Depending upon your OpenGL
2193 implementation only a subset of these may be supported.
2194
2195 \value NoFormat Equivalent to GL_NONE
2196
2197 \value R8_UNorm Equivalent to GL_R8
2198 \value RG8_UNorm Equivalent to GL_RG8
2199 \value RGB8_UNorm Equivalent to GL_RGB8
2200 \value RGBA8_UNorm Equivalent to GL_RGBA8
2201
2202 \value R16_UNorm Equivalent to GL_R16
2203 \value RG16_UNorm Equivalent to GL_RG16
2204 \value RGB16_UNorm Equivalent to GL_RGB16
2205 \value RGBA16_UNorm Equivalent to GL_RGBA16
2206
2207 \value R8_SNorm Equivalent to GL_R8_SNORM
2208 \value RG8_SNorm Equivalent to GL_RG8_SNORM
2209 \value RGB8_SNorm Equivalent to GL_RGB8_SNORM
2210 \value RGBA8_SNorm Equivalent to GL_RGBA8_SNORM
2211
2212 \value R16_SNorm Equivalent to GL_R16_SNORM
2213 \value RG16_SNorm Equivalent to GL_RG16_SNORM
2214 \value RGB16_SNorm Equivalent to GL_RGB16_SNORM
2215 \value RGBA16_SNorm Equivalent to GL_RGBA16_SNORM
2216
2217 \value R8U Equivalent to GL_R8UI
2218 \value RG8U Equivalent to GL_RG8UI
2219 \value RGB8U Equivalent to GL_RGB8UI
2220 \value RGBA8U Equivalent to GL_RGBA8UI
2221
2222 \value R16U Equivalent to GL_R16UI
2223 \value RG16U Equivalent to GL_RG16UI
2224 \value RGB16U Equivalent to GL_RGB16UI
2225 \value RGBA16U Equivalent to GL_RGBA16UI
2226
2227 \value R32U Equivalent to GL_R32UI
2228 \value RG32U Equivalent to GL_RG32UI
2229 \value RGB32U Equivalent to GL_RGB32UI
2230 \value RGBA32U Equivalent to GL_RGBA32UI
2231
2232 \value R8I Equivalent to GL_R8I
2233 \value RG8I Equivalent to GL_RG8I
2234 \value RGB8I Equivalent to GL_RGB8I
2235 \value RGBA8I Equivalent to GL_RGBA8I
2236
2237 \value R16I Equivalent to GL_R16I
2238 \value RG16I Equivalent to GL_RG16I
2239 \value RGB16I Equivalent to GL_RGB16I
2240 \value RGBA16I Equivalent to GL_RGBA16I
2241
2242 \value R32I Equivalent to GL_R32I
2243 \value RG32I Equivalent to GL_RG32I
2244 \value RGB32I Equivalent to GL_RGB32I
2245 \value RGBA32I Equivalent to GL_RGBA32I
2246
2247 \value R16F Equivalent to GL_R16F
2248 \value RG16F Equivalent to GL_RG16F
2249 \value RGB16F Equivalent to GL_RGB16F
2250 \value RGBA16F Equivalent to GL_RGBA16F
2251
2252 \value R32F Equivalent to GL_R32F
2253 \value RG32F Equivalent to GL_RG32F
2254 \value RGB32F Equivalent to GL_RGB32F
2255 \value RGBA32F Equivalent to GL_RGBA32F
2256
2257 \value RGB9E5 Equivalent to GL_RGB9_E5
2258 \value RG11B10F Equivalent to GL_R11F_G11F_B10F
2259 \value RG3B2 Equivalent to GL_R3_G3_B2
2260 \value R5G6B5 Equivalent to GL_RGB565
2261 \value RGB5A1 Equivalent to GL_RGB5_A1
2262 \value RGBA4 Equivalent to GL_RGBA4
2263 \value RGB10A2 Equivalent to GL_RGB10_A2UI
2264
2265 \value D16 Equivalent to GL_DEPTH_COMPONENT16
2266 \value D24 Equivalent to GL_DEPTH_COMPONENT24
2267 \value D24S8 Equivalent to GL_DEPTH24_STENCIL8
2268 \value D32 Equivalent to GL_DEPTH_COMPONENT32
2269 \value D32F Equivalent to GL_DEPTH_COMPONENT32F
2270 \value D32FS8X24 Equivalent to GL_DEPTH32F_STENCIL8
2271 \value S8 Equivalent to GL_STENCIL_INDEX8. Introduced in Qt 5.4
2272
2273 \value RGB_DXT1 Equivalent to GL_COMPRESSED_RGB_S3TC_DXT1_EXT
2274 \value RGBA_DXT1 Equivalent to GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
2275 \value RGBA_DXT3 Equivalent to GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
2276 \value RGBA_DXT5 Equivalent to GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
2277 \value R_ATI1N_UNorm Equivalent to GL_COMPRESSED_RED_RGTC1
2278 \value R_ATI1N_SNorm Equivalent to GL_COMPRESSED_SIGNED_RED_RGTC1
2279 \value RG_ATI2N_UNorm Equivalent to GL_COMPRESSED_RG_RGTC2
2280 \value RG_ATI2N_SNorm Equivalent to GL_COMPRESSED_SIGNED_RG_RGTC2
2281 \value RGB_BP_UNSIGNED_FLOAT Equivalent to GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
2282 \value RGB_BP_SIGNED_FLOAT Equivalent to GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
2283 \value RGB_BP_UNorm Equivalent to GL_COMPRESSED_RGBA_BPTC_UNORM_ARB
2284 \value R11_EAC_UNorm Equivalent to GL_COMPRESSED_R11_EAC
2285 \value R11_EAC_SNorm Equivalent to GL_COMPRESSED_SIGNED_R11_EAC
2286 \value RG11_EAC_UNorm Equivalent to GL_COMPRESSED_RG11_EAC
2287 \value RG11_EAC_SNorm Equivalent to GL_COMPRESSED_SIGNED_RG11_EAC
2288 \value RGB8_ETC2 Equivalent to GL_COMPRESSED_RGB8_ETC2
2289 \value SRGB8_ETC2 Equivalent to GL_COMPRESSED_SRGB8_ETC2
2290 \value RGB8_PunchThrough_Alpha1_ETC2 Equivalent to GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
2291 \value SRGB8_PunchThrough_Alpha1_ETC2 Equivalent to GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
2292 \value RGBA8_ETC2_EAC Equivalent to GL_COMPRESSED_RGBA8_ETC2_EAC
2293 \value SRGB8_Alpha8_ETC2_EAC Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
2294 \value RGB8_ETC1 Equivalent to GL_ETC1_RGB8_OES
2295 \value RGBA_ASTC_4x4 Equivalent to GL_COMPRESSED_RGBA_ASTC_4x4_KHR
2296 \value RGBA_ASTC_5x4 Equivalent to GL_COMPRESSED_RGBA_ASTC_5x4_KHR
2297 \value RGBA_ASTC_5x5 Equivalent to GL_COMPRESSED_RGBA_ASTC_5x5_KHR
2298 \value RGBA_ASTC_6x5 Equivalent to GL_COMPRESSED_RGBA_ASTC_6x5_KHR
2299 \value RGBA_ASTC_6x6 Equivalent to GL_COMPRESSED_RGBA_ASTC_6x6_KHR
2300 \value RGBA_ASTC_8x5 Equivalent to GL_COMPRESSED_RGBA_ASTC_8x5_KHR
2301 \value RGBA_ASTC_8x6 Equivalent to GL_COMPRESSED_RGBA_ASTC_8x6_KHR
2302 \value RGBA_ASTC_8x8 Equivalent to GL_COMPRESSED_RGBA_ASTC_8x8_KHR
2303 \value RGBA_ASTC_10x5 Equivalent to GL_COMPRESSED_RGBA_ASTC_10x5_KHR
2304 \value RGBA_ASTC_10x6 Equivalent to GL_COMPRESSED_RGBA_ASTC_10x6_KHR
2305 \value RGBA_ASTC_10x8 Equivalent to GL_COMPRESSED_RGBA_ASTC_10x8_KHR
2306 \value RGBA_ASTC_10x10 Equivalent to GL_COMPRESSED_RGBA_ASTC_10x10_KHR
2307 \value RGBA_ASTC_12x10 Equivalent to GL_COMPRESSED_RGBA_ASTC_12x10_KHR
2308 \value RGBA_ASTC_12x12 Equivalent to GL_COMPRESSED_RGBA_ASTC_12x12_KHR
2309 \value SRGB8_Alpha8_ASTC_4x4 Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
2310 \value SRGB8_Alpha8_ASTC_5x4 Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
2311 \value SRGB8_Alpha8_ASTC_5x5 Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
2312 \value SRGB8_Alpha8_ASTC_6x5 Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
2313 \value SRGB8_Alpha8_ASTC_6x6 Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
2314 \value SRGB8_Alpha8_ASTC_8x5 Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
2315 \value SRGB8_Alpha8_ASTC_8x6 Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
2316 \value SRGB8_Alpha8_ASTC_8x8 Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
2317 \value SRGB8_Alpha8_ASTC_10x5 Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
2318 \value SRGB8_Alpha8_ASTC_10x6 Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
2319 \value SRGB8_Alpha8_ASTC_10x8 Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
2320 \value SRGB8_Alpha8_ASTC_10x10 Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
2321 \value SRGB8_Alpha8_ASTC_12x10 Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
2322 \value SRGB8_Alpha8_ASTC_12x12 Equivalent to GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
2323
2324 \value SRGB8 Equivalent to GL_SRGB8
2325 \value SRGB8_Alpha8 Equivalent to GL_SRGB8_ALPHA8
2326 \value SRGB_DXT1 Equivalent to GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
2327 \value SRGB_Alpha_DXT1 Equivalent to GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
2328 \value SRGB_Alpha_DXT3 Equivalent to GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
2329 \value SRGB_Alpha_DXT5 Equivalent to GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
2330 \value SRGB_BP_UNorm Equivalent to GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB
2331
2332 \value DepthFormat Equivalent to GL_DEPTH_COMPONENT (only OpenGL ES 3 or ES 2 with OES_depth_texture)
2333 \value AlphaFormat Equivalent to GL_ALPHA (OpenGL ES 2 only)
2334 \value RGBFormat Equivalent to GL_RGB (OpenGL ES 2 only)
2335 \value RGBAFormat Equivalent to GL_RGBA (OpenGL ES 2 only)
2336 \value LuminanceFormat Equivalent to GL_LUMINANCE (OpenGL ES 2 only)
2337 \value LuminanceAlphaFormat Equivalent to GL_LUMINANCE_ALPHA (OpenGL ES 2 only)
2338*/
2339
2340/*!
2341 \enum QOpenGLTexture::CubeMapFace
2342 This enum defines the possible CubeMap faces.
2343
2344 \value CubeMapPositiveX Equivalent to GL_TEXTURE_CUBE_MAP_POSITIVE_X
2345 \value CubeMapNegativeX Equivalent to GL_TEXTURE_CUBE_MAP_NEGATIVE_X
2346 \value CubeMapPositiveY Equivalent to GL_TEXTURE_CUBE_MAP_POSITIVE_Y
2347 \value CubeMapNegativeY Equivalent to GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
2348 \value CubeMapPositiveZ Equivalent to GL_TEXTURE_CUBE_MAP_POSITIVE_Z
2349 \value CubeMapNegativeZ Equivalent to GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
2350*/
2351
2352/*!
2353 \enum QOpenGLTexture::PixelFormat
2354 This enum defines the possible client-side pixel formats for a pixel
2355 transfer operation.
2356
2357 \value NoSourceFormat Equivalent to GL_NONE
2358 \value Red Equivalent to GL_RED
2359 \value RG Equivalent to GL_RG
2360 \value RGB Equivalent to GL_RGB
2361 \value BGR Equivalent to GL_BGR
2362 \value RGBA Equivalent to GL_RGBA
2363 \value BGRA Equivalent to GL_BGRA
2364 \value Red_Integer Equivalent to GL_RED_INTEGER
2365 \value RG_Integer Equivalent to GL_RG_INTEGER
2366 \value RGB_Integer Equivalent to GL_RGB_INTEGER
2367 \value BGR_Integer Equivalent to GL_BGR_INTEGER
2368 \value RGBA_Integer Equivalent to GL_RGBA_INTEGER
2369 \value BGRA_Integer Equivalent to GL_BGRA_INTEGER
2370 \value Stencil Equivalent to GL_STENCIL_INDEX. Introduced in Qt 5.4
2371 \value Depth Equivalent to GL_DEPTH_COMPONENT
2372 \value DepthStencil Equivalent to GL_DEPTH_STENCIL
2373 \value Alpha Equivalent to GL_ALPHA (OpenGL ES 2 only)
2374 \value Luminance Equivalent to GL_LUMINANCE (OpenGL ES 2 only)
2375 \value LuminanceAlpha Equivalent to GL_LUMINANCE_ALPHA (OpenGL ES 2 only)
2376
2377*/
2378
2379/*!
2380 \enum QOpenGLTexture::PixelType
2381 This enum defines the possible pixel data types for a pixel transfer operation
2382
2383 \value NoPixelType Equivalent to GL_NONE
2384 \value Int8 Equivalent to GL_BYTE
2385 \value UInt8 Equivalent to GL_UNSIGNED_BYTE
2386 \value Int16 Equivalent to GL_SHORT
2387 \value UInt16 Equivalent to GL_UNSIGNED_SHORT
2388 \value Int32 Equivalent to GL_INT
2389 \value UInt32 Equivalent to GL_UNSIGNED_INT
2390 \value Float16 Equivalent to GL_HALF_FLOAT
2391 \value Float16OES Equivalent to GL_HALF_FLOAT_OES
2392 \value Float32 Equivalent to GL_FLOAT
2393 \value UInt32_RGB9_E5 Equivalent to GL_UNSIGNED_INT_5_9_9_9_REV
2394 \value UInt32_RG11B10F Equivalent to GL_UNSIGNED_INT_10F_11F_11F_REV
2395 \value UInt8_RG3B2 Equivalent to GL_UNSIGNED_BYTE_3_3_2
2396 \value UInt8_RG3B2_Rev Equivalent to GL_UNSIGNED_BYTE_2_3_3_REV
2397 \value UInt16_RGB5A1 Equivalent to GL_UNSIGNED_SHORT_5_5_5_1
2398 \value UInt16_RGB5A1_Rev Equivalent to GL_UNSIGNED_SHORT_1_5_5_5_REV
2399 \value UInt16_R5G6B5 Equivalent to GL_UNSIGNED_SHORT_5_6_5
2400 \value UInt16_R5G6B5_Rev Equivalent to GL_UNSIGNED_SHORT_5_6_5_REV
2401 \value UInt16_RGBA4 Equivalent to GL_UNSIGNED_SHORT_4_4_4_4
2402 \value UInt16_RGBA4_Rev Equivalent to GL_UNSIGNED_SHORT_4_4_4_4_REV
2403 \value UInt32_RGBA8 Equivalent to GL_UNSIGNED_INT_8_8_8_8
2404 \value UInt32_RGBA8_Rev Equivalent to GL_UNSIGNED_INT_8_8_8_8_REV
2405 \value UInt32_RGB10A2 Equivalent to GL_UNSIGNED_INT_10_10_10_2
2406 \value UInt32_RGB10A2_Rev Equivalent to GL_UNSIGNED_INT_2_10_10_10_REV
2407 \value UInt32_D24S8 Equivalent to GL_UNSIGNED_INT_24_8. Introduced in Qt 5.4
2408 \value Float32_D32_UInt32_S8_X24 Equivalent to GL_FLOAT_32_UNSIGNED_INT_24_8_REV. Introduced in Qt 5.4
2409*/
2410
2411/*!
2412 \enum QOpenGLTexture::Feature
2413 This enum defines the OpenGL texture-related features that can be tested for.
2414
2415 \value ImmutableStorage Support for immutable texture storage
2416 \value ImmutableMultisampleStorage Support for immutable texture storage with
2417 multisample targets
2418 \value TextureRectangle Support for the GL_TEXTURE_RECTANGLE target
2419 \value TextureArrays Support for texture targets with array layers
2420 \value Texture3D Support for the 3 dimensional texture target
2421 \value TextureMultisample Support for texture targets that have multisample capabilities
2422 \value TextureBuffer Support for textures that use OpenGL buffer objects
2423 as their data source
2424 \value TextureCubeMapArrays Support for cubemap array texture target
2425 \value Swizzle Support for texture component swizzle masks
2426 \value StencilTexturing Support for stencil texturing (i.e. looking up depth or stencil
2427 components of a combined depth/stencil format texture in GLSL shaders).
2428 \value AnisotropicFiltering Support for anisotropic texture filtering
2429 \value NPOTTextures Basic support for non-power-of-two textures
2430 \value NPOTTextureRepeat Full support for non-power-of-two textures including texture
2431 repeat modes
2432 \value Texture1D Support for the 1 dimensional texture target
2433 \value TextureComparisonOperators Support for texture comparison operators
2434 \value TextureMipMapLevel Support for setting the base and maximum mipmap levels
2435*/
2436
2437/*!
2438 \enum QOpenGLTexture::SwizzleComponent
2439 This enum defines the texture color components that can be assigned a swizzle mask.
2440
2441 \value SwizzleRed The red component. Equivalent to GL_TEXTURE_SWIZZLE_R
2442 \value SwizzleGreen The green component. Equivalent to GL_TEXTURE_SWIZZLE_G
2443 \value SwizzleBlue The blue component. Equivalent to GL_TEXTURE_SWIZZLE_B
2444 \value SwizzleAlpha The alpha component. Equivalent to GL_TEXTURE_SWIZZLE_A
2445*/
2446
2447/*!
2448 \enum QOpenGLTexture::SwizzleValue
2449 This enum defines the possible mask values for texture swizzling.
2450
2451 \value RedValue Maps the component to the red channel. Equivalent to GL_RED
2452 \value GreenValue Maps the component to the green channel. Equivalent to GL_GREEN
2453 \value BlueValue Maps the component to the blue channel. Equivalent to GL_BLUE
2454 \value AlphaValue Maps the component to the alpha channel. Equivalent to GL_ALPHA
2455 \value ZeroValue Maps the component to a fixed value of 0. Equivalent to GL_ZERO
2456 \value OneValue Maps the component to a fixed value of 1. Equivalent to GL_ONE
2457*/
2458
2459/*!
2460 \enum QOpenGLTexture::WrapMode
2461 This enum defines the possible texture coordinate wrapping modes.
2462
2463 \value Repeat Texture coordinate is repeated. Equivalent to GL_REPEAT
2464 \value MirroredRepeat Texture coordinate is reflected about 0 and 1. Equivalent to GL_MIRRORED_REPEAT
2465 \value ClampToEdge Clamps the texture coordinates to [0,1]. Equivalent to GL_CLAMP_TO_EDGE
2466 \value ClampToBorder As for ClampToEdge but also blends samples at 0 and 1 with a
2467 fixed border color. Equivalent to GL_CLAMP_TO_BORDER
2468*/
2469
2470/*!
2471 \enum QOpenGLTexture::CoordinateDirection
2472 This enum defines the possible texture coordinate directions
2473
2474 \value DirectionS The horizontal direction. Equivalent to GL_TEXTURE_WRAP_S
2475 \value DirectionT The vertical direction. Equivalent to GL_TEXTURE_WRAP_T
2476 \value DirectionR The depth direction. Equivalent to GL_TEXTURE_WRAP_R
2477*/
2478
2479/*!
2480 Creates a QOpenGLTexture object that can later be bound to \a target.
2481
2482 This does not create the underlying OpenGL texture object. Therefore,
2483 construction using this constructor does not require a valid current
2484 OpenGL context.
2485*/
2486QOpenGLTexture::QOpenGLTexture(Target target)
2487 : d_ptr(new QOpenGLTexturePrivate(target, this))
2488{
2489}
2490
2491/*!
2492 Creates a QOpenGLTexture object that can later be bound to the 2D texture
2493 target and contains the pixel data contained in \a image. If you wish
2494 to have a chain of mipmaps generated then set \a genMipMaps to \c true (this
2495 is the default).
2496
2497 This does create the underlying OpenGL texture object. Therefore,
2498 construction using this constructor does require a valid current
2499 OpenGL context.
2500*/
2501QOpenGLTexture::QOpenGLTexture(const QImage& image, MipMapGeneration genMipMaps)
2502 : QOpenGLTexture(QOpenGLTexture::Target2D)
2503{
2504 setData(image, genMipMaps);
2505}
2506
2507QOpenGLTexture::~QOpenGLTexture()
2508{
2509}
2510
2511/*!
2512 Returns the binding target of this texture.
2513
2514 \since 5.4
2515*/
2516QOpenGLTexture::Target QOpenGLTexture::target() const
2517{
2518 Q_D(const QOpenGLTexture);
2519 return d->target;
2520}
2521
2522/*!
2523 Creates the underlying OpenGL texture object. This requires a current valid
2524 OpenGL context. If the texture object already exists, this function does
2525 nothing.
2526
2527 Once the texture object is created you can obtain the object
2528 name from the textureId() function. This may be useful if you wish to make
2529 some raw OpenGL calls related to this texture.
2530
2531 Normally it should not be necessary to call this function directly as all
2532 functions that set properties of the texture object implicitly call create()
2533 on your behalf.
2534
2535 Returns \c true if the creation succeeded, otherwise returns \c false.
2536
2537 \sa destroy(), isCreated(), textureId()
2538*/
2539bool QOpenGLTexture::create()
2540{
2541 Q_D(QOpenGLTexture);
2542 return d->create();
2543}
2544
2545/*!
2546 Destroys the underlying OpenGL texture object. This requires a current valid
2547 OpenGL context.
2548
2549 \sa create(), isCreated(), textureId()
2550*/
2551void QOpenGLTexture::destroy()
2552{
2553 Q_D(QOpenGLTexture);
2554 return d->destroy();
2555}
2556
2557/*!
2558 Returns \c true if the underlying OpenGL texture object has been created.
2559
2560 \sa create(), destroy(), textureId()
2561*/
2562bool QOpenGLTexture::isCreated() const
2563{
2564 Q_D(const QOpenGLTexture);
2565 return d->textureId != 0;
2566}
2567
2568/*!
2569 Returns the name of the underlying OpenGL texture object or 0 if it has
2570 not yet been created.
2571
2572 \sa create(), destroy(), isCreated()
2573*/
2574GLuint QOpenGLTexture::textureId() const
2575{
2576 Q_D(const QOpenGLTexture);
2577 return d->textureId;
2578}
2579
2580/*!
2581 Binds this texture to the currently active texture unit ready for
2582 rendering. Note that you do not need to bind QOpenGLTexture objects
2583 in order to modify them as the implementation makes use of the
2584 EXT_direct_state_access extension where available and simulates it
2585 where it is not.
2586
2587 \sa release()
2588*/
2589void QOpenGLTexture::bind()
2590{
2591 Q_D(QOpenGLTexture);
2592 Q_ASSERT(d->textureId);
2593 d->bind();
2594}
2595
2596/*!
2597 Binds this texture to texture unit \a unit ready for
2598 rendering. Note that you do not need to bind QOpenGLTexture objects
2599 in order to modify them as the implementation makes use of the
2600 EXT_direct_state_access extension where available and simulates it
2601 where it is not.
2602
2603 If parameter \a reset is \c true then this function will restore
2604 the active unit to the texture unit that was active upon entry.
2605
2606 \sa release()
2607*/
2608void QOpenGLTexture::bind(uint unit, TextureUnitReset reset)
2609{
2610 Q_D(QOpenGLTexture);
2611 Q_ASSERT(d->textureId);
2612 d->bind(unit, reset);
2613}
2614
2615/*!
2616 Unbinds this texture from the currently active texture unit.
2617
2618 \sa bind()
2619*/
2620void QOpenGLTexture::release()
2621{
2622 Q_D(QOpenGLTexture);
2623 d->release();
2624}
2625
2626/*!
2627 Unbinds this texture from texture unit \a unit.
2628
2629 If parameter \a reset is \c true then this function
2630 will restore the active unit to the texture unit that was active
2631 upon entry.
2632*/
2633void QOpenGLTexture::release(uint unit, TextureUnitReset reset)
2634{
2635 Q_D(QOpenGLTexture);
2636 d->release(unit, reset);
2637}
2638
2639/*!
2640 Returns \c true if this texture is bound to the corresponding target
2641 of the currently active texture unit.
2642
2643 \sa bind(), release()
2644*/
2645bool QOpenGLTexture::isBound() const
2646{
2647 Q_D(const QOpenGLTexture);
2648 Q_ASSERT(d->textureId);
2649 return d->isBound();
2650}
2651
2652/*!
2653 Returns \c true if this texture is bound to the corresponding target
2654 of texture unit \a unit.
2655
2656 \sa bind(), release()
2657*/
2658bool QOpenGLTexture::isBound(uint unit)
2659{
2660 Q_D(const QOpenGLTexture);
2661 Q_ASSERT(d->textureId);
2662 return d->isBound(unit);
2663}
2664
2665/*!
2666 Returns the textureId of the texture that is bound to the \a target
2667 of the currently active texture unit.
2668*/
2669GLuint QOpenGLTexture::boundTextureId(BindingTarget target)
2670{
2671 QOpenGLContext *ctx = QOpenGLContext::currentContext();
2672 if (!ctx) {
2673 qWarning("QOpenGLTexture::boundTextureId() requires a valid current context");
2674 return 0;
2675 }
2676
2677 GLint textureId = 0;
2678 ctx->functions()->glGetIntegerv(target, &textureId);
2679 return static_cast<GLuint>(textureId);
2680}
2681
2682/*!
2683 Returns the textureId of the texture that is bound to the \a target
2684 of the texture unit \a unit.
2685*/
2686GLuint QOpenGLTexture::boundTextureId(uint unit, BindingTarget target)
2687{
2688 QOpenGLContext *ctx = QOpenGLContext::currentContext();
2689 if (!ctx) {
2690 qWarning("QOpenGLTexture::boundTextureId() requires a valid current context");
2691 return 0;
2692 }
2693
2694 QOpenGLFunctions *funcs = ctx->functions();
2695 funcs->initializeOpenGLFunctions();
2696
2697 GLint oldTextureUnit = 0;
2698 funcs->glGetIntegerv(GL_ACTIVE_TEXTURE, &oldTextureUnit);
2699
2700 funcs->glActiveTexture(unit);
2701 GLint textureId = 0;
2702 funcs->glGetIntegerv(target, &textureId);
2703 funcs->glActiveTexture(oldTextureUnit);
2704
2705 return static_cast<GLuint>(textureId);
2706}
2707
2708/*!
2709 Sets the format of this texture object to \a format. This function
2710 must be called before texture storage is allocated.
2711
2712 Note that all formats may not be supported. The exact set of supported
2713 formats is dependent upon your OpenGL implementation and version.
2714
2715 \sa format(), allocateStorage()
2716*/
2717void QOpenGLTexture::setFormat(TextureFormat format)
2718{
2719 Q_D(QOpenGLTexture);
2720 d->create();
2721 if (isStorageAllocated()) {
2722 qWarning("QOpenGLTexture::setFormat(): Cannot change format once storage has been allocated");
2723 return;
2724 }
2725
2726 d->format = format;
2727
2728 switch (format) {
2729 case NoFormat:
2730 d->formatClass = NoFormatClass;
2731 break;
2732
2733 case RGBA32F:
2734 case RGBA32U:
2735 case RGBA32I:
2736 d->formatClass = FormatClass_128Bit;
2737 break;
2738
2739 case RGB32F:
2740 case RGB32U:
2741 case RGB32I:
2742 d->formatClass = FormatClass_96Bit;
2743 break;
2744
2745 case RGBA16F:
2746 case RG32F:
2747 case RGBA16U:
2748 case RG32U:
2749 case RGBA16I:
2750 case RG32I:
2751 case RGBA16_UNorm:
2752 case RGBA16_SNorm:
2753 d->formatClass = FormatClass_64Bit;
2754 break;
2755
2756 case RGB16_UNorm:
2757 case RGB16_SNorm:
2758 case RGB16F:
2759 case RGB16U:
2760 case RGB16I:
2761 d->formatClass = FormatClass_48Bit;
2762 break;
2763
2764 case RG16F:
2765 case RG11B10F:
2766 case R32F:
2767 case RGB10A2:
2768 case RGBA8U:
2769 case RG16U:
2770 case R32U:
2771 case RGBA8I:
2772 case RG16I:
2773 case R32I:
2774 case RGBA8_UNorm:
2775 case RG16_UNorm:
2776 case RGBA8_SNorm:
2777 case RG16_SNorm:
2778 case SRGB8_Alpha8:
2779 case RGB9E5:
2780 d->formatClass = FormatClass_32Bit;
2781 break;
2782
2783 case RGB8_UNorm:
2784 case RGB8_SNorm:
2785 case SRGB8:
2786 case RGB8U:
2787 case RGB8I:
2788 d->formatClass = FormatClass_24Bit;
2789 break;
2790
2791 case R16F:
2792 case RG8U:
2793 case R16U:
2794 case RG8I:
2795 case R16I:
2796 case RG8_UNorm:
2797 case R16_UNorm:
2798 case RG8_SNorm:
2799 case R16_SNorm:
2800 d->formatClass = FormatClass_16Bit;
2801 break;
2802
2803 case R8U:
2804 case R8I:
2805 case R8_UNorm:
2806 case R8_SNorm:
2807 d->formatClass = FormatClass_8Bit;
2808 break;
2809
2810 case R_ATI1N_UNorm:
2811 case R_ATI1N_SNorm:
2812 d->formatClass = FormatClass_RGTC1_R;
2813 break;
2814
2815 case RG_ATI2N_UNorm:
2816 case RG_ATI2N_SNorm:
2817 d->formatClass = FormatClass_RGTC2_RG;
2818 break;
2819
2820 case RGB_BP_UNorm:
2821 case SRGB_BP_UNorm:
2822 d->formatClass = FormatClass_BPTC_Unorm;
2823 break;
2824
2825 case RGB_BP_UNSIGNED_FLOAT:
2826 case RGB_BP_SIGNED_FLOAT:
2827 d->formatClass = FormatClass_BPTC_Float;
2828 break;
2829
2830 case RGB_DXT1:
2831 case SRGB_DXT1:
2832 d->formatClass = FormatClass_S3TC_DXT1_RGB;
2833 break;
2834
2835 case RGBA_DXT1:
2836 case SRGB_Alpha_DXT1:
2837 d->formatClass = FormatClass_S3TC_DXT1_RGBA;
2838 break;
2839
2840 case RGBA_DXT3:
2841 case SRGB_Alpha_DXT3:
2842 d->formatClass = FormatClass_S3TC_DXT3_RGBA;
2843 break;
2844
2845 case RGBA_DXT5:
2846 case SRGB_Alpha_DXT5:
2847 d->formatClass = FormatClass_S3TC_DXT5_RGBA;
2848 break;
2849
2850 case QOpenGLTexture::R11_EAC_UNorm:
2851 case QOpenGLTexture::R11_EAC_SNorm:
2852 case QOpenGLTexture::RG11_EAC_UNorm:
2853 case QOpenGLTexture::RG11_EAC_SNorm:
2854 case QOpenGLTexture::RGB8_ETC2:
2855 case QOpenGLTexture::SRGB8_ETC2:
2856 case QOpenGLTexture::RGB8_PunchThrough_Alpha1_ETC2:
2857 case QOpenGLTexture::SRGB8_PunchThrough_Alpha1_ETC2:
2858 case QOpenGLTexture::RGBA8_ETC2_EAC:
2859 case QOpenGLTexture::SRGB8_Alpha8_ETC2_EAC:
2860 case QOpenGLTexture::RGB8_ETC1:
2861 case RG3B2:
2862 case R5G6B5:
2863 case RGB5A1:
2864 case RGBA4:
2865 case D16:
2866 case D24:
2867 case D24S8:
2868 case D32:
2869 case D32F:
2870 case D32FS8X24:
2871 case S8:
2872 case DepthFormat:
2873 case AlphaFormat:
2874 case RGBFormat:
2875 case RGBAFormat:
2876 case LuminanceFormat:
2877 case LuminanceAlphaFormat:
2878 case QOpenGLTexture::RGBA_ASTC_4x4:
2879 case QOpenGLTexture::RGBA_ASTC_5x4:
2880 case QOpenGLTexture::RGBA_ASTC_5x5:
2881 case QOpenGLTexture::RGBA_ASTC_6x5:
2882 case QOpenGLTexture::RGBA_ASTC_6x6:
2883 case QOpenGLTexture::RGBA_ASTC_8x5:
2884 case QOpenGLTexture::RGBA_ASTC_8x6:
2885 case QOpenGLTexture::RGBA_ASTC_8x8:
2886 case QOpenGLTexture::RGBA_ASTC_10x5:
2887 case QOpenGLTexture::RGBA_ASTC_10x6:
2888 case QOpenGLTexture::RGBA_ASTC_10x8:
2889 case QOpenGLTexture::RGBA_ASTC_10x10:
2890 case QOpenGLTexture::RGBA_ASTC_12x10:
2891 case QOpenGLTexture::RGBA_ASTC_12x12:
2892 case QOpenGLTexture::SRGB8_Alpha8_ASTC_4x4:
2893 case QOpenGLTexture::SRGB8_Alpha8_ASTC_5x4:
2894 case QOpenGLTexture::SRGB8_Alpha8_ASTC_5x5:
2895 case QOpenGLTexture::SRGB8_Alpha8_ASTC_6x5:
2896 case QOpenGLTexture::SRGB8_Alpha8_ASTC_6x6:
2897 case QOpenGLTexture::SRGB8_Alpha8_ASTC_8x5:
2898 case QOpenGLTexture::SRGB8_Alpha8_ASTC_8x6:
2899 case QOpenGLTexture::SRGB8_Alpha8_ASTC_8x8:
2900 case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x5:
2901 case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x6:
2902 case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x8:
2903 case QOpenGLTexture::SRGB8_Alpha8_ASTC_10x10:
2904 case QOpenGLTexture::SRGB8_Alpha8_ASTC_12x10:
2905 case QOpenGLTexture::SRGB8_Alpha8_ASTC_12x12:
2906 d->formatClass = FormatClass_Unique;
2907 break;
2908 }
2909}
2910
2911/*!
2912 Returns the format of this texture object.
2913
2914 \sa setFormat()
2915*/
2916QOpenGLTexture::TextureFormat QOpenGLTexture::format() const
2917{
2918 Q_D(const QOpenGLTexture);
2919 return d->format;
2920}
2921
2922static bool isNpot(int width, int height = 1, int depth = 1)
2923{
2924 return width & (width-1) || height & (height-1) || depth & (depth-1);
2925}
2926
2927/*!
2928 Sets the dimensions of this texture object to \a width,
2929 \a height, and \a depth. The default for each dimension is 1.
2930 The maximum allowable texture size is dependent upon your OpenGL
2931 implementation. Allocating storage for a texture less than the
2932 maximum size can still fail if your system is low on resources.
2933
2934 If a non-power-of-two \a width, \a height or \a depth is provided and your
2935 OpenGL implementation doesn't have support for repeating non-power-of-two
2936 textures, then the wrap mode is automatically set to ClampToEdge.
2937
2938 \sa width(), height(), depth()
2939*/
2940void QOpenGLTexture::setSize(int width, int height, int depth)
2941{
2942 Q_D(QOpenGLTexture);
2943 d->create();
2944 if (isStorageAllocated()) {
2945 qWarning("Cannot resize a texture that already has storage allocated.\n"
2946 "To do so, destroy() the texture and then create() and setSize()");
2947 return;
2948 }
2949
2950 if (isNpot(width, height, depth) && !hasFeature(Feature::NPOTTextureRepeat) && d->target != Target::TargetRectangle)
2951 d->setWrapMode(WrapMode::ClampToEdge);
2952
2953 switch (d->target) {
2954 case QOpenGLTexture::Target1D:
2955 case QOpenGLTexture::Target1DArray:
2956 case QOpenGLTexture::TargetBuffer:
2957 d->dimensions[0] = width;
2958 Q_UNUSED(height);
2959 Q_UNUSED(depth);
2960 break;
2961
2962 case QOpenGLTexture::Target2D:
2963 case QOpenGLTexture::Target2DArray:
2964 case QOpenGLTexture::TargetRectangle:
2965 case QOpenGLTexture::Target2DMultisample:
2966 case QOpenGLTexture::Target2DMultisampleArray:
2967 d->dimensions[0] = width;
2968 d->dimensions[1] = height;
2969 Q_UNUSED(depth);
2970 break;
2971
2972 case QOpenGLTexture::TargetCubeMap:
2973 case QOpenGLTexture::TargetCubeMapArray:
2974 if (width != height)
2975 qWarning("QAbstractOpenGLTexture::setSize(): Cube map textures must be square");
2976 d->dimensions[0] = d->dimensions[1] = width;
2977 Q_UNUSED(depth);
2978 break;
2979
2980 case QOpenGLTexture::Target3D:
2981 d->dimensions[0] = width;
2982 d->dimensions[1] = height;
2983 d->dimensions[2] = depth;
2984 break;
2985 }
2986}
2987
2988/*!
2989 Returns the width of a 1D, 2D or 3D texture.
2990
2991 \sa height(), depth(), setSize()
2992*/
2993int QOpenGLTexture::width() const
2994{
2995 Q_D(const QOpenGLTexture);
2996 return d->dimensions[0];
2997}
2998
2999/*!
3000 Returns the height of a 2D or 3D texture.
3001
3002 \sa width(), depth(), setSize()
3003*/
3004int QOpenGLTexture::height() const
3005{
3006 Q_D(const QOpenGLTexture);
3007 return d->dimensions[1];
3008}
3009
3010/*!
3011 Returns the depth of a 3D texture.
3012
3013 \sa width(), height(), setSize()
3014*/
3015int QOpenGLTexture::depth() const
3016{
3017 Q_D(const QOpenGLTexture);
3018 return d->dimensions[2];
3019}
3020
3021/*!
3022 For texture targets that support mipmaps, this function
3023 sets the requested number of mipmap \a levels to allocate storage
3024 for. This function should be called before storage is allocated
3025 for the texture.
3026
3027 If the texture target does not support mipmaps this function
3028 has no effect.
3029
3030 \sa mipLevels(), maximumMipLevels(), isStorageAllocated()
3031*/
3032void QOpenGLTexture::setMipLevels(int levels)
3033{
3034 Q_D(QOpenGLTexture);
3035 d->create();
3036 if (isStorageAllocated()) {
3037 qWarning("Cannot set mip levels on a texture that already has storage allocated.\n"
3038 "To do so, destroy() the texture and then create() and setMipLevels()");
3039 return;
3040 }
3041
3042 switch (d->target) {
3043 case QOpenGLTexture::Target1D:
3044 case QOpenGLTexture::Target1DArray:
3045 case QOpenGLTexture::Target2D:
3046 case QOpenGLTexture::Target2DArray:
3047 case QOpenGLTexture::TargetCubeMap:
3048 case QOpenGLTexture::TargetCubeMapArray:
3049 case QOpenGLTexture::Target3D:
3050 d->requestedMipLevels = levels;
3051 break;
3052
3053 case QOpenGLTexture::TargetBuffer:
3054 case QOpenGLTexture::TargetRectangle:
3055 case QOpenGLTexture::Target2DMultisample:
3056 case QOpenGLTexture::Target2DMultisampleArray:
3057 qWarning("QAbstractOpenGLTexture::setMipLevels(): This texture target does not support mipmaps");
3058 break;
3059 }
3060}
3061
3062/*!
3063 Returns the number of mipmap levels for this texture. If storage
3064 has not yet been allocated for this texture it returns the
3065 requested number of mipmap levels.
3066
3067 \sa setMipLevels(), maximumMipLevels(), isStorageAllocated()
3068*/
3069int QOpenGLTexture::mipLevels() const
3070{
3071 Q_D(const QOpenGLTexture);
3072 return isStorageAllocated() ? d->mipLevels : d->requestedMipLevels;
3073}
3074
3075/*!
3076 Returns the maximum number of mipmap levels that this texture
3077 can have given the current dimensions.
3078
3079 \sa setMipLevels(), mipLevels(), setSize()
3080*/
3081int QOpenGLTexture::maximumMipLevels() const
3082{
3083 Q_D(const QOpenGLTexture);
3084 return d->maximumMipLevelCount();
3085}
3086
3087/*!
3088 Sets the number of array \a layers to allocate storage for. This
3089 function should be called before storage is allocated for the texture.
3090
3091 For targets that do not support array layers this function has
3092 no effect.
3093
3094 \sa layers(), isStorageAllocated()
3095*/
3096void QOpenGLTexture::setLayers(int layers)
3097{
3098 Q_D(QOpenGLTexture);
3099 d->create();
3100 if (isStorageAllocated()) {
3101 qWarning("Cannot set layers on a texture that already has storage allocated.\n"
3102 "To do so, destroy() the texture and then create() and setLayers()");
3103 return;
3104 }
3105
3106 switch (d->target) {
3107 case QOpenGLTexture::Target1DArray:
3108 case QOpenGLTexture::Target2DArray:
3109 case QOpenGLTexture::TargetCubeMapArray:
3110 case QOpenGLTexture::Target2DMultisampleArray:
3111 d->layers = layers;
3112 break;
3113
3114 case QOpenGLTexture::Target1D:
3115 case QOpenGLTexture::Target2D:
3116 case QOpenGLTexture::Target3D:
3117 case QOpenGLTexture::TargetCubeMap:
3118 case QOpenGLTexture::TargetBuffer:
3119 case QOpenGLTexture::TargetRectangle:
3120 case QOpenGLTexture::Target2DMultisample:
3121 qWarning("Texture target does not support array layers");
3122 break;
3123 }
3124}
3125
3126/*!
3127 Returns the number of array layers for this texture. If
3128 storage has not yet been allocated for this texture then
3129 this function returns the requested number of array layers.
3130
3131 For texture targets that do not support array layers this
3132 will return 1.
3133
3134 \sa setLayers(), isStorageAllocated()
3135*/
3136int QOpenGLTexture::layers() const
3137{
3138 Q_D(const QOpenGLTexture);
3139 return d->layers;
3140}
3141
3142/*!
3143 Returns the number of faces for this texture. For cubemap
3144 and cubemap array type targets this will be 6.
3145
3146 For non-cubemap type targets this will return 1.
3147*/
3148int QOpenGLTexture::faces() const
3149{
3150 Q_D(const QOpenGLTexture);
3151 return d->faces;
3152}
3153
3154/*!
3155 Sets the number of \a samples to allocate storage for when rendering to
3156 a multisample capable texture target. This function should
3157 be called before storage is allocated for the texture.
3158
3159 For targets that do not support multisampling this function has
3160 no effect.
3161
3162 \sa samples(), isStorageAllocated()
3163*/
3164void QOpenGLTexture::setSamples(int samples)
3165{
3166 Q_D(QOpenGLTexture);
3167 d->create();
3168 if (isStorageAllocated()) {
3169 qWarning("Cannot set sample count on a texture that already has storage allocated.\n"
3170 "To do so, destroy() the texture and then create() and setSamples()");
3171 return;
3172 }
3173
3174 switch (d->target) {
3175 case QOpenGLTexture::Target2DMultisample:
3176 case QOpenGLTexture::Target2DMultisampleArray:
3177 d->samples = samples;
3178 break;
3179
3180 case QOpenGLTexture::Target1D:
3181 case QOpenGLTexture::Target2D:
3182 case QOpenGLTexture::Target3D:
3183 case QOpenGLTexture::Target1DArray:
3184 case QOpenGLTexture::Target2DArray:
3185 case QOpenGLTexture::TargetCubeMap:
3186 case QOpenGLTexture::TargetCubeMapArray:
3187 case QOpenGLTexture::TargetBuffer:
3188 case QOpenGLTexture::TargetRectangle:
3189
3190 qWarning("Texture target does not support multisampling");
3191 break;
3192 }
3193}
3194
3195/*!
3196 Returns the number of multisample sample points for this texture.
3197 If storage has not yet been allocated for this texture then
3198 this function returns the requested number of samples.
3199
3200 For texture targets that do not support multisampling this
3201 will return 0.
3202
3203 \sa setSamples(), isStorageAllocated()
3204*/
3205int QOpenGLTexture::samples() const
3206{
3207 Q_D(const QOpenGLTexture);
3208 return d->samples;
3209}
3210
3211/*!
3212 Sets whether the sample positions and number of samples used with
3213 a multisample capable texture target to \a fixed. If set to \c true
3214 the sample positions and number of samples used are the same for
3215 all texels in the image and will not depend upon the image size or
3216 internal format. This function should be called before storage is allocated
3217 for the texture.
3218
3219 For targets that do not support multisampling this function has
3220 no effect.
3221
3222 The default value is \c true.
3223
3224 \sa isFixedSamplePositions(), isStorageAllocated()
3225*/
3226void QOpenGLTexture::setFixedSamplePositions(bool fixed)
3227{
3228 Q_D(QOpenGLTexture);
3229 d->create();
3230 if (isStorageAllocated()) {
3231 qWarning("Cannot set sample positions on a texture that already has storage allocated.\n"
3232 "To do so, destroy() the texture and then create() and setFixedSamplePositions()");
3233 return;
3234 }
3235
3236 switch (d->target) {
3237 case QOpenGLTexture::Target2DMultisample:
3238 case QOpenGLTexture::Target2DMultisampleArray:
3239 d->fixedSamplePositions = fixed;
3240 break;
3241
3242 case QOpenGLTexture::Target1D:
3243 case QOpenGLTexture::Target2D:
3244 case QOpenGLTexture::Target3D:
3245 case QOpenGLTexture::Target1DArray:
3246 case QOpenGLTexture::Target2DArray:
3247 case QOpenGLTexture::TargetCubeMap:
3248 case QOpenGLTexture::TargetCubeMapArray:
3249 case QOpenGLTexture::TargetBuffer:
3250 case QOpenGLTexture::TargetRectangle:
3251
3252 qWarning("Texture target does not support multisampling");
3253 break;
3254 }
3255}
3256
3257/*!
3258 Returns whether this texture uses a fixed pattern of multisample
3259 samples. If storage has not yet been allocated for this texture then
3260 this function returns the requested fixed sample position setting.
3261
3262 For texture targets that do not support multisampling this
3263 will return \c true.
3264
3265 \sa setFixedSamplePositions(), isStorageAllocated()
3266*/
3267bool QOpenGLTexture::isFixedSamplePositions() const
3268{
3269 Q_D(const QOpenGLTexture);
3270 return d->fixedSamplePositions;
3271}
3272
3273/*!
3274 Allocates server-side storage for this texture object taking
3275 into account, the format, dimensions, mipmap levels, array
3276 layers and cubemap faces.
3277
3278 Once storage has been allocated it is no longer possible to change
3279 these properties.
3280
3281 If supported QOpenGLTexture makes use of immutable texture
3282 storage.
3283
3284 Once storage has been allocated for the texture then pixel data
3285 can be uploaded via one of the setData() overloads.
3286
3287 \note If immutable texture storage is not available,
3288 then a default pixel format and pixel type will be used to
3289 create the mutable storage. You can use the other
3290 allocateStorage() overload to specify exactly the pixel format
3291 and the pixel type to use when allocating mutable storage;
3292 this is particulary useful under certain OpenGL ES implementations
3293 (notably, OpenGL ES 2), where the pixel format and the pixel type
3294 used at allocation time must perfectly match the format
3295 and the type passed to any subsequent setData() call.
3296
3297 \sa isStorageAllocated(), setData()
3298*/
3299void QOpenGLTexture::allocateStorage()
3300{
3301 Q_D(QOpenGLTexture);
3302 if (