Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QGLFormat Class

TheQGLFormat class specifies the display format of anOpenGL rendering context.More...

Header:#include <QGLFormat>

Public Types

enumOpenGLContextProfile { NoProfile, CoreProfile, CompatibilityProfile }
enumOpenGLVersionFlag { OpenGL_Version_None, OpenGL_Version_1_1, OpenGL_Version_1_2, OpenGL_Version_1_3, ..., OpenGL_ES_Version_2_0 }
flagsOpenGLVersionFlags

Public Functions

QGLFormat()
QGLFormat(QGL::FormatOptions options, int plane = 0)
QGLFormat(const QGLFormat & other)
~QGLFormat()
boolaccum() const
intaccumBufferSize() const
boolalpha() const
intalphaBufferSize() const
intblueBufferSize() const
booldepth() const
intdepthBufferSize() const
booldirectRendering() const
booldoubleBuffer() const
intgreenBufferSize() const
boolhasOverlay() const
intmajorVersion() const
intminorVersion() const
intplane() const
OpenGLContextProfileprofile() const
intredBufferSize() const
boolrgba() const
boolsampleBuffers() const
intsamples() const
voidsetAccum(bool enable)
voidsetAccumBufferSize(int size)
voidsetAlpha(bool enable)
voidsetAlphaBufferSize(int size)
voidsetBlueBufferSize(int size)
voidsetDepth(bool enable)
voidsetDepthBufferSize(int size)
voidsetDirectRendering(bool enable)
voidsetDoubleBuffer(bool enable)
voidsetGreenBufferSize(int size)
voidsetOption(QGL::FormatOptions opt)
voidsetOverlay(bool enable)
voidsetPlane(int plane)
voidsetProfile(OpenGLContextProfile profile)
voidsetRedBufferSize(int size)
voidsetRgba(bool enable)
voidsetSampleBuffers(bool enable)
voidsetSamples(int numSamples)
voidsetStencil(bool enable)
voidsetStencilBufferSize(int size)
voidsetStereo(bool enable)
voidsetSwapInterval(int interval)
voidsetVersion(int major, int minor)
boolstencil() const
intstencilBufferSize() const
boolstereo() const
intswapInterval() const
booltestOption(QGL::FormatOptions opt) const
QGLFormat &operator=(const QGLFormat & other)

Static Public Members

QGLFormatdefaultFormat()
QGLFormatdefaultOverlayFormat()
QGLFormatfromPlatformWindowFormat(const QPlatformWindowFormat & format)
boolhasOpenGL()
boolhasOpenGLOverlays()
OpenGLVersionFlagsopenGLVersionFlags()
voidsetDefaultFormat(const QGLFormat & f)
voidsetDefaultOverlayFormat(const QGLFormat & f)
QPlatformWindowFormattoPlatformWindowFormat(const QGLFormat & format)

Related Non-Members

booloperator!=(const QGLFormat & a, const QGLFormat & b)
booloperator==(const QGLFormat & a, const QGLFormat & b)

Detailed Description

TheQGLFormat class specifies the display format of anOpenGL rendering context.

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() andsetStencilBufferSize().

Note that even if you specify that you prefer a 32 bit depth buffer (e.g. withsetDepthBufferSize(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 aQGLFormat object what rendering options you want from anOpenGL 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 aQGLWidget, 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 aQGLFormat 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 yourQGLWidget subclass:

QGLFormat fmt;fmt.setDoubleBuffer(false);// single bufferfmt.setDirectRendering(false);// software renderingMyGLWidget* 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 offif (!myWidget->format().hasOverlay()) {qFatal("Cool hardware required");    }}

OpenGL is a trademark of Silicon Graphics, Inc. in the United States and other countries.

See alsoQGLContext andQGLWidget.

Member Type Documentation

enum QGLFormat::OpenGLContextProfile

This enum describes theOpenGL context profiles that can be specified for contexts implementingOpenGL version 3.2 or higher. These profiles are different fromOpenGL ES profiles.

ConstantValueDescription
QGLFormat::NoProfile0OpenGL version is lower than 3.2.
QGLFormat::CoreProfile1Functionality deprecated inOpenGL version 3.0 is not available.
QGLFormat::CompatibilityProfile2Functionality from earlierOpenGL versions is available.

This enum was introduced or modified in Qt 4.7.

enum QGLFormat::OpenGLVersionFlag
flags QGLFormat::OpenGLVersionFlags

This enum describes the variousOpenGL versions that are recognized by Qt. Use theQGLFormat::openGLVersionFlags() function to identify which versions that are supported at runtime.

ConstantValueDescription
QGLFormat::OpenGL_Version_None0x00000000If noOpenGL is present or if noOpenGL context is current.
QGLFormat::OpenGL_Version_1_10x00000001OpenGL version 1.1 or higher is present.
QGLFormat::OpenGL_Version_1_20x00000002OpenGL version 1.2 or higher is present.
QGLFormat::OpenGL_Version_1_30x00000004OpenGL version 1.3 or higher is present.
QGLFormat::OpenGL_Version_1_40x00000008OpenGL version 1.4 or higher is present.
QGLFormat::OpenGL_Version_1_50x00000010OpenGL version 1.5 or higher is present.
QGLFormat::OpenGL_Version_2_00x00000020OpenGL version 2.0 or higher is present. Note that version 2.0 supports all the functionality of version 1.5.
QGLFormat::OpenGL_Version_2_10x00000040OpenGL version 2.1 or higher is present.
QGLFormat::OpenGL_Version_3_00x00001000OpenGL version 3.0 or higher is present.
QGLFormat::OpenGL_Version_3_10x00002000OpenGL version 3.1 or higher is present. Note thatOpenGL version 3.1 or higher does not necessarily support all the features of version 3.0 and lower.
QGLFormat::OpenGL_Version_3_20x00004000OpenGL version 3.2 or higher is present.
QGLFormat::OpenGL_Version_3_30x00008000OpenGL version 3.3 or higher is present.
QGLFormat::OpenGL_Version_4_00x00010000OpenGL version 4.0 or higher is present.
QGLFormat::OpenGL_ES_CommonLite_Version_1_00x00000100OpenGL ES version 1.0 Common Lite or higher is present.
QGLFormat::OpenGL_ES_Common_Version_1_00x00000080OpenGL 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_10x00000400OpenGL ES version 1.1 Common Lite or higher is present.
QGLFormat::OpenGL_ES_Common_Version_1_10x00000200OpenGL ES version 1.1 Common or higher is present. The Common profile supports all the features of Common Lite.
QGLFormat::OpenGL_ES_Version_2_00x00000800OpenGL ES version 2.0 or higher is present. Note thatOpenGL ES version 2.0 does not support all the features ofOpenGL ES 1.x. So if OpenGL_ES_Version_2_0 is returned, none of the ES 1.x flags are returned.

See alsohttp://www.opengl.org for more information about the different revisions ofOpenGL.

This enum was introduced or modified in Qt 4.2.

The OpenGLVersionFlags type is a typedef forQFlags<OpenGLVersionFlag>. It stores an OR combination of OpenGLVersionFlag values.

See alsoopenGLVersionFlags().

Member Function Documentation

QGLFormat::QGLFormat()

Constructs aQGLFormat object with the following default settings:

QGLFormat::QGLFormat(QGL::FormatOptions options,int plane = 0)

Creates aQGLFormat object that is a copy of the currentdefaultFormat().

Ifoptions is not 0, the default format is modified by the specified format options. Theoptions parameter should beQGL::FormatOption values OR'ed together.

This constructor makes it easy to specify a certain desired format in classes derived fromQGLWidget, for example:

// The rendering in MyGLWidget depends on using// stencil buffer and alpha channelMyGLWidget::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 areQGL::FormatOption values to turn format settings both on and off, e.g.QGL::DepthBuffer andQGL::NoDepthBuffer,QGL::DirectRendering andQGL::IndirectRendering, etc.

Theplane parameter defaults to 0 and is the plane which this format should be associated with. Not allOpenGL implementations supports overlay/underlay rendering planes.

See alsodefaultFormat(),setOption(), andsetPlane().

QGLFormat::QGLFormat(constQGLFormat & other)

Constructs a copy ofother.

QGLFormat::~QGLFormat()

Destroys theQGLFormat.

bool QGLFormat::accum() const

Returns true if the accumulation buffer is enabled; otherwise returns false. The accumulation buffer is disabled by default.

See alsosetAccum() andsetAccumBufferSize().

int QGLFormat::accumBufferSize() const

Returns the accumulation buffer size.

See alsosetAccumBufferSize(),accum(), andsetAccum().

bool QGLFormat::alpha() const

Returns true if the alpha buffer in the framebuffer is enabled; otherwise returns false. The alpha buffer is disabled by default.

See alsosetAlpha() andsetAlphaBufferSize().

int QGLFormat::alphaBufferSize() const

Returns the alpha buffer size.

See alsoalpha(),setAlpha(), andsetAlphaBufferSize().

int QGLFormat::blueBufferSize() const

Returns the blue buffer size.

This function was introduced in Qt 4.2.

See alsosetBlueBufferSize().

[static]QGLFormat QGLFormat::defaultFormat()

Returns the defaultQGLFormat for the application. AllQGLWidget 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 usingsetDefaultFormat(), the default format is the same as that created withQGLFormat().

See alsosetDefaultFormat().

[static]QGLFormat QGLFormat::defaultOverlayFormat()

Returns the defaultQGLFormat for overlay contexts.

The default overlay format is:

See alsosetDefaultOverlayFormat() andsetDefaultFormat().

bool QGLFormat::depth() const

Returns true if the depth buffer is enabled; otherwise returns false. The depth buffer is enabled by default.

See alsosetDepth() andsetDepthBufferSize().

int QGLFormat::depthBufferSize() const

Returns the depth buffer size.

See alsodepth(),setDepth(), andsetDepthBufferSize().

bool QGLFormat::directRendering() const

Returns true if direct rendering is enabled; otherwise returns false.

Direct rendering is enabled by default.

See alsosetDirectRendering().

bool QGLFormat::doubleBuffer() const

Returns true if double buffering is enabled; otherwise returns false. Double buffering is enabled by default.

See alsosetDoubleBuffer().

[static]QGLFormat QGLFormat::fromPlatformWindowFormat(constQPlatformWindowFormat & format)

Returns anOpenGL format for the platform window format specified byformat.

This function was introduced in Qt 4.8.

int QGLFormat::greenBufferSize() const

Returns the green buffer size.

This function was introduced in Qt 4.2.

See alsosetGreenBufferSize().

[static]bool QGLFormat::hasOpenGL()

Returns true if the window system has anyOpenGL support; otherwise returns false.

Warning: This function must not be called until theQApplication object has been created.

[static]bool QGLFormat::hasOpenGLOverlays()

Returns true if the window system supportsOpenGL overlays; otherwise returns false.

Warning: This function must not be called until theQApplication object has been created.

bool QGLFormat::hasOverlay() const

Returns true if overlay plane is enabled; otherwise returns false.

Overlay is disabled by default.

See alsosetOverlay().

int QGLFormat::majorVersion() const

Returns theOpenGL major version.

This function was introduced in Qt 4.7.

See alsosetVersion() andminorVersion().

int QGLFormat::minorVersion() const

Returns theOpenGL minor version.

This function was introduced in Qt 4.7.

See alsosetVersion() andmajorVersion().

[static]OpenGLVersionFlags QGLFormat::openGLVersionFlags()

Identifies, at runtime, whichOpenGL versions that are supported by the current platform.

Note that ifOpenGL version 1.5 is supported, its predecessors (i.e., version 1.4 and lower) are also supported. To identify the support of a particular feature, like multi texturing, test for the version in which the feature was first introduced (i.e., version 1.3 in the case of multi texturing) to adapt to the largest possible group of runtime platforms.

This function needs a valid currentOpenGL context to work; otherwise it will returnOpenGL_Version_None.

This function was introduced in Qt 4.2.

See alsohasOpenGL() andhasOpenGLOverlays().

int QGLFormat::plane() const

Returns the plane of this format. The default for normal formats is 0, which means the normal plane. The default for overlay formats is 1, which is the first overlay plane.

See alsosetPlane() anddefaultOverlayFormat().

OpenGLContextProfile QGLFormat::profile() const

Returns theOpenGL context profile.

This function was introduced in Qt 4.7.

See alsosetProfile().

int QGLFormat::redBufferSize() const

Returns the red buffer size.

This function was introduced in Qt 4.2.

See alsosetRedBufferSize().

bool QGLFormat::rgba() const

Returns true if RGBA color mode is set. Returns false if color index mode is set. The default color mode is RGBA.

See alsosetRgba().

bool QGLFormat::sampleBuffers() const

Returns true if multisample buffer support is enabled; otherwise returns false.

The multisample buffer is disabled by default.

See alsosetSampleBuffers().

int QGLFormat::samples() const

Returns the number of samples per pixel when multisampling is enabled. By default, the highest number of samples that is available is used.

See alsosetSampleBuffers(),sampleBuffers(), andsetSamples().

void QGLFormat::setAccum(bool enable)

Ifenable 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.

See alsoaccum() andsetAccumBufferSize().

void QGLFormat::setAccumBufferSize(int size)

Set the preferred accumulation buffer size, wheresize is the bit depth for each RGBA component.

See alsoaccum(),setAccum(), andaccumBufferSize().

void QGLFormat::setAlpha(bool enable)

Ifenable 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.

See alsoalpha() andsetAlphaBufferSize().

void QGLFormat::setAlphaBufferSize(int size)

Set the preferred alpha buffer size tosize. This function implicitly enables the alpha channel.

See alsosetRedBufferSize(),setGreenBufferSize(), andalphaBufferSize().

void QGLFormat::setBlueBufferSize(int size)

Set the preferred blue buffer size tosize.

This function was introduced in Qt 4.2.

See alsoblueBufferSize(),setRedBufferSize(),setGreenBufferSize(), andsetAlphaBufferSize().

[static]void QGLFormat::setDefaultFormat(constQGLFormat & f)

Sets a new defaultQGLFormat for the application tof. 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);

See alsodefaultFormat().

[static]void QGLFormat::setDefaultOverlayFormat(constQGLFormat & f)

Sets a new defaultQGLFormat for overlay contexts tof. This format is used whenever aQGLWidget is created with a format thathasOverlay() enabled.

For example, to get a double buffered overlay context (if available), use code like this:

QGLFormat f=QGLFormat::defaultOverlayFormat();f.setDoubleBuffer(true);QGLFormat::setDefaultOverlayFormat(f);

As usual, you can find out after widget creation whether the underlyingOpenGL system was able to provide the requested specification:

// ...continued from aboveMyGLWidget* myWidget=new MyGLWidget(QGLFormat(QGL::HasOverlay),...);if (myWidget->format().hasOverlay()) {// Yes, we got an overlay, let's check _its_ format:QGLContext* olContext= myWidget->overlayContext();if (olContext->format().doubleBuffer())        ;// yes, we got a double buffered overlayelse        ;// no, only single buffered overlays are available}

See alsodefaultOverlayFormat().

void QGLFormat::setDepth(bool enable)

Ifenable 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.

See alsodepth() andsetDepthBufferSize().

void QGLFormat::setDepthBufferSize(int size)

Set the minimum depth buffer size tosize.

See alsodepthBufferSize(),setDepth(), anddepth().

void QGLFormat::setDirectRendering(bool enable)

Ifenable is true enables direct rendering; otherwise disables direct rendering.

Direct rendering is enabled by default.

Enabling this option will makeOpenGL bypass the underlying window system and render directly from hardware to the screen, if this is supported by the system.

See alsodirectRendering().

void QGLFormat::setDoubleBuffer(bool enable)

Ifenable 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.

Note that single buffered contexts are currently not supported with EGL.

See alsodoubleBuffer(),QGLContext::swapBuffers(), andQGLWidget::swapBuffers().

void QGLFormat::setGreenBufferSize(int size)

Set the preferred green buffer size tosize.

This function was introduced in Qt 4.2.

See alsogreenBufferSize(),setRedBufferSize(),setBlueBufferSize(), andsetAlphaBufferSize().

void QGLFormat::setOption(QGL::FormatOptions opt)

Sets the format option toopt.

See alsotestOption().

void QGLFormat::setOverlay(bool enable)

Ifenable is true enables an overlay plane; otherwise disables the overlay plane.

Enabling the overlay plane will causeQGLWidget to create an additional context in an overlay plane. See theQGLWidget documentation for further information.

See alsohasOverlay().

void QGLFormat::setPlane(int plane)

Sets the requested plane toplane. 0 is the normal plane, 1 is the first overlay plane, 2 is the second overlay plane, etc.; -1, -2, etc. are underlay planes.

Note that in contrast to other format specifications, the plane specifications will be matched exactly. This means that if you specify a plane that the underlyingOpenGL system cannot provide, aninvalidQGLWidget will be created.

See alsoplane().

void QGLFormat::setProfile(OpenGLContextProfile profile)

Set theOpenGL context profile toprofile. Theprofile is ignored if the requestedOpenGL version is less than 3.2.

This function was introduced in Qt 4.7.

See alsoprofile().

void QGLFormat::setRedBufferSize(int size)

Set the preferred red buffer size tosize.

This function was introduced in Qt 4.2.

See alsoredBufferSize(),setGreenBufferSize(),setBlueBufferSize(), andsetAlphaBufferSize().

void QGLFormat::setRgba(bool enable)

Ifenable is true sets RGBA mode. Ifenable is false sets color index mode.

The default color mode is RGBA.

RGBA is the preferred mode for mostOpenGL 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.

See alsorgba().

void QGLFormat::setSampleBuffers(bool enable)

Ifenable is true, a GL context with multisample buffer support is picked; otherwise ignored.

See alsosampleBuffers(),setSamples(), andsamples().

void QGLFormat::setSamples(int numSamples)

Set the preferred number of samples per pixel when multisampling is enabled tonumSamples. By default, the highest number of samples available is used.

See alsosetSampleBuffers(),sampleBuffers(), andsamples().

void QGLFormat::setStencil(bool enable)

Ifenable 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.

See alsostencil() andsetStencilBufferSize().

void QGLFormat::setStencilBufferSize(int size)

Set the preferred stencil buffer size tosize.

See alsostencilBufferSize(),setStencil(), andstencil().

void QGLFormat::setStereo(bool enable)

Ifenable 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 alsostereo().

void QGLFormat::setSwapInterval(int interval)

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 aninterval 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 theWGL_EXT_swap_control andGLX_SGI_video_sync extensions are used, theinterval parameter can be used to set the minimum number of video frames that are displayed before a buffer swap will occur. In effect, setting theinterval to 10, means there will be 10 vertical retraces between every buffer swap.

Under Windows theWGL_EXT_swap_control extension has to be present, and under X11 theGLX_SGI_video_sync extension has to be present.

This function was introduced in Qt 4.2.

See alsoswapInterval().

void QGLFormat::setVersion(int major,int minor)

Set theOpenGL version to themajor andminor numbers. If a context compatible with the requestedOpenGL version cannot be created, a context compatible with version 1.x is created instead.

This function was introduced in Qt 4.7.

See alsomajorVersion() andminorVersion().

bool QGLFormat::stencil() const

Returns true if the stencil buffer is enabled; otherwise returns false. The stencil buffer is enabled by default.

See alsosetStencil() andsetStencilBufferSize().

int QGLFormat::stencilBufferSize() const

Returns the stencil buffer size.

See alsostencil(),setStencil(), andsetStencilBufferSize().

bool QGLFormat::stereo() const

Returns true if stereo buffering is enabled; otherwise returns false. Stereo buffering is disabled by default.

See alsosetStereo().

int QGLFormat::swapInterval() const

Returns the currently set swap interval. -1 is returned if setting the swap interval isn't supported in the system GL implementation.

This function was introduced in Qt 4.2.

See alsosetSwapInterval().

bool QGLFormat::testOption(QGL::FormatOptions opt) const

Returns true if format optionopt is set; otherwise returns false.

See alsosetOption().

[static]QPlatformWindowFormat QGLFormat::toPlatformWindowFormat(constQGLFormat & format)

Returns a platform window format for theOpenGL format specified byformat.

This function was introduced in Qt 4.8.

QGLFormat & QGLFormat::operator=(constQGLFormat & other)

Assignsother to this object.

Related Non-Members

booloperator!=(constQGLFormat & a, constQGLFormat & b)

Returns false if all the options of the twoQGLFormat objectsa andb are equal; otherwise returns true.

booloperator==(constQGLFormat & a, constQGLFormat & b)

Returns true if all the options of the twoQGLFormat objectsa andb are equal; otherwise returns false.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp