QGLFormat Class
The QGLFormat class specifies the display format of an OpenGL rendering context. More...
| Header: | #include <QGLFormat> |
| qmake: | QT += opengl |
This class is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.
Public Types
| enum | OpenGLContextProfile { NoProfile, CoreProfile, CompatibilityProfile } |
| enum | OpenGLVersionFlag { OpenGL_Version_None, OpenGL_Version_1_1, OpenGL_Version_1_2, OpenGL_Version_1_3, OpenGL_Version_1_4, …, OpenGL_ES_Version_2_0 } |
Detailed Description
A display format has several characteristics:
- Double or single buffering.
- Depth buffer.
- RGBA or color index mode.
- Alpha channel.
- Accumulation buffer.
- Stencil buffer.
- Stereo buffers.
- Direct rendering.
- Presence of an overlay.
- Plane of an overlay.
- Multisample buffers.
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() and 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 QGLFormat 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 QGLFormat 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 is a trademark of Silicon Graphics, Inc. in the United States and other countries.
See also QGLContext and QGLWidget.
Member Type Documentation
enum QGLFormat::OpenGLContextProfile
This enum describes the OpenGL context profiles that can be specified for contexts implementing OpenGL version 3.2 or higher. These profiles are different from OpenGL ES profiles.
| Constant | Value | Description |
|---|---|---|
QGLFormat::NoProfile | 0 | OpenGL version is lower than 3.2. |
QGLFormat::CoreProfile | 1 | Functionality deprecated in OpenGL version 3.0 is not available. |
QGLFormat::CompatibilityProfile | 2 | Functionality from earlier OpenGL versions is available. |
This enum was introduced or modified in Qt 4.7.
enum QGLFormat::OpenGLVersionFlag
This enum describes the various OpenGL versions that are recognized by Qt. Use the QGLFormat::openGLVersionFlags() function to identify which versions that are supported at runtime.
| Constant | Value | Description |
|---|---|---|
QGLFormat::OpenGL_Version_None | 0x00000000 | If no OpenGL is present or if no OpenGL context is current. |
QGLFormat::OpenGL_Version_1_1 | 0x00000001 | OpenGL version 1.1 or higher is present. |
QGLFormat::OpenGL_Version_1_2 | 0x00000002 | OpenGL version 1.2 or higher is present. |
QGLFormat::OpenGL_Version_1_3 | 0x00000004 | OpenGL version 1.3 or higher is present. |
QGLFormat::OpenGL_Version_1_4 | 0x00000008 | OpenGL version 1.4 or higher is present. |
QGLFormat::OpenGL_Version_1_5 | 0x00000010 | OpenGL version 1.5 or higher is present. |
QGLFormat::OpenGL_Version_2_0 | 0x00000020 | OpenGL version 2.0 or higher is present. Note that version 2.0 supports all the functionality of version 1.5. |
QGLFormat::OpenGL_Version_2_1 | 0x00000040 | OpenGL version 2.1 or higher is present. |
QGLFormat::OpenGL_Version_3_0 | 0x00001000 | OpenGL version 3.0 or higher is present. |
QGLFormat::OpenGL_Version_3_1 | 0x00002000 | OpenGL version 3.1 or higher is present. Note that OpenGL version 3.1 or higher does not necessarily support all the features of version 3.0 and lower. |
QGLFormat::OpenGL_Version_3_2 | 0x00004000 | OpenGL version 3.2 or higher is present. |
QGLFormat::OpenGL_Version_3_3 | 0x00008000 | OpenGL version 3.3 or higher is present. |
QGLFormat::OpenGL_Version_4_0 | 0x00010000 | OpenGL version 4.0 or higher is present. |
QGLFormat::OpenGL_Version_4_1 | 0x00020000 | OpenGL version 4.1 or higher is present. |
QGLFormat::OpenGL_Version_4_2 | 0x00040000 | OpenGL version 4.2 or higher is present. |
QGLFormat::OpenGL_Version_4_3 | 0x00080000 | OpenGL version 4.3 or higher is present. |
QGLFormat::OpenGL_ES_CommonLite_Version_1_0 | 0x00000100 | OpenGL ES version 1.0 Common Lite or higher is present. |
QGLFormat::OpenGL_ES_Common_Version_1_0 | 0x00000080 | OpenGL ES version 1.0 Common or higher is present. The Common profile supports all the features of Common Lite. |
QGLFormat::OpenGL_ES_CommonLite_Version_1_1 | 0x00000400 | OpenGL ES version 1.1 Common Lite or higher is present. |
QGLFormat::OpenGL_ES_Common_Version_1_1 | 0x00000200 | OpenGL ES version 1.1 Common or higher is present. The Common profile supports all the features of Common Lite. |
QGLFormat::OpenGL_ES_Version_2_0 | 0x00000800 | OpenGL ES version 2.0 or higher is present. Note that OpenGL ES version 2.0 does not support all the features of OpenGL ES 1.x. So if OpenGL_ES_Version_2_0 is returned, none of the ES 1.x flags are returned. |
See also http://www.opengl.org for more information about the different revisions of OpenGL.
This enum was introduced or modified in Qt 4.2.
See also openGLVersionFlags().