1/****************************************************************************
2**
3** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QABSTRACTOPENGLTEXTURE_P_H
41#define QABSTRACTOPENGLTEXTURE_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#ifndef QT_NO_OPENGL
55
56#include <QtGui/private/qtguiglobal_p.h>
57#include "private/qobject_p.h"
58#include "qopengltexture.h"
59#include "qopengl.h"
60
61#include <cmath>
62
63namespace {
64inline double qLog2(const double x)
65{
66 return std::log(x: x) / std::log(x: 2.0);
67}
68}
69
70QT_BEGIN_NAMESPACE
71
72class QOpenGLContext;
73class QOpenGLTextureHelper;
74class QOpenGLFunctions;
75
76class QOpenGLTexturePrivate
77{
78public:
79 QOpenGLTexturePrivate(QOpenGLTexture::Target textureTarget,
80 QOpenGLTexture *qq);
81 ~QOpenGLTexturePrivate();
82
83 Q_DECLARE_PUBLIC(QOpenGLTexture)
84
85 void resetFuncs(QOpenGLTextureHelper *funcs);
86 void initializeOpenGLFunctions();
87
88 bool create();
89 void destroy();
90
91 void bind();
92 void bind(uint unit, QOpenGLTexture::TextureUnitReset reset = QOpenGLTexture::DontResetTextureUnit);
93 void release();
94 void release(uint unit, QOpenGLTexture::TextureUnitReset reset = QOpenGLTexture::DontResetTextureUnit);
95 bool isBound() const;
96 bool isBound(uint unit) const;
97
98 void allocateStorage(QOpenGLTexture::PixelFormat pixelFormat, QOpenGLTexture::PixelType pixelType);
99 void allocateMutableStorage(QOpenGLTexture::PixelFormat pixelFormat, QOpenGLTexture::PixelType pixelType);
100 void allocateImmutableStorage();
101 void setData(int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace,
102 QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType,
103 const void *data, const QOpenGLPixelTransferOptions * const options);
104 void setData(int xOffset, int yOffset, int zOffset, int width, int height, int depth,
105 int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace,
106 QOpenGLTexture::PixelFormat sourceFormat, QOpenGLTexture::PixelType sourceType,
107 const void *data, const QOpenGLPixelTransferOptions * const options);
108 void setCompressedData(int mipLevel, int layer, int layerCount, QOpenGLTexture::CubeMapFace cubeFace,
109 int dataSize, const void *data,
110 const QOpenGLPixelTransferOptions * const options);
111
112
113 void setWrapMode(QOpenGLTexture::WrapMode mode);
114 void setWrapMode(QOpenGLTexture::CoordinateDirection direction, QOpenGLTexture::WrapMode mode);
115 QOpenGLTexture::WrapMode wrapMode(QOpenGLTexture::CoordinateDirection direction) const;
116
117 QOpenGLTexture *createTextureView(QOpenGLTexture::Target target, QOpenGLTexture::TextureFormat viewFormat,
118 int minimumMipmapLevel, int maximumMipmapLevel,
119 int minimumLayer, int maximumLayer) const;
120
121 int evaluateMipLevels() const;
122
123 inline int maximumMipLevelCount() const
124 {
125 return 1 + std::floor(x: qLog2(x: qMax(a: dimensions[0], b: qMax(a: dimensions[1], b: dimensions[2]))));
126 }
127
128 static inline int mipLevelSize(int mipLevel, int baseLevelSize)
129 {
130 return std::floor(x: double(qMax(a: 1, b: baseLevelSize >> mipLevel)));
131 }
132
133 bool isUsingImmutableStorage() const;
134
135 QOpenGLTexture *q_ptr;
136 QOpenGLContext *context;
137 QOpenGLTexture::Target target;
138 QOpenGLTexture::BindingTarget bindingTarget;
139 GLuint textureId;
140 QOpenGLTexture::TextureFormat format;
141 QOpenGLTexture::TextureFormatClass formatClass;
142 int dimensions[3];
143 int requestedMipLevels;
144 int mipLevels;
145 int layers;
146 int faces;
147
148 int samples;
149 bool fixedSamplePositions;
150
151 int baseLevel;
152 int maxLevel;
153
154 QOpenGLTexture::SwizzleValue swizzleMask[4];
155 QOpenGLTexture::DepthStencilMode depthStencilMode;
156 QOpenGLTexture::ComparisonFunction comparisonFunction;
157 QOpenGLTexture::ComparisonMode comparisonMode;
158
159 QOpenGLTexture::Filter minFilter;
160 QOpenGLTexture::Filter magFilter;
161 float maxAnisotropy;
162 QOpenGLTexture::WrapMode wrapModes[3];
163 QVariantList borderColor;
164 float minLevelOfDetail;
165 float maxLevelOfDetail;
166 float levelOfDetailBias;
167
168 bool textureView;
169 bool autoGenerateMipMaps;
170 bool storageAllocated;
171
172 QOpenGLTextureHelper *texFuncs;
173 QOpenGLFunctions *functions;
174
175 QOpenGLTexture::Features features;
176};
177
178QT_END_NAMESPACE
179
180#undef Q_CALL_MEMBER_FUNCTION
181
182#endif // QT_NO_OPENGL
183
184#endif // QABSTRACTOPENGLTEXTURE_P_H
185

source code of qtbase/src/gui/opengl/qopengltexture_p.h