1// Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QOPENGLABSTRACTTEXTURE_H
5#define QOPENGLABSTRACTTEXTURE_H
6
7#include <QtOpenGL/qtopenglglobal.h>
8
9#ifndef QT_NO_OPENGL
10
11#include <QtGui/qopengl.h>
12#include <QtGui/qimage.h>
13#include <QtCore/QScopedPointer>
14
15QT_BEGIN_NAMESPACE
16
17class QDebug;
18class QOpenGLTexturePrivate;
19class QOpenGLPixelTransferOptions;
20
21class Q_OPENGL_EXPORT QOpenGLTexture
22{
23 Q_GADGET
24public:
25 enum Target {
26 Target1D = 0x0DE0, // GL_TEXTURE_1D
27 Target1DArray = 0x8C18, // GL_TEXTURE_1D_ARRAY
28 Target2D = 0x0DE1, // GL_TEXTURE_2D
29 Target2DArray = 0x8C1A, // GL_TEXTURE_2D_ARRAY
30 Target3D = 0x806F, // GL_TEXTURE_3D
31 TargetCubeMap = 0x8513, // GL_TEXTURE_CUBE_MAP
32 TargetCubeMapArray = 0x9009, // GL_TEXTURE_CUBE_MAP_ARRAY
33 Target2DMultisample = 0x9100, // GL_TEXTURE_2D_MULTISAMPLE
34 Target2DMultisampleArray = 0x9102, // GL_TEXTURE_2D_MULTISAMPLE_ARRAY
35 TargetRectangle = 0x84F5, // GL_TEXTURE_RECTANGLE
36 TargetBuffer = 0x8C2A // GL_TEXTURE_BUFFER
37 };
38 Q_ENUM(Target)
39
40 enum BindingTarget {
41 BindingTarget1D = 0x8068, // GL_TEXTURE_BINDING_1D
42 BindingTarget1DArray = 0x8C1C, // GL_TEXTURE_BINDING_1D_ARRAY
43 BindingTarget2D = 0x8069, // GL_TEXTURE_BINDING_2D
44 BindingTarget2DArray = 0x8C1D, // GL_TEXTURE_BINDING_2D_ARRAY
45 BindingTarget3D = 0x806A, // GL_TEXTURE_BINDING_3D
46 BindingTargetCubeMap = 0x8514, // GL_TEXTURE_BINDING_CUBE_MAP
47 BindingTargetCubeMapArray = 0x900A, // GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
48 BindingTarget2DMultisample = 0x9104, // GL_TEXTURE_BINDING_2D_MULTISAMPLE
49 BindingTarget2DMultisampleArray = 0x9105, // GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY
50 BindingTargetRectangle = 0x84F6, // GL_TEXTURE_BINDING_RECTANGLE
51 BindingTargetBuffer = 0x8C2C // GL_TEXTURE_BINDING_BUFFER
52 };
53 Q_ENUM(BindingTarget)
54
55 enum MipMapGeneration {
56 GenerateMipMaps,
57 DontGenerateMipMaps
58 };
59 Q_ENUM(MipMapGeneration)
60
61 enum TextureUnitReset {
62 ResetTextureUnit,
63 DontResetTextureUnit
64 };
65 Q_ENUM(TextureUnitReset)
66
67 enum TextureFormat {
68 NoFormat = 0, // GL_NONE
69
70 // Unsigned normalized formats
71 R8_UNorm = 0x8229, // GL_R8
72 RG8_UNorm = 0x822B, // GL_RG8
73 RGB8_UNorm = 0x8051, // GL_RGB8
74 RGBA8_UNorm = 0x8058, // GL_RGBA8
75
76 R16_UNorm = 0x822A, // GL_R16
77 RG16_UNorm = 0x822C, // GL_RG16
78 RGB16_UNorm = 0x8054, // GL_RGB16
79 RGBA16_UNorm = 0x805B, // GL_RGBA16
80
81 // Signed normalized formats
82 R8_SNorm = 0x8F94, // GL_R8_SNORM
83 RG8_SNorm = 0x8F95, // GL_RG8_SNORM
84 RGB8_SNorm = 0x8F96, // GL_RGB8_SNORM
85 RGBA8_SNorm = 0x8F97, // GL_RGBA8_SNORM
86
87 R16_SNorm = 0x8F98, // GL_R16_SNORM
88 RG16_SNorm = 0x8F99, // GL_RG16_SNORM
89 RGB16_SNorm = 0x8F9A, // GL_RGB16_SNORM
90 RGBA16_SNorm = 0x8F9B, // GL_RGBA16_SNORM
91
92 // Unsigned integer formats
93 R8U = 0x8232, // GL_R8UI
94 RG8U = 0x8238, // GL_RG8UI
95 RGB8U = 0x8D7D, // GL_RGB8UI
96 RGBA8U = 0x8D7C, // GL_RGBA8UI
97
98 R16U = 0x8234, // GL_R16UI
99 RG16U = 0x823A, // GL_RG16UI
100 RGB16U = 0x8D77, // GL_RGB16UI
101 RGBA16U = 0x8D76, // GL_RGBA16UI
102
103 R32U = 0x8236, // GL_R32UI
104 RG32U = 0x823C, // GL_RG32UI
105 RGB32U = 0x8D71, // GL_RGB32UI
106 RGBA32U = 0x8D70, // GL_RGBA32UI
107
108 // Signed integer formats
109 R8I = 0x8231, // GL_R8I
110 RG8I = 0x8237, // GL_RG8I
111 RGB8I = 0x8D8F, // GL_RGB8I
112 RGBA8I = 0x8D8E, // GL_RGBA8I
113
114 R16I = 0x8233, // GL_R16I
115 RG16I = 0x8239, // GL_RG16I
116 RGB16I = 0x8D89, // GL_RGB16I
117 RGBA16I = 0x8D88, // GL_RGBA16I
118
119 R32I = 0x8235, // GL_R32I
120 RG32I = 0x823B, // GL_RG32I
121 RGB32I = 0x8D83, // GL_RGB32I
122 RGBA32I = 0x8D82, // GL_RGBA32I
123
124 // Floating point formats
125 R16F = 0x822D, // GL_R16F
126 RG16F = 0x822F, // GL_RG16F
127 RGB16F = 0x881B, // GL_RGB16F
128 RGBA16F = 0x881A, // GL_RGBA16F
129
130 R32F = 0x822E, // GL_R32F
131 RG32F = 0x8230, // GL_RG32F
132 RGB32F = 0x8815, // GL_RGB32F
133 RGBA32F = 0x8814, // GL_RGBA32F
134
135 // Packed formats
136 RGB9E5 = 0x8C3D, // GL_RGB9_E5
137 RG11B10F = 0x8C3A, // GL_R11F_G11F_B10F
138 RG3B2 = 0x2A10, // GL_R3_G3_B2
139 R5G6B5 = 0x8D62, // GL_RGB565
140 RGB5A1 = 0x8057, // GL_RGB5_A1
141 RGBA4 = 0x8056, // GL_RGBA4
142 RGB10A2 = 0x906F, // GL_RGB10_A2UI
143
144 // Depth formats
145 D16 = 0x81A5, // GL_DEPTH_COMPONENT16
146 D24 = 0x81A6, // GL_DEPTH_COMPONENT24
147 D24S8 = 0x88F0, // GL_DEPTH24_STENCIL8
148 D32 = 0x81A7, // GL_DEPTH_COMPONENT32
149 D32F = 0x8CAC, // GL_DEPTH_COMPONENT32F
150 D32FS8X24 = 0x8CAD, // GL_DEPTH32F_STENCIL8
151 S8 = 0x8D48, // GL_STENCIL_INDEX8
152
153 // Compressed formats
154 RGB_DXT1 = 0x83F0, // GL_COMPRESSED_RGB_S3TC_DXT1_EXT
155 RGBA_DXT1 = 0x83F1, // GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
156 RGBA_DXT3 = 0x83F2, // GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
157 RGBA_DXT5 = 0x83F3, // GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
158 R_ATI1N_UNorm = 0x8DBB, // GL_COMPRESSED_RED_RGTC1
159 R_ATI1N_SNorm = 0x8DBC, // GL_COMPRESSED_SIGNED_RED_RGTC1
160 RG_ATI2N_UNorm = 0x8DBD, // GL_COMPRESSED_RG_RGTC2
161 RG_ATI2N_SNorm = 0x8DBE, // GL_COMPRESSED_SIGNED_RG_RGTC2
162 RGB_BP_UNSIGNED_FLOAT = 0x8E8F, // GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
163 RGB_BP_SIGNED_FLOAT = 0x8E8E, // GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
164 RGB_BP_UNorm = 0x8E8C, // GL_COMPRESSED_RGBA_BPTC_UNORM_ARB
165 R11_EAC_UNorm = 0x9270, // GL_COMPRESSED_R11_EAC
166 R11_EAC_SNorm = 0x9271, // GL_COMPRESSED_SIGNED_R11_EAC
167 RG11_EAC_UNorm = 0x9272, // GL_COMPRESSED_RG11_EAC
168 RG11_EAC_SNorm = 0x9273, // GL_COMPRESSED_SIGNED_RG11_EAC
169 RGB8_ETC2 = 0x9274, // GL_COMPRESSED_RGB8_ETC2
170 SRGB8_ETC2 = 0x9275, // GL_COMPRESSED_SRGB8_ETC2
171 RGB8_PunchThrough_Alpha1_ETC2 = 0x9276, // GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
172 SRGB8_PunchThrough_Alpha1_ETC2 = 0x9277, // GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
173 RGBA8_ETC2_EAC = 0x9278, // GL_COMPRESSED_RGBA8_ETC2_EAC
174 SRGB8_Alpha8_ETC2_EAC = 0x9279, // GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
175 RGB8_ETC1 = 0x8D64, // GL_ETC1_RGB8_OES
176 RGBA_ASTC_4x4 = 0x93B0, // GL_COMPRESSED_RGBA_ASTC_4x4_KHR
177 RGBA_ASTC_5x4 = 0x93B1, // GL_COMPRESSED_RGBA_ASTC_5x4_KHR
178 RGBA_ASTC_5x5 = 0x93B2, // GL_COMPRESSED_RGBA_ASTC_5x5_KHR
179 RGBA_ASTC_6x5 = 0x93B3, // GL_COMPRESSED_RGBA_ASTC_6x5_KHR
180 RGBA_ASTC_6x6 = 0x93B4, // GL_COMPRESSED_RGBA_ASTC_6x6_KHR
181 RGBA_ASTC_8x5 = 0x93B5, // GL_COMPRESSED_RGBA_ASTC_8x5_KHR
182 RGBA_ASTC_8x6 = 0x93B6, // GL_COMPRESSED_RGBA_ASTC_8x6_KHR
183 RGBA_ASTC_8x8 = 0x93B7, // GL_COMPRESSED_RGBA_ASTC_8x8_KHR
184 RGBA_ASTC_10x5 = 0x93B8, // GL_COMPRESSED_RGBA_ASTC_10x5_KHR
185 RGBA_ASTC_10x6 = 0x93B9, // GL_COMPRESSED_RGBA_ASTC_10x6_KHR
186 RGBA_ASTC_10x8 = 0x93BA, // GL_COMPRESSED_RGBA_ASTC_10x8_KHR
187 RGBA_ASTC_10x10 = 0x93BB, // GL_COMPRESSED_RGBA_ASTC_10x10_KHR
188 RGBA_ASTC_12x10 = 0x93BC, // GL_COMPRESSED_RGBA_ASTC_12x10_KHR
189 RGBA_ASTC_12x12 = 0x93BD, // GL_COMPRESSED_RGBA_ASTC_12x12_KHR
190 SRGB8_Alpha8_ASTC_4x4 = 0x93D0, // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
191 SRGB8_Alpha8_ASTC_5x4 = 0x93D1, // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
192 SRGB8_Alpha8_ASTC_5x5 = 0x93D2, // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
193 SRGB8_Alpha8_ASTC_6x5 = 0x93D3, // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
194 SRGB8_Alpha8_ASTC_6x6 = 0x93D4, // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
195 SRGB8_Alpha8_ASTC_8x5 = 0x93D5, // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
196 SRGB8_Alpha8_ASTC_8x6 = 0x93D6, // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
197 SRGB8_Alpha8_ASTC_8x8 = 0x93D7, // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
198 SRGB8_Alpha8_ASTC_10x5 = 0x93D8, // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
199 SRGB8_Alpha8_ASTC_10x6 = 0x93D9, // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
200 SRGB8_Alpha8_ASTC_10x8 = 0x93DA, // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
201 SRGB8_Alpha8_ASTC_10x10 = 0x93DB, // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
202 SRGB8_Alpha8_ASTC_12x10 = 0x93DC, // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
203 SRGB8_Alpha8_ASTC_12x12 = 0x93DD, // GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
204
205 // sRGB formats
206 SRGB8 = 0x8C41, // GL_SRGB8
207 SRGB8_Alpha8 = 0x8C43, // GL_SRGB8_ALPHA8
208 SRGB_DXT1 = 0x8C4C, // GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
209 SRGB_Alpha_DXT1 = 0x8C4D, // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
210 SRGB_Alpha_DXT3 = 0x8C4E, // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
211 SRGB_Alpha_DXT5 = 0x8C4F, // GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
212 SRGB_BP_UNorm = 0x8E8D, // GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB
213
214 // ES 2 formats
215 DepthFormat = 0x1902, // GL_DEPTH_COMPONENT
216 AlphaFormat = 0x1906, // GL_ALPHA
217 RGBFormat = 0x1907, // GL_RGB
218 RGBAFormat = 0x1908, // GL_RGBA
219 LuminanceFormat = 0x1909, // GL_LUMINANCE
220 LuminanceAlphaFormat = 0x190A
221
222 };
223 Q_ENUM(TextureFormat)
224
225 // This is not used externally yet but is reserved to allow checking of
226 // compatibility between texture formats
227#ifndef Q_QDOC
228 enum TextureFormatClass {
229 NoFormatClass,
230 FormatClass_128Bit,
231 FormatClass_96Bit,
232 FormatClass_64Bit,
233 FormatClass_48Bit,
234 FormatClass_32Bit,
235 FormatClass_24Bit,
236 FormatClass_16Bit,
237 FormatClass_8Bit,
238 FormatClass_RGTC1_R,
239 FormatClass_RGTC2_RG,
240 FormatClass_BPTC_Unorm,
241 FormatClass_BPTC_Float,
242 FormatClass_S3TC_DXT1_RGB,
243 FormatClass_S3TC_DXT1_RGBA,
244 FormatClass_S3TC_DXT3_RGBA,
245 FormatClass_S3TC_DXT5_RGBA,
246 FormatClass_Unique
247 };
248#endif
249
250 enum CubeMapFace {
251 CubeMapPositiveX = 0x8515, // GL_TEXTURE_CUBE_MAP_POSITIVE_X
252 CubeMapNegativeX = 0x8516, // GL_TEXTURE_CUBE_MAP_NEGATIVE_X
253 CubeMapPositiveY = 0x8517, // GL_TEXTURE_CUBE_MAP_POSITIVE_Y
254 CubeMapNegativeY = 0x8518, // GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
255 CubeMapPositiveZ = 0x8519, // GL_TEXTURE_CUBE_MAP_POSITIVE_Z
256 CubeMapNegativeZ = 0x851A // GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
257 };
258 Q_ENUM(CubeMapFace)
259
260 enum PixelFormat {
261 NoSourceFormat = 0, // GL_NONE
262 Red = 0x1903, // GL_RED
263 RG = 0x8227, // GL_RG
264 RGB = 0x1907, // GL_RGB
265 BGR = 0x80E0, // GL_BGR
266 RGBA = 0x1908, // GL_RGBA
267 BGRA = 0x80E1, // GL_BGRA
268 Red_Integer = 0x8D94, // GL_RED_INTEGER
269 RG_Integer = 0x8228, // GL_RG_INTEGER
270 RGB_Integer = 0x8D98, // GL_RGB_INTEGER
271 BGR_Integer = 0x8D9A, // GL_BGR_INTEGER
272 RGBA_Integer = 0x8D99, // GL_RGBA_INTEGER
273 BGRA_Integer = 0x8D9B, // GL_BGRA_INTEGER
274 Stencil = 0x1901, // GL_STENCIL_INDEX
275 Depth = 0x1902, // GL_DEPTH_COMPONENT
276 DepthStencil = 0x84F9, // GL_DEPTH_STENCIL
277 Alpha = 0x1906, // GL_ALPHA
278 Luminance = 0x1909, // GL_LUMINANCE
279 LuminanceAlpha = 0x190A // GL_LUMINANCE_ALPHA
280 };
281 Q_ENUM(PixelFormat)
282
283 enum PixelType {
284 NoPixelType = 0, // GL_NONE
285 Int8 = 0x1400, // GL_BYTE
286 UInt8 = 0x1401, // GL_UNSIGNED_BYTE
287 Int16 = 0x1402, // GL_SHORT
288 UInt16 = 0x1403, // GL_UNSIGNED_SHORT
289 Int32 = 0x1404, // GL_INT
290 UInt32 = 0x1405, // GL_UNSIGNED_INT
291 Float16 = 0x140B, // GL_HALF_FLOAT
292 Float16OES = 0x8D61, // GL_HALF_FLOAT_OES
293 Float32 = 0x1406, // GL_FLOAT
294 UInt32_RGB9_E5 = 0x8C3E, // GL_UNSIGNED_INT_5_9_9_9_REV
295 UInt32_RG11B10F = 0x8C3B, // GL_UNSIGNED_INT_10F_11F_11F_REV
296 UInt8_RG3B2 = 0x8032, // GL_UNSIGNED_BYTE_3_3_2
297 UInt8_RG3B2_Rev = 0x8362, // GL_UNSIGNED_BYTE_2_3_3_REV
298 UInt16_RGB5A1 = 0x8034, // GL_UNSIGNED_SHORT_5_5_5_1
299 UInt16_RGB5A1_Rev = 0x8366, // GL_UNSIGNED_SHORT_1_5_5_5_REV
300 UInt16_R5G6B5 = 0x8363, // GL_UNSIGNED_SHORT_5_6_5
301 UInt16_R5G6B5_Rev = 0x8364, // GL_UNSIGNED_SHORT_5_6_5_REV
302 UInt16_RGBA4 = 0x8033, // GL_UNSIGNED_SHORT_4_4_4_4
303 UInt16_RGBA4_Rev = 0x8365, // GL_UNSIGNED_SHORT_4_4_4_4_REV
304 UInt32_RGBA8 = 0x8035, // GL_UNSIGNED_INT_8_8_8_8
305 UInt32_RGBA8_Rev = 0x8367, // GL_UNSIGNED_INT_8_8_8_8_REV
306 UInt32_RGB10A2 = 0x8036, // GL_UNSIGNED_INT_10_10_10_2
307 UInt32_RGB10A2_Rev = 0x8368, // GL_UNSIGNED_INT_2_10_10_10_REV
308 UInt32_D24S8 = 0x84FA, // GL_UNSIGNED_INT_24_8
309 Float32_D32_UInt32_S8_X24 = 0x8DAD // GL_FLOAT_32_UNSIGNED_INT_24_8_REV
310 };
311 Q_ENUM(PixelType)
312
313 enum SwizzleComponent {
314 SwizzleRed = 0x8E42, // GL_TEXTURE_SWIZZLE_R
315 SwizzleGreen = 0x8E43, // GL_TEXTURE_SWIZZLE_G
316 SwizzleBlue = 0x8E44, // GL_TEXTURE_SWIZZLE_B
317 SwizzleAlpha = 0x8E45 // GL_TEXTURE_SWIZZLE_A
318 };
319 Q_ENUM(SwizzleComponent)
320
321 enum SwizzleValue {
322 RedValue = 0x1903, // GL_RED
323 GreenValue = 0x1904, // GL_GREEN
324 BlueValue = 0x1905, // GL_BLUE
325 AlphaValue = 0x1906, // GL_ALPHA
326 ZeroValue = 0, // GL_ZERO
327 OneValue = 1 // GL_ONE
328 };
329 Q_ENUM(SwizzleValue)
330
331 enum WrapMode {
332 Repeat = 0x2901, // GL_REPEAT
333 MirroredRepeat = 0x8370, // GL_MIRRORED_REPEAT
334 ClampToEdge = 0x812F, // GL_CLAMP_TO_EDGE
335 ClampToBorder = 0x812D // GL_CLAMP_TO_BORDER
336 };
337 Q_ENUM(WrapMode)
338
339 enum CoordinateDirection {
340 DirectionS = 0x2802, // GL_TEXTURE_WRAP_S
341 DirectionT = 0x2803, // GL_TEXTURE_WRAP_T
342 DirectionR = 0x8072 // GL_TEXTURE_WRAP_R
343 };
344 Q_ENUM(CoordinateDirection)
345
346 // Features
347 enum Feature {
348 ImmutableStorage = 0x00000001,
349 ImmutableMultisampleStorage = 0x00000002,
350 TextureRectangle = 0x00000004,
351 TextureArrays = 0x00000008,
352 Texture3D = 0x00000010,
353 TextureMultisample = 0x00000020,
354 TextureBuffer = 0x00000040,
355 TextureCubeMapArrays = 0x00000080,
356 Swizzle = 0x00000100,
357 StencilTexturing = 0x00000200,
358 AnisotropicFiltering = 0x00000400,
359 NPOTTextures = 0x00000800,
360 NPOTTextureRepeat = 0x00001000,
361 Texture1D = 0x00002000,
362 TextureComparisonOperators = 0x00004000,
363 TextureMipMapLevel = 0x00008000,
364#ifndef Q_QDOC
365 MaxFeatureFlag = 0x00010000
366#endif
367 };
368 Q_DECLARE_FLAGS(Features, Feature)
369 Q_ENUM(Feature)
370
371 explicit QOpenGLTexture(Target target);
372 explicit QOpenGLTexture(const QImage& image, MipMapGeneration genMipMaps = GenerateMipMaps);
373 ~QOpenGLTexture();
374
375 Target target() const;
376
377 // Creation and destruction
378 bool create();
379 void destroy();
380 bool isCreated() const;
381 GLuint textureId() const;
382
383 // Binding and releasing
384 void bind();
385 void bind(uint unit, TextureUnitReset reset = DontResetTextureUnit);
386 void release();
387 void release(uint unit, TextureUnitReset reset = DontResetTextureUnit);
388
389 bool isBound() const;
390 bool isBound(uint unit);
391 static GLuint boundTextureId(BindingTarget target);
392 static GLuint boundTextureId(uint unit, BindingTarget target);
393
394 // Storage allocation
395 void setFormat(TextureFormat format);
396 TextureFormat format() const;
397 void setSize(int width, int height = 1, int depth = 1);
398 int width() const;
399 int height() const;
400 int depth() const;
401 void setMipLevels(int levels);
402 int mipLevels() const;
403 int maximumMipLevels() const;
404 void setLayers(int layers);
405 int layers() const;
406 int faces() const;
407 void setSamples(int samples);
408 int samples() const;
409 void setFixedSamplePositions(bool fixed);
410 bool isFixedSamplePositions() const;
411 void allocateStorage();
412 void allocateStorage(PixelFormat pixelFormat, PixelType pixelType);
413 bool isStorageAllocated() const;
414
415 QOpenGLTexture *createTextureView(Target target,
416 TextureFormat viewFormat,
417 int minimumMipmapLevel, int maximumMipmapLevel,
418 int minimumLayer, int maximumLayer) const;
419 bool isTextureView() const;
420
421 // Pixel transfer
422 void setData(int mipLevel, int layer, CubeMapFace cubeFace,
423 PixelFormat sourceFormat, PixelType sourceType,
424 const void *data, const QOpenGLPixelTransferOptions * const options = nullptr);
425 void setData(int mipLevel, int layer, int layerCount, CubeMapFace cubeFace,
426 PixelFormat sourceFormat, PixelType sourceType,
427 const void *data, const QOpenGLPixelTransferOptions * const options = nullptr);
428 void setData(int mipLevel, int layer,
429 PixelFormat sourceFormat, PixelType sourceType,
430 const void *data, const QOpenGLPixelTransferOptions * const options = nullptr);
431 void setData(int mipLevel,
432 PixelFormat sourceFormat, PixelType sourceType,
433 const void *data, const QOpenGLPixelTransferOptions * const options = nullptr);
434 void setData(PixelFormat sourceFormat, PixelType sourceType,
435 const void *data, const QOpenGLPixelTransferOptions * const options = nullptr);
436
437 void setData(int xOffset, int yOffset, int zOffset,
438 int width, int height, int depth,
439 PixelFormat sourceFormat, PixelType sourceType,
440 const void *data, const QOpenGLPixelTransferOptions * const options = nullptr);
441 void setData(int xOffset, int yOffset, int zOffset,
442 int width, int height, int depth, int mipLevel,
443 PixelFormat sourceFormat, PixelType sourceType,
444 const void *data, const QOpenGLPixelTransferOptions * const options = nullptr);
445 void setData(int xOffset, int yOffset, int zOffset,
446 int width, int height, int depth,
447 int mipLevel, int layer,
448 PixelFormat sourceFormat, PixelType sourceType,
449 const void *data, const QOpenGLPixelTransferOptions * const options = nullptr);
450 void setData(int xOffset, int yOffset, int zOffset,
451 int width, int height, int depth,
452 int mipLevel, int layer,
453 CubeMapFace cubeFace,
454 PixelFormat sourceFormat, PixelType sourceType,
455 const void *data, const QOpenGLPixelTransferOptions * const options = nullptr);
456 void setData(int xOffset, int yOffset, int zOffset,
457 int width, int height, int depth,
458 int mipLevel, int layer,
459 CubeMapFace cubeFace, int layerCount,
460 PixelFormat sourceFormat, PixelType sourceType,
461 const void *data, const QOpenGLPixelTransferOptions * const options = nullptr);
462
463 // Compressed data upload
464 void setCompressedData(int mipLevel, int layer, CubeMapFace cubeFace,
465 int dataSize, const void *data,
466 const QOpenGLPixelTransferOptions * const options = nullptr);
467 void setCompressedData(int mipLevel, int layer, int layerCount, CubeMapFace cubeFace,
468 int dataSize, const void *data,
469 const QOpenGLPixelTransferOptions * const options = nullptr);
470 void setCompressedData(int mipLevel, int layer,
471 int dataSize, const void *data,
472 const QOpenGLPixelTransferOptions * const options = nullptr);
473 void setCompressedData(int mipLevel, int dataSize, const void *data,
474 const QOpenGLPixelTransferOptions * const options = nullptr);
475 void setCompressedData(int dataSize, const void *data,
476 const QOpenGLPixelTransferOptions * const options = nullptr);
477
478 // Helpful overloads for setData
479 void setData(const QImage& image, MipMapGeneration genMipMaps = GenerateMipMaps);
480
481 static bool hasFeature(Feature feature);
482
483 // Texture Parameters
484 void setMipBaseLevel(int baseLevel);
485 int mipBaseLevel() const;
486 void setMipMaxLevel(int maxLevel);
487 int mipMaxLevel() const;
488 void setMipLevelRange(int baseLevel, int maxLevel);
489 QPair<int, int> mipLevelRange() const;
490
491 void setAutoMipMapGenerationEnabled(bool enabled);
492 bool isAutoMipMapGenerationEnabled() const;
493
494 void generateMipMaps();
495 void generateMipMaps(int baseLevel, bool resetBaseLevel = true);
496
497 void setSwizzleMask(SwizzleComponent component, SwizzleValue value);
498 void setSwizzleMask(SwizzleValue r, SwizzleValue g,
499 SwizzleValue b, SwizzleValue a);
500 SwizzleValue swizzleMask(SwizzleComponent component) const;
501
502 enum DepthStencilMode {
503 DepthMode = 0x1902, // GL_DEPTH_COMPONENT
504 StencilMode = 0x1901 // GL_STENCIL_INDEX
505 };
506 Q_ENUM(DepthStencilMode)
507
508 void setDepthStencilMode(DepthStencilMode mode);
509 DepthStencilMode depthStencilMode() const;
510
511 enum ComparisonFunction {
512 CompareLessEqual = 0x0203, // GL_LEQUAL
513 CompareGreaterEqual = 0x0206, // GL_GEQUAL
514 CompareLess = 0x0201, // GL_LESS
515 CompareGreater = 0x0204, // GL_GREATER
516 CompareEqual = 0x0202, // GL_EQUAL
517 CompareNotEqual = 0x0205, // GL_NOTEQUAL
518 CompareAlways = 0x0207, // GL_ALWAYS
519 CompareNever = 0x0200, // GL_NEVER
520
521#if QT_DEPRECATED_SINCE(6, 1)
522 CommpareNotEqual Q_DECL_ENUMERATOR_DEPRECATED_X(
523 "Use CompareNotEqual instead.") = CompareNotEqual
524#endif
525 };
526 Q_ENUM(ComparisonFunction)
527
528 void setComparisonFunction(ComparisonFunction function);
529 ComparisonFunction comparisonFunction() const;
530
531 enum ComparisonMode {
532 CompareRefToTexture = 0x884E, // GL_COMPARE_REF_TO_TEXTURE
533 CompareNone = 0x0000 // GL_NONE
534 };
535
536 void setComparisonMode(ComparisonMode mode);
537 ComparisonMode comparisonMode() const;
538
539 // Sampling Parameters
540 enum Filter {
541 Nearest = 0x2600, // GL_NEAREST
542 Linear = 0x2601, // GL_LINEAR
543 NearestMipMapNearest = 0x2700, // GL_NEAREST_MIPMAP_NEAREST
544 NearestMipMapLinear = 0x2702, // GL_NEAREST_MIPMAP_LINEAR
545 LinearMipMapNearest = 0x2701, // GL_LINEAR_MIPMAP_NEAREST
546 LinearMipMapLinear = 0x2703 // GL_LINEAR_MIPMAP_LINEAR
547 };
548 Q_ENUM(Filter)
549
550 void setMinificationFilter(Filter filter);
551 Filter minificationFilter() const;
552 void setMagnificationFilter(Filter filter);
553 Filter magnificationFilter() const;
554 void setMinMagFilters(Filter minificationFilter,
555 Filter magnificationFilter);
556 QPair<Filter, Filter> minMagFilters() const;
557 void setMaximumAnisotropy(float anisotropy);
558 float maximumAnisotropy() const;
559
560 void setWrapMode(WrapMode mode);
561 void setWrapMode(CoordinateDirection direction, WrapMode mode);
562 WrapMode wrapMode(CoordinateDirection direction) const;
563
564 void setBorderColor(const QColor &color);
565 void setBorderColor(float r, float g, float b, float a);
566 void setBorderColor(int r, int g, int b, int a);
567 void setBorderColor(uint r, uint g, uint b, uint a);
568
569 QColor borderColor() const;
570 void borderColor(float *border) const;
571 void borderColor(int *border) const;
572 void borderColor(unsigned int *border) const;
573
574 void setMinimumLevelOfDetail(float value);
575 float minimumLevelOfDetail() const;
576 void setMaximumLevelOfDetail(float value);
577 float maximumLevelOfDetail() const;
578 void setLevelOfDetailRange(float min, float max);
579 QPair<float, float> levelOfDetailRange() const;
580 void setLevelofDetailBias(float bias);
581 float levelofDetailBias() const;
582
583#ifndef QT_NO_DEBUG_STREAM
584 friend Q_OPENGL_EXPORT QDebug operator<<(QDebug dbg, const QOpenGLTexture *t);
585#endif
586
587private:
588 Q_DISABLE_COPY(QOpenGLTexture)
589 Q_DECLARE_PRIVATE(QOpenGLTexture)
590 QScopedPointer<QOpenGLTexturePrivate> d_ptr;
591};
592
593Q_DECLARE_OPERATORS_FOR_FLAGS(QOpenGLTexture::Features)
594
595#ifndef QT_NO_DEBUG_STREAM
596Q_OPENGL_EXPORT QDebug operator<<(QDebug debug, const QOpenGLTexture *t);
597#endif
598
599QT_END_NAMESPACE
600
601#endif // QT_NO_OPENGL
602
603#endif // QOPENGLABSTRACTTEXTURE_H
604

source code of qtbase/src/opengl/qopengltexture.h