1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3#ifndef QSURFACEFORMAT_H
4#define QSURFACEFORMAT_H
5
6#include <QtGui/qtguiglobal.h>
7#include <QtCore/qobjectdefs.h>
8
9QT_BEGIN_NAMESPACE
10
11class QColorSpace;
12class QOpenGLContext;
13class QSurfaceFormatPrivate;
14
15class Q_GUI_EXPORT QSurfaceFormat
16{
17 Q_GADGET
18public:
19 enum FormatOption {
20 StereoBuffers = 0x0001,
21 DebugContext = 0x0002,
22 DeprecatedFunctions = 0x0004,
23 ResetNotification = 0x0008,
24 ProtectedContent = 0x0010
25 };
26 Q_ENUM(FormatOption)
27 Q_DECLARE_FLAGS(FormatOptions, FormatOption)
28
29 enum SwapBehavior {
30 DefaultSwapBehavior,
31 SingleBuffer,
32 DoubleBuffer,
33 TripleBuffer
34 };
35 Q_ENUM(SwapBehavior)
36
37 enum RenderableType {
38 DefaultRenderableType = 0x0,
39 OpenGL = 0x1,
40 OpenGLES = 0x2,
41 OpenVG = 0x4
42 };
43 Q_ENUM(RenderableType)
44
45 enum OpenGLContextProfile {
46 NoProfile,
47 CoreProfile,
48 CompatibilityProfile
49 };
50 Q_ENUM(OpenGLContextProfile)
51
52#if QT_DEPRECATED_SINCE(6,0)
53 enum ColorSpace {
54 DefaultColorSpace,
55 sRGBColorSpace
56 };
57 Q_ENUM(ColorSpace)
58#endif
59
60 QSurfaceFormat();
61 Q_IMPLICIT QSurfaceFormat(FormatOptions options);
62 QSurfaceFormat(const QSurfaceFormat &other);
63 QSurfaceFormat &operator=(const QSurfaceFormat &other);
64 ~QSurfaceFormat();
65
66 void setDepthBufferSize(int size);
67 int depthBufferSize() const;
68
69 void setStencilBufferSize(int size);
70 int stencilBufferSize() const;
71
72 void setRedBufferSize(int size);
73 int redBufferSize() const;
74 void setGreenBufferSize(int size);
75 int greenBufferSize() const;
76 void setBlueBufferSize(int size);
77 int blueBufferSize() const;
78 void setAlphaBufferSize(int size);
79 int alphaBufferSize() const;
80
81 void setSamples(int numSamples);
82 int samples() const;
83
84 void setSwapBehavior(SwapBehavior behavior);
85 SwapBehavior swapBehavior() const;
86
87 bool hasAlpha() const;
88
89 void setProfile(OpenGLContextProfile profile);
90 OpenGLContextProfile profile() const;
91
92 void setRenderableType(RenderableType type);
93 RenderableType renderableType() const;
94
95 void setMajorVersion(int majorVersion);
96 int majorVersion() const;
97
98 void setMinorVersion(int minorVersion);
99 int minorVersion() const;
100
101 std::pair<int, int> version() const;
102 void setVersion(int major, int minor);
103
104 bool stereo() const;
105 void setStereo(bool enable);
106
107 void setOptions(QSurfaceFormat::FormatOptions options);
108 void setOption(FormatOption option, bool on = true);
109 bool testOption(FormatOption option) const;
110 QSurfaceFormat::FormatOptions options() const;
111
112 int swapInterval() const;
113 void setSwapInterval(int interval);
114
115 const QColorSpace &colorSpace() const;
116 void setColorSpace(const QColorSpace &colorSpace);
117#if QT_DEPRECATED_SINCE(6,0)
118 Q_DECL_DEPRECATED_X("Use setColorSpace(QColorSpace) instead.")
119 void setColorSpace(ColorSpace colorSpace);
120#endif
121
122 static void setDefaultFormat(const QSurfaceFormat &format);
123 static QSurfaceFormat defaultFormat();
124
125private:
126 QSurfaceFormatPrivate *d;
127
128 void detach();
129 bool equals(const QSurfaceFormat &other) const noexcept;
130
131 friend inline bool operator==(const QSurfaceFormat &lhs, const QSurfaceFormat &rhs) noexcept
132 { return lhs.equals(other: rhs); }
133 friend inline bool operator!=(const QSurfaceFormat &lhs, const QSurfaceFormat &rhs) noexcept
134 { return !lhs.equals(other: rhs); }
135#ifndef QT_NO_DEBUG_STREAM
136 friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QSurfaceFormat &);
137#endif
138};
139
140#ifndef QT_NO_DEBUG_STREAM
141Q_GUI_EXPORT QDebug operator<<(QDebug, const QSurfaceFormat &);
142#endif
143
144Q_DECLARE_OPERATORS_FOR_FLAGS(QSurfaceFormat::FormatOptions)
145
146inline bool QSurfaceFormat::stereo() const
147{
148 return testOption(option: QSurfaceFormat::StereoBuffers);
149}
150
151QT_END_NAMESPACE
152
153#endif //QSURFACEFORMAT_H
154

source code of qtbase/src/gui/kernel/qsurfaceformat.h