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 QABSTRACTOPENGLTEXTURE_P_H |
5 | #define QABSTRACTOPENGLTEXTURE_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #ifndef QT_NO_OPENGL |
19 | |
20 | #include <QtOpenGL/qtopenglglobal.h> |
21 | #include "private/qobject_p.h" |
22 | #include "qopengltexture.h" |
23 | #include "qopengl.h" |
24 | |
25 | #include <cmath> |
26 | |
27 | namespace { |
28 | inline double qLog2(const double x) |
29 | { |
30 | return std::log(x: x) / std::log(x: 2.0); |
31 | } |
32 | } |
33 | |
34 | QT_BEGIN_NAMESPACE |
35 | |
36 | class QOpenGLContext; |
37 | class QOpenGLTextureHelper; |
38 | class QOpenGLFunctions; |
39 | |
40 | class QOpenGLTexturePrivate |
41 | { |
42 | public: |
43 | QOpenGLTexturePrivate(QOpenGLTexture::Target textureTarget, |
44 | QOpenGLTexture *qq); |
45 | ~QOpenGLTexturePrivate(); |
46 | |
47 | Q_DECLARE_PUBLIC(QOpenGLTexture) |
48 | |
49 | void resetFuncs(QOpenGLTextureHelper *funcs); |
50 | void initializeOpenGLFunctions(); |
51 | |
52 | bool create(); |
53 | void destroy(); |
54 | |
55 | void bind(); |
56 | void bind(uint unit, QOpenGLTexture::TextureUnitReset reset = QOpenGLTexture::DontResetTextureUnit); |
57 | void release(); |
58 | void release(uint unit, QOpenGLTexture::TextureUnitReset reset = QOpenGLTexture::DontResetTextureUnit); |
59 | bool isBound() const; |
60 | bool isBound(uint unit) const; |
61 | |
62 | void allocateStorage(QOpenGLTexture::PixelFormat pixelFormat, QOpenGLTexture::PixelType pixelType); |
63 | void allocateMutableStorage(QOpenGLTexture::PixelFormat pixelFormat, QOpenGLTexture::PixelType pixelType); |
64 | void allocateImmutableStorage(); |
65 | void setData(int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace, |
66 | QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, |
67 | const void *data, const QOpenGLPixelTransferOptions * const options); |
68 | void setData(int xOffset, int yOffset, int zOffset, int width, int height, int depth, |
69 | int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace, |
70 | QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType, |
71 | const void *data, const QOpenGLPixelTransferOptions * const options); |
72 | void setCompressedData(int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace, |
73 | int dataSize, const void *data, |
74 | const QOpenGLPixelTransferOptions * const options); |
75 | |
76 | |
77 | void setWrapMode(QOpenGLTexture::WrapMode mode); |
78 | void setWrapMode(QOpenGLTexture::CoordinateDirection direction, QOpenGLTexture::WrapMode mode); |
79 | QOpenGLTexture::WrapMode wrapMode(QOpenGLTexture::CoordinateDirection direction) const; |
80 | |
81 | QOpenGLTexture *createTextureView(QOpenGLTexture::Target target, QOpenGLTexture::TextureFormat viewFormat, |
82 | int minimumMipmapLevel, int maximumMipmapLevel, |
83 | int minimumLayer, int maximumLayer) const; |
84 | |
85 | int evaluateMipLevels() const; |
86 | |
87 | inline int maximumMipLevelCount() const |
88 | { |
89 | return 1 + std::floor(x: qLog2(x: qMax(a: dimensions[0], b: qMax(a: dimensions[1], b: dimensions[2])))); |
90 | } |
91 | |
92 | static inline int mipLevelSize(int mipLevel, int baseLevelSize) |
93 | { |
94 | return std::floor(x: double(qMax(a: 1, b: baseLevelSize >> mipLevel))); |
95 | } |
96 | |
97 | bool isUsingImmutableStorage() const; |
98 | |
99 | QOpenGLTexture *q_ptr; |
100 | QOpenGLContext *context; |
101 | QOpenGLTexture::Target target; |
102 | QOpenGLTexture::BindingTarget bindingTarget; |
103 | GLuint textureId; |
104 | QOpenGLTexture::TextureFormat format; |
105 | QOpenGLTexture::TextureFormatClass formatClass; |
106 | int dimensions[3]; |
107 | int requestedMipLevels; |
108 | int mipLevels; |
109 | int layers; |
110 | int faces; |
111 | |
112 | int samples; |
113 | bool fixedSamplePositions; |
114 | |
115 | int baseLevel; |
116 | int maxLevel; |
117 | |
118 | QOpenGLTexture::SwizzleValue swizzleMask[4]; |
119 | QOpenGLTexture::DepthStencilMode depthStencilMode; |
120 | QOpenGLTexture::ComparisonFunction comparisonFunction; |
121 | QOpenGLTexture::ComparisonMode comparisonMode; |
122 | |
123 | QOpenGLTexture::Filter minFilter; |
124 | QOpenGLTexture::Filter magFilter; |
125 | float maxAnisotropy; |
126 | QOpenGLTexture::WrapMode wrapModes[3]; |
127 | QVariantList borderColor; |
128 | float minLevelOfDetail; |
129 | float maxLevelOfDetail; |
130 | float levelOfDetailBias; |
131 | |
132 | bool textureView; |
133 | bool autoGenerateMipMaps; |
134 | bool storageAllocated; |
135 | |
136 | QOpenGLTextureHelper *texFuncs; |
137 | QOpenGLFunctions *functions; |
138 | |
139 | QOpenGLTexture::Features features; |
140 | }; |
141 | |
142 | QT_END_NAMESPACE |
143 | |
144 | #undef Q_CALL_MEMBER_FUNCTION |
145 | |
146 | #endif // QT_NO_OPENGL |
147 | |
148 | #endif // QABSTRACTOPENGLTEXTURE_P_H |
149 | |