1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
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#ifndef QSURFACEFORMAT_H
40#define QSURFACEFORMAT_H
41
42#include <QtGui/qtguiglobal.h>
43#include <QtCore/qpair.h>
44#include <QtCore/qobjectdefs.h>
45
46QT_BEGIN_NAMESPACE
47
48class QColorSpace;
49class QOpenGLContext;
50class QSurfaceFormatPrivate;
51
52class Q_GUI_EXPORT QSurfaceFormat
53{
54 Q_GADGET
55public:
56 enum FormatOption {
57 StereoBuffers = 0x0001,
58 DebugContext = 0x0002,
59 DeprecatedFunctions = 0x0004,
60 ResetNotification = 0x0008,
61 ProtectedContent = 0x0010
62 };
63 Q_ENUM(FormatOption)
64 Q_DECLARE_FLAGS(FormatOptions, FormatOption)
65
66 enum SwapBehavior {
67 DefaultSwapBehavior,
68 SingleBuffer,
69 DoubleBuffer,
70 TripleBuffer
71 };
72 Q_ENUM(SwapBehavior)
73
74 enum RenderableType {
75 DefaultRenderableType = 0x0,
76 OpenGL = 0x1,
77 OpenGLES = 0x2,
78 OpenVG = 0x4
79 };
80 Q_ENUM(RenderableType)
81
82 enum OpenGLContextProfile {
83 NoProfile,
84 CoreProfile,
85 CompatibilityProfile
86 };
87 Q_ENUM(OpenGLContextProfile)
88
89#if QT_DEPRECATED_SINCE(6,0)
90 enum ColorSpace {
91 DefaultColorSpace,
92 sRGBColorSpace
93 };
94 Q_ENUM(ColorSpace)
95#endif
96
97 QSurfaceFormat();
98 Q_IMPLICIT QSurfaceFormat(FormatOptions options);
99 QSurfaceFormat(const QSurfaceFormat &other);
100 QSurfaceFormat &operator=(const QSurfaceFormat &other);
101 ~QSurfaceFormat();
102
103 void setDepthBufferSize(int size);
104 int depthBufferSize() const;
105
106 void setStencilBufferSize(int size);
107 int stencilBufferSize() const;
108
109 void setRedBufferSize(int size);
110 int redBufferSize() const;
111 void setGreenBufferSize(int size);
112 int greenBufferSize() const;
113 void setBlueBufferSize(int size);
114 int blueBufferSize() const;
115 void setAlphaBufferSize(int size);
116 int alphaBufferSize() const;
117
118 void setSamples(int numSamples);
119 int samples() const;
120
121 void setSwapBehavior(SwapBehavior behavior);
122 SwapBehavior swapBehavior() const;
123
124 bool hasAlpha() const;
125
126 void setProfile(OpenGLContextProfile profile);
127 OpenGLContextProfile profile() const;
128
129 void setRenderableType(RenderableType type);
130 RenderableType renderableType() const;
131
132 void setMajorVersion(int majorVersion);
133 int majorVersion() const;
134
135 void setMinorVersion(int minorVersion);
136 int minorVersion() const;
137
138 QPair<int, int> version() const;
139 void setVersion(int major, int minor);
140
141 bool stereo() const;
142 void setStereo(bool enable);
143
144 void setOptions(QSurfaceFormat::FormatOptions options);
145 void setOption(FormatOption option, bool on = true);
146 bool testOption(FormatOption option) const;
147 QSurfaceFormat::FormatOptions options() const;
148
149 int swapInterval() const;
150 void setSwapInterval(int interval);
151
152 const QColorSpace &colorSpace() const;
153 void setColorSpace(const QColorSpace &colorSpace);
154#if QT_DEPRECATED_SINCE(6,0)
155 Q_DECL_DEPRECATED_X("Use setColorSpace(QColorSpace) instead.")
156 void setColorSpace(ColorSpace colorSpace);
157#endif
158
159 static void setDefaultFormat(const QSurfaceFormat &format);
160 static QSurfaceFormat defaultFormat();
161
162private:
163 QSurfaceFormatPrivate *d;
164
165 void detach();
166 bool equals(const QSurfaceFormat &other) const noexcept;
167
168 friend inline bool operator==(const QSurfaceFormat &lhs, const QSurfaceFormat &rhs) noexcept
169 { return lhs.equals(rhs); }
170 friend inline bool operator!=(const QSurfaceFormat &lhs, const QSurfaceFormat &rhs) noexcept
171 { return !lhs.equals(rhs); }
172#ifndef QT_NO_DEBUG_STREAM
173 friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QSurfaceFormat &);
174#endif
175};
176
177#ifndef QT_NO_DEBUG_STREAM
178Q_GUI_EXPORT QDebug operator<<(QDebug, const QSurfaceFormat &);
179#endif
180
181Q_DECLARE_OPERATORS_FOR_FLAGS(QSurfaceFormat::FormatOptions)
182
183inline bool QSurfaceFormat::stereo() const
184{
185 return testOption(QSurfaceFormat::StereoBuffers);
186}
187
188QT_END_NAMESPACE
189
190#endif //QSURFACEFORMAT_H
191