QSurfaceFormat Class
The QSurfaceFormat class represents the format of a QSurface. More…
| Header | #include <QSurfaceFormat> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Gui) |
| Module | Nt GUI C++ Classes |
| Since | 6.0 |
List of all members, including inherited members
Public Types
| enum | FormatOption |
| typedef | FormatOptions |
| enum | SwapBehavior |
| enum | RenderableType |
| enum | OpenGLContextProfile |
Public Functions
| QSurfaceFormat() | |
| QSurfaceFormat(FormatOptions options) | |
| void | setDepthBufferSize(int size) |
| int | depthBufferSize() const |
| void | setStencilBufferSize(int size) |
| int | stencilBufferSize() const |
| void | setRedBufferSize(int size) |
| int | redBufferSize() const |
| void | setGreenBufferSize(int size) |
| int | greenBufferSize() const |
| void | setBlueBufferSize(int size) |
| int | blueBufferSize() const |
| void | setAlphaBufferSize(int size) |
| int | alphaBufferSize() const |
| void | setSamples(int numSamples) |
| int | samples() const |
| void | setSwapBehavior(SwapBehavior behavior) |
| SwapBehavior | swapBehavior() const |
| bool | hasAlpha() const |
| void | setProfile(OpenGLContextProfile profile) |
| OpenGLContextProfile | profile() const |
| void | setRenderableType(RenderableType type) |
| RenderableType | renderableType() const |
| void | setMajorVersion(int majorVersion) |
| int | majorVersion() const |
| void | setMinorVersion(int minorVersion) |
| int | minorVersion() const |
| std::pair<int, int> | version() const |
| void | setVersion(int major, int minor) |
| bool | stereo() const |
| void | setStereo(bool enable) |
| void | setOptions(QSurfaceFormat::FormatOptions options) |
| void | setOption(FormatOption option, bool on = true) |
| bool | testOption(FormatOption option) const |
| QSurfaceFormat::FormatOptions | options() const |
| int | swapInterval() const |
| void | setSwapInterval(int interval) |
Static Public Members
| void | setDefaultFormat(const QSurfaceFormat &format) |
| QSurfaceFormat | defaultFormat() |
Detailed Description
The format describes the buffers an OpenGL surface asks for (the sizes of the color, depth and stencil buffers and the number of samples for multisampling), the OpenGL version and profile of the context, and the swap interval:
QSurfaceFormat format;
format.setDepthBufferSize(24);
format.setStencilBufferSize(8);
format.setSamples(4);
format.setSwapInterval(0); // do not wait for the display
QSurfaceFormat::setDefaultFormat(format);
A size of -1, the default, means no particular size. Set the format on a window with QWindow::setFormat() and on a context with QOpenGLContext::setFormat(), or for all of them with setDefaultFormat() before they are made.
See also QOpenGLContext and QWindow::setFormat().
Differences from Qt
There is no color space. OpenVG is not supported, and the swap behavior is only remembered: windows are double buffered.
Member Type Documentation
enum QSurfaceFormat::FormatOption
This enum describes options of a context.
| Constant | Description |
|---|---|
QSurfaceFormat::StereoBuffers | Stereo buffers, for left and right images. |
QSurfaceFormat::DebugContext | A context that reports debug messages. |
QSurfaceFormat::DeprecatedFunctions | A context where the functions deprecated by OpenGL 3.0 remain. |
QSurfaceFormat::ResetNotification | A context that reports resets of the graphics hardware. |
QSurfaceFormat::ProtectedContent | Content that cannot be read back. |
typedef QSurfaceFormat::FormatOptions
The FormatOptions type is a typedef for QFlags<FormatOption>. It stores an OR combination of FormatOption values.
enum QSurfaceFormat::OpenGLContextProfile
This enum describes the profile of a desktop OpenGL context of version 3.2 or later.
| Constant | Description |
|---|---|
QSurfaceFormat::NoProfile | No profile: the version is before 3.2, or it does not matter. |
QSurfaceFormat::CoreProfile | Only the functions that OpenGL 3.0 did not deprecate. |
QSurfaceFormat::CompatibilityProfile | All functions, including the deprecated ones. |
enum QSurfaceFormat::RenderableType
This enum describes the rendering API of a context.
| Constant | Description |
|---|---|
QSurfaceFormat::DefaultRenderableType | Desktop OpenGL if the system has it, otherwise OpenGL ES. |
QSurfaceFormat::OpenGL | Desktop OpenGL. |
QSurfaceFormat::OpenGLES | OpenGL ES. |
QSurfaceFormat::OpenVG | OpenVG, which Nt does not support. |
enum QSurfaceFormat::SwapBehavior
This enum describes how many buffers a surface swaps.
| Constant | Description |
|---|---|
QSurfaceFormat::DefaultSwapBehavior | Whatever the platform does. |
QSurfaceFormat::SingleBuffer | One buffer. |
QSurfaceFormat::DoubleBuffer | Two buffers. |
QSurfaceFormat::TripleBuffer | Three buffers. |
Member Function Documentation
QSurfaceFormat::QSurfaceFormat()
Constructs a format with the defaults: no particular buffer sizes, OpenGL 2.0, no profile, and a swap interval of 1.
QSurfaceFormat::QSurfaceFormat(FormatOptions options)
Constructs a default format with the options set.
int QSurfaceFormat::alphaBufferSize() const
Returns the number of bits of alpha, or -1 for any.
int QSurfaceFormat::blueBufferSize() const
Returns the number of bits of blue, or -1 for any.
QSurfaceFormat QSurfaceFormat::defaultFormat()
Returns the format set with setDefaultFormat(), or a default format.
int QSurfaceFormat::depthBufferSize() const
Returns the number of bits of the depth buffer, or -1 for any.
int QSurfaceFormat::greenBufferSize() const
Returns the number of bits of green, or -1 for any.
bool QSurfaceFormat::hasAlpha() const
Returns true if the format has an alpha buffer.
int QSurfaceFormat::majorVersion() const
Returns the major OpenGL version.
int QSurfaceFormat::minorVersion() const
Returns the minor OpenGL version.
QSurfaceFormat::FormatOptions QSurfaceFormat::options() const
Returns the options.
OpenGLContextProfile QSurfaceFormat::profile() const
Returns the OpenGL profile.
int QSurfaceFormat::redBufferSize() const
Returns the number of bits of red, or -1 for any.
RenderableType QSurfaceFormat::renderableType() const
Returns the rendering API.
int QSurfaceFormat::samples() const
Returns the number of samples per pixel, or -1 for no multisampling.
void QSurfaceFormat::setAlphaBufferSize(int size)
Sets the number of bits of alpha to size.
void QSurfaceFormat::setBlueBufferSize(int size)
Sets the number of bits of blue to size.
void QSurfaceFormat::setDefaultFormat(const QSurfaceFormat &format)
Sets the format that windows, offscreen surfaces and contexts start with to format.
See also defaultFormat().
void QSurfaceFormat::setDepthBufferSize(int size)
Sets the number of bits of the depth buffer to size.
void QSurfaceFormat::setGreenBufferSize(int size)
Sets the number of bits of green to size.
void QSurfaceFormat::setMajorVersion(int majorVersion)
Sets the major OpenGL version to majorVersion.
void QSurfaceFormat::setMinorVersion(int minorVersion)
Sets the minor OpenGL version to minorVersion.
void QSurfaceFormat::setOption(FormatOption option, bool on = true)
Sets option on if on is true, and off otherwise.
See also testOption() and setOptions().
void QSurfaceFormat::setOptions(QSurfaceFormat::FormatOptions options)
Sets the options to options.
void QSurfaceFormat::setProfile(OpenGLContextProfile profile)
Sets the OpenGL profile to profile.
void QSurfaceFormat::setRedBufferSize(int size)
Sets the number of bits of red to size.
void QSurfaceFormat::setRenderableType(RenderableType type)
Sets the rendering API to type.
void QSurfaceFormat::setSamples(int numSamples)
Sets the number of samples per pixel for multisampling to numSamples. With more than one, QPainter on an OpenGL surface draws antialiased.
void QSurfaceFormat::setStencilBufferSize(int size)
Sets the number of bits of the stencil buffer to size.
void QSurfaceFormat::setStereo(bool enable)
Asks for stereo buffers if enable is true.
void QSurfaceFormat::setSwapBehavior(SwapBehavior behavior)
Sets the swap behavior to behavior.
void QSurfaceFormat::setSwapInterval(int interval)
Sets the swap interval to interval. With 0, swapping does not wait for the display, so rendering is not capped by its refresh rate.
void QSurfaceFormat::setVersion(int major, int minor)
Sets the OpenGL version to major and minor.
int QSurfaceFormat::stencilBufferSize() const
Returns the number of bits of the stencil buffer, or -1 for any.
bool QSurfaceFormat::stereo() const
Returns true if the format has stereo buffers.
SwapBehavior QSurfaceFormat::swapBehavior() const
Returns the swap behavior.
int QSurfaceFormat::swapInterval() const
Returns the swap interval: the number of display refreshes QOpenGLContext::swapBuffers() waits for. The default is 1, which synchronizes with the display (vsync).
bool QSurfaceFormat::testOption(FormatOption option) const
Returns true if option is set.
std::pair<int, int> QSurfaceFormat::version() const
Returns the major and minor OpenGL version.