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