The QPlatformWindowFormat class specifies the display format of an OpenGL rendering context and if possible attributes of the corresponding QPlatformWindow. 更多...
| 头: | #include <QPlatformWindowFormat> |
| Since: | Qt 4.8 |
| enum | FormatOption { DoubleBuffer, DepthBuffer, Rgba, AlphaChannel, ..., NoWindowSurface } |
| flags | FormatOptions |
| enum | WindowApi { Raster, OpenGL, OpenVG } |
| QPlatformWindowFormat () | |
| QPlatformWindowFormat (FormatOptions options ) | |
| QPlatformWindowFormat (const QPlatformWindowFormat & other ) | |
| ~QPlatformWindowFormat () | |
| bool | accum () const |
| int | accumBufferSize () const |
| bool | alpha () const |
| int | alphaBufferSize () const |
| int | blueBufferSize () const |
| bool | depth () const |
| int | depthBufferSize () const |
| bool | directRendering () const |
| bool | doubleBuffer () const |
| int | greenBufferSize () const |
| bool | hasWindowSurface () const |
| int | redBufferSize () const |
| bool | rgba () const |
| bool | sampleBuffers () const |
| int | samples () const |
| void | setAccum (bool enable ) |
| void | setAccumBufferSize (int size ) |
| void | setAlpha (bool enable ) |
| void | setAlphaBufferSize (int size ) |
| void | setBlueBufferSize (int size ) |
| void | setDepth (bool enable ) |
| void | setDepthBufferSize (int size ) |
| void | setDirectRendering (bool enable ) |
| void | setDoubleBuffer (bool enable ) |
| void | setGreenBufferSize (int size ) |
| void | setOption (QPlatformWindowFormat::FormatOptions opt ) |
| void | setRedBufferSize (int size ) |
| void | setRgba (bool enable ) |
| void | setSampleBuffers (bool enable ) |
| void | setSamples (int numSamples ) |
| void | setSharedContext (QPlatformGLContext * context ) |
| void | setStencil (bool enable ) |
| void | setStencilBufferSize (int size ) |
| void | setStereo (bool enable ) |
| void | setSwapInterval (int interval ) |
| void | setWindowApi (QPlatformWindowFormat::WindowApi api ) |
| void | setWindowSurface (bool enable ) |
| QPlatformGLContext * | sharedGLContext () const |
| bool | stencil () const |
| int | stencilBufferSize () const |
| bool | stereo () const |
| int | swapInterval () const |
| bool | testOption (QPlatformWindowFormat::FormatOptions opt ) const |
| WindowApi | windowApi () const |
| QPlatformWindowFormat & | operator= (const QPlatformWindowFormat & other ) |
| QPlatformWindowFormat | defaultFormat () |
| void | setDefaultFormat (const QPlatformWindowFormat & f ) |
| bool | operator!= (const QPlatformWindowFormat & a , const QPlatformWindowFormat & b ) |
| bool | operator== (const QPlatformWindowFormat & a , const QPlatformWindowFormat & b ) |
The QPlatformWindowFormat class specifies the display format of an OpenGL rendering context and if possible attributes of the corresponding QPlatformWindow.
QWidget has a setter and getter function for QPlatformWindowFormat . These functions can be used by the application programmer to signal what kind of format he wants to the window and glcontext should have. However, it is not always possible to fulfill these requirements. The application programmer should therefore check the resulting QPlatformWindowFormat from QPlatformGLContext to see the format that was actually created.
A display format has several characteristics:
You can also specify preferred bit depths for the color buffer, depth buffer, alpha buffer, accumulation buffer and the stencil buffer with the functions: setRedBufferSize (), setGreenBufferSize (), setBlueBufferSize (), setDepthBufferSize (), setAlphaBufferSize (), setAccumBufferSize () 和 setStencilBufferSize ().
Note that even if you specify that you prefer a 32 bit depth buffer (e.g. with setDepthBufferSize (32)), the format that is chosen may not have a 32 bit depth buffer, even if there is a format available with a 32 bit depth buffer. The main reason for this is how the system dependant picking algorithms work on the different platforms, and some format options may have higher precedence than others.
You create and tell a QPlatformWindowFormat object what rendering options you want from an OpenGL rendering context.
OpenGL drivers or accelerated hardware may or may not support advanced features such as alpha channel or stereographic viewing. If you request some features that the driver/hardware does not provide when you create a QGLWidget , you will get a rendering context with the nearest subset of features.
There are different ways to define the display characteristics of a rendering context. One is to create a QPlatformWindowFormat and make it the default for the entire application:
QGLFormat fmt; fmt.setAlpha(true); fmt.setStereo(true); QGLFormat::setDefaultFormat(fmt);
Or you can specify the desired format when creating an object of your QGLWidget subclass:
QGLFormat fmt; fmt.setDoubleBuffer(false); // single buffer fmt.setDirectRendering(false); // software rendering MyGLWidget* myWidget = new MyGLWidget(fmt, ...);
After the widget has been created, you can find out which of the requested features the system was able to provide:
QGLFormat fmt; fmt.setOverlay(true); fmt.setStereo(true); MyGLWidget* myWidget = new MyGLWidget(fmt, ...); if (!myWidget->format().stereo()) { // ok, goggles off if (!myWidget->format().hasOverlay()) { qFatal("Cool hardware required"); } }
OpenGL 是 Silicon (硅谷) 图形公司在美国及其它国家的商标。
另请参阅 QPlatformGLContext and QWidget .
FormatOptions 类型是 typedef 对于 QFlags <FormatOption>。它存储 FormatOption 值的 OR 组合。
构造 QPlatformWindowFormat object with the following default settings:
创建 QPlatformWindowFormat object that is a copy of the current defaultFormat ().
若 options is not 0, the default format is modified by the specified format options. The options parameter should be QGL::FormatOption values OR'ed together.
This constructor makes it easy to specify a certain desired format in classes derived from QGLWidget ,例如:
// The rendering in MyGLWidget depends on using // stencil buffer and alpha channel MyGLWidget::MyGLWidget(QWidget* parent) : QGLWidget(QGLFormat(QGL::StencilBuffer | QGL::AlphaChannel), parent) { if (!format().stencil()) qWarning("Could not get stencil buffer; results will be suboptimal"); if (!format().alpha()) qWarning("Could not get alpha channel; results will be suboptimal"); ... }
Note that there are QGL::FormatOption values to turn format settings both on and off; e.g., QGL::DepthBuffer and QGL::NoDepthBuffer , QGL::DirectRendering and QGL::IndirectRendering ,等。
另请参阅 defaultFormat () 和 setOption ().
构造副本为 other .
Returns true if the accumulation buffer is enabled; otherwise returns false. The accumulation buffer is disabled by default.
另请参阅 setAccum () 和 setAccumBufferSize ().
Returns the accumulation buffer size.
另请参阅 setAccumBufferSize (), accum (),和 setAccum ().
Returns true if the alpha buffer in the framebuffer is enabled; otherwise returns false. The alpha buffer is disabled by default.
另请参阅 setAlpha () 和 setAlphaBufferSize ().
Returns the alpha buffer size.
另请参阅 alpha (), setAlpha (),和 setAlphaBufferSize ().
Returns the blue buffer size.
该函数在 Qt 4.2 引入。
另请参阅 setBlueBufferSize ().
[static]
QPlatformWindowFormat
QPlatformWindowFormat::
defaultFormat
()
Returns the default QPlatformWindowFormat for the application. All QGLWidget objects that are created use this format unless another format is specified, e.g. when they are constructed.
If no special default format has been set using setDefaultFormat (), the default format is the same as that created with QPlatformWindowFormat ().
另请参阅 setDefaultFormat ().
Returns true if the depth buffer is enabled; otherwise returns false. The depth buffer is enabled by default.
另请参阅 setDepth () 和 setDepthBufferSize ().
返回深度缓冲大小。
另请参阅 depth (), setDepth (),和 setDepthBufferSize ().
Returns true if direct rendering is enabled; otherwise returns false.
Direct rendering is enabled by default.
另请参阅 setDirectRendering ().
Returns true if double buffering is enabled; otherwise returns false. Double buffering is enabled by default.
另请参阅 setDoubleBuffer ().
Returns the green buffer size.
该函数在 Qt 4.2 引入。
另请参阅 setGreenBufferSize ().
Returns true if the corresponding widget has an instance of QWindowSurface.
Otherwise returns false.
WindowSurface is enabled by default.
Returns the red buffer size.
该函数在 Qt 4.2 引入。
另请参阅 setRedBufferSize ().
Returns true if RGBA color mode is set. Returns false if color index mode is set. The default color mode is RGBA.
另请参阅 setRgba ().
Returns true if multisample buffer support is enabled; otherwise returns false.
The multisample buffer is disabled by default.
另请参阅 setSampleBuffers ().
Returns the number of samples per pixel when multisampling is enabled. By default, the highest number of samples that is available is used.
另请参阅 setSampleBuffers (), sampleBuffers (),和 setSamples ().
若 enable is true enables the accumulation buffer; otherwise disables the accumulation buffer.
The accumulation buffer is disabled by default.
The accumulation buffer is used to create blur effects and multiple exposures.
另请参阅 accum () 和 setAccumBufferSize ().
Set the preferred accumulation buffer size, where size is the bit depth for each RGBA component.
另请参阅 accum (), setAccum (),和 accumBufferSize ().
若 enable is true enables the alpha buffer; otherwise disables the alpha buffer.
The alpha buffer is disabled by default.
The alpha buffer is typically used for implementing transparency or translucency. The A in RGBA specifies the transparency of a pixel.
另请参阅 alpha () 和 setAlphaBufferSize ().
Set the preferred alpha buffer size to size . This function implicitly enables the alpha channel.
另请参阅 setRedBufferSize (), setGreenBufferSize (),和 alphaBufferSize ().
Set the preferred blue buffer size to size .
该函数在 Qt 4.2 引入。
另请参阅 blueBufferSize (), setRedBufferSize (), setGreenBufferSize (),和 setAlphaBufferSize ().
[static]
void
QPlatformWindowFormat::
setDefaultFormat
(const
QPlatformWindowFormat
&
f
)
Sets a new default QPlatformWindowFormat for the application to f . For example, to set single buffering as the default instead of double buffering, your main() might contain code like this:
QApplication a(argc, argv); QGLFormat f; f.setDoubleBuffer(false); QGLFormat::setDefaultFormat(f);
另请参阅 defaultFormat ().
若 enable is true enables the depth buffer; otherwise disables the depth buffer.
The depth buffer is enabled by default.
The purpose of a depth buffer (or Z-buffering) is to remove hidden surfaces. Pixels are assigned Z values based on the distance to the viewer. A pixel with a high Z value is closer to the viewer than a pixel with a low Z value. This information is used to decide whether to draw a pixel or not.
另请参阅 depth () 和 setDepthBufferSize ().
Set the minimum depth buffer size to size .
另请参阅 depthBufferSize (), setDepth (),和 depth ().
若 enable is true enables direct rendering; otherwise disables direct rendering.
Direct rendering is enabled by default.
Enabling this option will make OpenGL bypass the underlying window system and render directly from hardware to the screen, if this is supported by the system.
另请参阅 directRendering ().
若 enable is true sets double buffering; otherwise sets single buffering.
Double buffering is enabled by default.
Double buffering is a technique where graphics are rendered on an off-screen buffer and not directly to the screen. When the drawing has been completed, the program calls a swapBuffers() function to exchange the screen contents with the buffer. The result is flicker-free drawing and often better performance.
另请参阅 doubleBuffer (), QGLContext::swapBuffers (),和 QGLWidget::swapBuffers ().
Set the preferred green buffer size to size .
该函数在 Qt 4.2 引入。
另请参阅 greenBufferSize (), setRedBufferSize (), setBlueBufferSize (),和 setAlphaBufferSize ().
Sets the format option to opt .
另请参阅 testOption ().
Set the preferred red buffer size to size .
该函数在 Qt 4.2 引入。
另请参阅 redBufferSize (), setGreenBufferSize (), setBlueBufferSize (),和 setAlphaBufferSize ().
若 enable is true sets RGBA mode. If enable is false sets color index mode.
The default color mode is RGBA.
RGBA is the preferred mode for most OpenGL applications. In RGBA color mode you specify colors as red + green + blue + alpha quadruplets.
In color index mode you specify an index into a color lookup table.
另请参阅 rgba ().
若 enable is true, a GL context with multisample buffer support is picked; otherwise ignored.
另请参阅 sampleBuffers (), setSamples (),和 samples ().
Set the preferred number of samples per pixel when multisampling is enabled to numSamples . By default, the highest number of samples available is used.
另请参阅 setSampleBuffers (), sampleBuffers (),和 samples ().
若 enable is true enables the stencil buffer; otherwise disables the stencil buffer.
The stencil buffer is enabled by default.
The stencil buffer masks certain parts of the drawing area so that masked parts are not drawn on.
另请参阅 stencil () 和 setStencilBufferSize ().
将首选蜡纸缓冲大小设为 size .
另请参阅 stencilBufferSize (), setStencil (),和 stencil ().
若 enable is true enables stereo buffering; otherwise disables stereo buffering.
默认情况下,立体缓冲是禁用的。
Stereo buffering provides extra color buffers to generate left-eye and right-eye images.
另请参阅 stereo ().
Set the preferred swap interval. This can be used to sync the GL drawing into a system 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.
Under Windows and under X11, where the
WGL_EXT_swap_control
and
GLX_SGI_video_sync
extensions are used, the
interval
parameter can be used to set the minimum number of video frames that are displayed before a buffer swap will occur. In effect, setting the
interval
to 10, means there will be 10 vertical retraces between every buffer swap.
Under Windows the
WGL_EXT_swap_control
extension has to be present, and under X11 the
GLX_SGI_video_sync
extension has to be present.
该函数在 Qt 4.2 引入。
另请参阅 swapInterval ().
另请参阅 windowApi ().
若 enable is true a top level QWidget will create a QWindowSurface at creation;
otherwise the QWidget will only have a QPlatformWindow.
This is useful for QGLWidget where the QPlatformGLContext controls the surface.
另请参阅 hasWindowSurface ().
Returns true if the stencil buffer is enabled; otherwise returns false. The stencil buffer is enabled by default.
另请参阅 setStencil () 和 setStencilBufferSize ().
Returns the stencil buffer size.
另请参阅 stencil (), setStencil (),和 setStencilBufferSize ().
Returns true if stereo buffering is enabled; otherwise returns false. Stereo buffering is disabled by default.
另请参阅 setStereo ().
Returns the currently set swap interval. -1 is returned if setting the swap interval isn't supported in the system GL implementation.
该函数在 Qt 4.2 引入。
另请参阅 setSwapInterval ().
Returns true if format option opt 有设置;否则返回 false。
另请参阅 setOption ().
另请参阅 setWindowApi ().
赋值 other 到此对象。
Returns false if all the options of the two QPlatformWindowFormat 对象 a and b are equal; otherwise returns true.
该函数在 Qt 4.8 引入。
Returns true if all the options of the two QPlatformWindowFormat 对象 a and b 相等;否则返回 false。
该函数在 Qt 4.8 引入。