- class QSurfaceFormat#
The
QSurfaceFormat
class represents the format of aQSurface
. More…Synopsis#
Methods#
def
__init__()
def
blueBufferSize()
def
colorSpace()
def
hasAlpha()
def
majorVersion()
def
minorVersion()
def
__ne__()
def
__eq__()
def
options()
def
profile()
def
redBufferSize()
def
renderableType()
def
samples()
def
setColorSpace()
def
setOption()
def
setOptions()
def
setProfile()
def
setSamples()
def
setStereo()
def
setVersion()
def
stereo()
def
swapBehavior()
def
swapInterval()
def
testOption()
def
version()
Static functions#
def
defaultFormat()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description#
The format includes the size of the color buffers, red, green, and blue; the size of the alpha buffer; the size of the depth and stencil buffers; and number of samples per pixel for multisampling. In addition, the format contains surface configuration parameters such as OpenGL profile and version for rendering, whether or not to enable stereo buffers, and swap behaviour.
Note
When troubleshooting context or window format issues, it can be helpful to enable the logging category
qt.qpa.gl
. Depending on the platform, this may print useful debug information when it comes to OpenGL initialization and the native visual or framebuffer configurations whichQSurfaceFormat
gets mapped to.- class FormatOption#
(inherits
enum.Flag
) This enum contains format options for use withQSurfaceFormat
.Constant
Description
QSurfaceFormat.StereoBuffers
Used to request stereo buffers in the surface format.
QSurfaceFormat.DebugContext
Used to request a debug context with extra debugging information.
QSurfaceFormat.DeprecatedFunctions
Used to request that deprecated functions be included in the OpenGL context profile. If not specified, you should get a forward compatible context without support functionality marked as deprecated. This requires OpenGL version 3.0 or higher.
QSurfaceFormat.ResetNotification
Enables notifications about resets of the OpenGL context. The status is then queryable via the context’s
isValid()
function. Note that not setting this flag does not guarantee that context state loss never occurs. Additionally, some implementations may choose to report context loss regardless of this flag. Platforms that support dynamically enabling the monitoring of the loss of context, such as, Windows with WGL, or Linux/X11 (xcb) with GLX, will monitor the status in every call tomakeCurrent()
. SeeisValid()
for more information on this.QSurfaceFormat.ProtectedContent
Enables access to protected content. This allows the GPU to operate on protected resources (surfaces, buffers, textures), for example DRM-protected video content. Currently only implemented for EGL.
- class SwapBehavior#
This enum is used by
QSurfaceFormat
to specify the swap behaviour of a surface. The swap behaviour is mostly transparent to the application, but it affects factors such as rendering latency and throughput.Constant
Description
QSurfaceFormat.DefaultSwapBehavior
The default, unspecified swap behaviour of the platform.
QSurfaceFormat.SingleBuffer
Used to request single buffering, which might result in flickering when OpenGL rendering is done directly to screen without an intermediate offscreen buffer.
QSurfaceFormat.DoubleBuffer
This is typically the default swap behaviour on desktop platforms, consisting of one back buffer and one front buffer. Rendering is done to the back buffer, and then the back buffer and front buffer are swapped, or the contents of the back buffer are copied to the front buffer, depending on the implementation.
QSurfaceFormat.TripleBuffer
This swap behaviour is sometimes used in order to decrease the risk of skipping a frame when the rendering rate is just barely keeping up with the screen refresh rate. Depending on the platform it might also lead to slightly more efficient use of the GPU due to improved pipelining behaviour. Triple buffering comes at the cost of an extra frame of memory usage and latency, and might not be supported depending on the underlying platform.
- class RenderableType#
This enum specifies the rendering backend for the surface.
Constant
Description
QSurfaceFormat.DefaultRenderableType
The default, unspecified rendering method
QSurfaceFormat.OpenGL
Desktop OpenGL rendering
QSurfaceFormat.OpenGLES
OpenGL ES 2.0 rendering
QSurfaceFormat.OpenVG
Open Vector Graphics rendering
- class OpenGLContextProfile#
This enum is used to specify the OpenGL context profile, in conjunction with
setMajorVersion()
andsetMinorVersion()
.Profiles are exposed in OpenGL 3.2 and above, and are used to choose between a restricted core profile, and a compatibility profile which might contain deprecated support functionality.
Note that the core profile might still contain functionality that is deprecated and scheduled for removal in a higher version. To get access to the deprecated functionality for the core profile in the set OpenGL version you can use the
QSurfaceFormat
format optionDeprecatedFunctions
.Constant
Description
QSurfaceFormat.NoProfile
OpenGL version is lower than 3.2. For 3.2 and newer this is same as CoreProfile.
QSurfaceFormat.CoreProfile
Functionality deprecated in OpenGL version 3.0 is not available.
QSurfaceFormat.CompatibilityProfile
Functionality from earlier OpenGL versions is available.
- class ColorSpace#
This enum is used to specify the preferred color space, controlling if the window’s associated default framebuffer is able to do updates and blending in a given encoding instead of the standard linear operations.
Constant
Description
QSurfaceFormat.DefaultColorSpace
The default, unspecified color space.
QSurfaceFormat.sRGBColorSpace
When
GL_ARB_framebuffer_sRGB
orGL_EXT_framebuffer_sRGB
is supported by the platform and this value is set, the window will be created with an sRGB-capable default framebuffer. Note that some platforms may return windows with a sRGB-capable default framebuffer even when not requested explicitly.
- __init__(options)#
- Parameters:
options – Combination of
FormatOption
Constructs a
QSurfaceFormat
with the given formatoptions
.- __init__()
Constructs a default initialized
QSurfaceFormat
.Note
By default OpenGL 2.0 is requested since this provides the highest grade of portability between platforms and OpenGL implementations.
- __init__(other)
- Parameters:
other –
QSurfaceFormat
Constructs a copy of
other
.- alphaBufferSize()#
- Return type:
int
Get the size in bits of the alpha channel of the color buffer.
See also
- blueBufferSize()#
- Return type:
int
Get the size in bits of the blue channel of the color buffer.
See also
- colorSpace()#
- Return type:
Returns the color space.
See also
- static defaultFormat()#
- Return type:
Returns the global default surface format.
When
setDefaultFormat()
is not called, this is a default-constructedQSurfaceFormat
.See also
- depthBufferSize()#
- Return type:
int
Returns the depth buffer size.
See also
- greenBufferSize()#
- Return type:
int
Get the size in bits of the green channel of the color buffer.
See also
- hasAlpha()#
- Return type:
bool
Returns
true
if the alpha buffer size is greater than zero.This means that the surface might be used with per pixel translucency effects.
- majorVersion()#
- Return type:
int
Returns the major OpenGL version.
The default version is 2.0.
See also
- minorVersion()#
- Return type:
int
Returns the minor OpenGL version.
See also
- __ne__(rhs)#
- Parameters:
rhs –
QSurfaceFormat
- Return type:
bool
Returns
false
if all the options of the twoQSurfaceFormat
objectslhs
andrhs
are equal; otherwise returnstrue
.- __eq__(rhs)#
- Parameters:
rhs –
QSurfaceFormat
- Return type:
bool
Returns
true
if all the options of the twoQSurfaceFormat
objectslhs
andrhs
are equal.- options()#
- Return type:
Combination of
FormatOption
Returns the currently set format options.
See also
- profile()#
- Return type:
Get the configured OpenGL context profile.
This setting is ignored if the requested OpenGL version is less than 3.2.
See also
- redBufferSize()#
- Return type:
int
Get the size in bits of the red channel of the color buffer.
See also
- renderableType()#
- Return type:
Gets the renderable type.
Chooses between desktop OpenGL, OpenGL ES, and
OpenVG
.See also
- samples()#
- Return type:
int
Returns the number of samples per pixel when multisampling is enabled, or
-1
when multisampling is disabled. The default return value is-1
.See also
- setAlphaBufferSize(size)#
- Parameters:
size – int
Set the desired
size
in bits of the alpha channel of the color buffer.See also
- setBlueBufferSize(size)#
- Parameters:
size – int
Set the desired
size
in bits of the blue channel of the color buffer.See also
- setColorSpace(colorSpace)#
- Parameters:
colorSpace –
QColorSpace
Sets the preferred
colorSpace
.For example, this allows requesting windows with default framebuffers that are sRGB-capable on platforms that support it.
Note
When the requested color space is not supported by the platform, the request is ignored. Query the
QSurfaceFormat
after window creation to verify if the color space request could be honored or not.Note
This setting controls if the default framebuffer of the window is capable of updates and blending in a given color space. It does not change applications’ output by itself. The applications’ rendering code will still have to opt in via the appropriate OpenGL calls to enable updates and blending to be performed in the given color space instead of using the standard linear operations.
See also
- setColorSpace(colorSpace)
- Parameters:
colorSpace –
ColorSpace
Note
This function is deprecated.
This is an overloaded function.
Use
setColorSpace
(QColorSpace
) instead.Sets the colorspace to one of the predefined values.
See also
- static setDefaultFormat(format)#
- Parameters:
format –
QSurfaceFormat
Sets the global default surface
format
.This format is used by default in
QOpenGLContext
,QWindow
, QOpenGLWidget and similar classes.It can always be overridden on a per-instance basis by using the class in question’s own setFormat() function. However, it is often more convenient to set the format for all windows once at the start of the application. It also guarantees proper behavior in cases where shared contexts are required, because settings the format via this function guarantees that all contexts and surfaces, even the ones created internally by Qt, will use the same format.
Note
When setting Qt::AA_ShareOpenGLContexts, it is strongly recommended to place the call to this function before the construction of the
QGuiApplication
or QApplication. Otherwiseformat
will not be applied to the global share context and therefore issues may arise with context sharing afterwards.See also
- setDepthBufferSize(size)#
- Parameters:
size – int
Set the minimum depth buffer size to
size
.See also
- setGreenBufferSize(size)#
- Parameters:
size – int
Set the desired
size
in bits of the green channel of the color buffer.See also
- setMajorVersion(majorVersion)#
- Parameters:
majorVersion – int
Sets the desired
major
OpenGL version.See also
- setMinorVersion(minorVersion)#
- Parameters:
minorVersion – int
Sets the desired
minor
OpenGL version.The default version is 2.0.
See also
- setOption(option[, on=true])#
- Parameters:
option –
FormatOption
on – bool
Sets the format option
option
ifon
is true; otherwise, clears the option.To verify that an option was respected, compare the actual format to the requested format after surface/context creation.
See also
- setOptions(options)#
- Parameters:
options – Combination of
FormatOption
Sets the format options to
options
.To verify that an option was respected, compare the actual format to the requested format after surface/context creation.
See also
- setProfile(profile)#
- Parameters:
profile –
OpenGLContextProfile
Sets the desired OpenGL context
profile
.This setting is ignored if the requested OpenGL version is less than 3.2.
See also
- setRedBufferSize(size)#
- Parameters:
size – int
Set the desired
size
in bits of the red channel of the color buffer.See also
- setRenderableType(type)#
- Parameters:
type –
RenderableType
Sets the desired renderable
type
.Chooses between desktop OpenGL, OpenGL ES, and
OpenVG
.See also
- setSamples(numSamples)#
- Parameters:
numSamples – int
Set the preferred number of samples per pixel when multisampling is enabled to
numSamples
. By default, multisampling is disabled.See also
- setStencilBufferSize(size)#
- Parameters:
size – int
Set the preferred stencil buffer size to
size
bits.See also
- setStereo(enable)#
- Parameters:
enable – bool
If
enable
is true enables stereo buffering; otherwise disables stereo buffering.Stereo buffering is disabled by default.
Stereo buffering provides extra color buffers to generate left-eye and right-eye images.
See also
- setSwapBehavior(behavior)#
- Parameters:
behavior –
SwapBehavior
Set the swap
behavior
of the surface.The swap behavior specifies whether single, double, or triple buffering is desired. The default,
DefaultSwapBehavior
, gives the default swap behavior of the platform.See also
- setSwapInterval(interval)#
- Parameters:
interval – int
Sets the preferred swap interval. The swap interval specifies the minimum number of video frames that are displayed before a buffer swap occurs. This can be used to sync the GL drawing into a window to the vertical refresh of the screen.
Setting an
interval
value of 0 will turn the vertical refresh syncing off, any value higher than 0 will turn the vertical syncing on. Settinginterval
to a higher value, for example 10, results in having 10 vertical retraces between every buffer swap.The default interval is 1.
Changing the swap interval may not be supported by the underlying platform. In this case, the request will be silently ignored.
See also
- setVersion(major, minor)#
- Parameters:
major – int
minor – int
Sets the desired
major
andminor
OpenGL versions.The default version is 2.0.
See also
- stencilBufferSize()#
- Return type:
int
Returns the stencil buffer size in bits.
See also
- stereo()#
- Return type:
bool
Returns
true
if stereo buffering is enabled; otherwise returns false. Stereo buffering is disabled by default.See also
- swapBehavior()#
- Return type:
Returns the configured swap behaviour.
See also
- swapInterval()#
- Return type:
int
Returns the swap interval.
See also
- testOption(option)#
- Parameters:
option –
FormatOption
- Return type:
bool
Returns true if the format option
option
is set; otherwise returns false.See also
- version()#
- Return type:
.std.pairint,int
Returns a QPair<int, int> representing the OpenGL version.
Useful for version checks, for example format.version() >= qMakePair(3, 2)
See also