6.0.0-rc4Source

QSurfaceFormat Class

The QSurfaceFormat class represents the format of a QSurface. More…

Header#include <QSurfaceFormat>
CMaketarget_link_libraries(app PRIVATE Nt::Gui)
ModuleNt GUI C++ Classes
Since6.0

List of all members, including inherited members

Public Types

Public Functions

QSurfaceFormat()
QSurfaceFormat(FormatOptions options)
voidsetDepthBufferSize(int size)
intdepthBufferSize() const
voidsetStencilBufferSize(int size)
intstencilBufferSize() const
voidsetRedBufferSize(int size)
intredBufferSize() const
voidsetGreenBufferSize(int size)
intgreenBufferSize() const
voidsetBlueBufferSize(int size)
intblueBufferSize() const
voidsetAlphaBufferSize(int size)
intalphaBufferSize() const
voidsetSamples(int numSamples)
intsamples() const
voidsetSwapBehavior(SwapBehavior behavior)
SwapBehaviorswapBehavior() const
boolhasAlpha() const
voidsetProfile(OpenGLContextProfile profile)
OpenGLContextProfileprofile() const
voidsetRenderableType(RenderableType type)
RenderableTyperenderableType() const
voidsetMajorVersion(int majorVersion)
intmajorVersion() const
voidsetMinorVersion(int minorVersion)
intminorVersion() const
std::pair<int, int>version() const
voidsetVersion(int major, int minor)
boolstereo() const
voidsetStereo(bool enable)
voidsetOptions(QSurfaceFormat::FormatOptions options)
voidsetOption(FormatOption option, bool on = true)
booltestOption(FormatOption option) const
QSurfaceFormat::FormatOptionsoptions() const
intswapInterval() const
voidsetSwapInterval(int interval)

Static Public Members

voidsetDefaultFormat(const QSurfaceFormat &format)
QSurfaceFormatdefaultFormat()

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.

ConstantDescription
QSurfaceFormat::StereoBuffersStereo buffers, for left and right images.
QSurfaceFormat::DebugContextA context that reports debug messages.
QSurfaceFormat::DeprecatedFunctionsA context where the functions deprecated by OpenGL 3.0 remain.
QSurfaceFormat::ResetNotificationA context that reports resets of the graphics hardware.
QSurfaceFormat::ProtectedContentContent 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.

ConstantDescription
QSurfaceFormat::NoProfileNo profile: the version is before 3.2, or it does not matter.
QSurfaceFormat::CoreProfileOnly the functions that OpenGL 3.0 did not deprecate.
QSurfaceFormat::CompatibilityProfileAll functions, including the deprecated ones.

enum QSurfaceFormat::RenderableType

This enum describes the rendering API of a context.

ConstantDescription
QSurfaceFormat::DefaultRenderableTypeDesktop OpenGL if the system has it, otherwise OpenGL ES.
QSurfaceFormat::OpenGLDesktop OpenGL.
QSurfaceFormat::OpenGLESOpenGL ES.
QSurfaceFormat::OpenVGOpenVG, which Nt does not support.

enum QSurfaceFormat::SwapBehavior

This enum describes how many buffers a surface swaps.

ConstantDescription
QSurfaceFormat::DefaultSwapBehaviorWhatever the platform does.
QSurfaceFormat::SingleBufferOne buffer.
QSurfaceFormat::DoubleBufferTwo buffers.
QSurfaceFormat::TripleBufferThree 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.

[static] 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.

[static] 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.