QRhiGles2InitParams Struct

OpenGL specific initialization parameters. 更多...

头: #include <QRhiGles2InitParams>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
Since: Qt 6.6
继承: QRhiInitParams

公共函数

QRhiGles2InitParams ()

公共变量

QSurface * fallbackSurface
QSurfaceFormat format
QOpenGLContext * shareContext
QWindow * window

静态公共成员

QOffscreenSurface * newFallbackSurface (const QSurfaceFormat & format = QSurfaceFormat::defaultFormat())

详细描述

注意: This is a RHI API with limited compatibility guarantees, see QRhi 了解细节。

An OpenGL-based QRhi needs an already created QSurface that can be used in combination with QOpenGLContext . Most commonly, this is a QOffscreenSurface in practice. Additionally, while optional, it is recommended that the QWindow the first QRhiSwapChain will target is passed in as well.

QOffscreenSurface *fallbackSurface = QRhiGles2InitParams::newFallbackSurface();
QRhiGles2InitParams params;
params.fallbackSurface = fallbackSurface;
params.window = window;
rhi = QRhi::create(QRhi::OpenGLES2, ¶ms);
					

默认情况下 QRhi 创建 QOpenGLContext on its own. This approach works well in most cases, included threaded scenarios, where there is a dedicated QRhi for each rendering thread. As there will be a QOpenGLContext for each QRhi , the OpenGL context requirements (a context can only be current on one thread) are satisfied. The implicitly created context is destroyed automatically together with the QRhi .

The QSurfaceFormat for the context is specified in format . The constructor sets this to QSurfaceFormat::defaultFormat () so applications that call QSurfaceFormat::setDefaultFormat () with the appropriate settings before the constructor runs will not need to change value of format .

注意: Remember to set the depth and stencil buffer sizes to 24 and 8 when the renderer relies on depth or stencil testing, either in the global default QSurfaceFormat , or, alternatively, separately in all the involved QSurfaceFormat instances: in format , the format argument passed to newFallbackSurface (), and on any QWindow that is used with the QRhi .

A QSurface has to be specified in fallbackSurface . In order to prevent mistakes in threaded situations, this is never created automatically by the QRhi because, like QWindow , instances of QSurface subclasses can often be created on the gui/main thread only.

As a convenience, applications can use newFallbackSurface () which creates and returns a QOffscreenSurface that is compatible with the QOpenGLContext that is going to be created by the QRhi afterwards. Note that the ownership of the returned QOffscreenSurface is transferred to the caller and the QRhi will not destroy it.

注意: With the OpenGL backend, QRhiSwapChain can only target QWindow instances that have their surface type set to QSurface::OpenGLSurface or QSurface::RasterGLSurface .

注意: window is optional. It is recommended to specify it whenever possible, in order to avoid problems on multi-adapter and multi-screen systems. When window is not set, the very first QOpenGLContext::makeCurrent () happens with fallbackSurface which may be an invisible window on some platforms (for example, Windows) and that may trigger unexpected problems in some cases.

In case resource sharing with an existing QOpenGLContext is desired, shareContext can be set to an existing QOpenGLContext . Alternatively, Qt::AA_ShareOpenGLContexts is honored as well, when enabled.

Working with existing OpenGL contexts

When interoperating with another graphics engine, it may be necessary to get a QRhi instance that uses the same OpenGL context. This can be achieved by passing a pointer to a QRhiGles2NativeHandles to QRhi::create ()。 QRhiGles2NativeHandles::context must be set to a non-null value then.

An alternative approach is to create a QOpenGLContext that shares resources with the other engine's context and passing in that context via QRhiGles2NativeHandles .

The QRhi does not take ownership of the QOpenGLContext passed in via QRhiGles2NativeHandles .

成员函数文档编制

QRhiGles2InitParams:: QRhiGles2InitParams ()

Constructs a new QRhiGles2InitParams.

format 被设为 QSurfaceFormat::defaultFormat ().

[static] QOffscreenSurface *QRhiGles2InitParams:: newFallbackSurface (const QSurfaceFormat & format = QSurfaceFormat::defaultFormat())

返回新的 QOffscreenSurface that can be used with a QRhi by passing it via a QRhiGles2InitParams .

format is not specified, its default value is the global default format settable via QSurfaceFormat::setDefaultFormat ().

format is adjusted as appropriate in order to avoid having problems afterwards due to an incompatible context and surface.

注意: This function must only be called on the gui/main thread.

注意: It is the application's responsibility to destroy the returned QOffscreenSurface on the gui/main thread once the associated QRhi has been destroyed. The QRhi will not destroy the QOffscreenSurface .

成员变量文档编制

QSurface *QRhiGles2InitParams:: fallbackSurface

A QSurface compatible with format . Typically a QOffscreenSurface . Providing this is mandatory. Be aware of the threading implications: a QOffscreenSurface , like QWindow , must only ever be created and destroyed on the main (gui) thread, even if the QRhi is created and operates on another thread.

QSurfaceFormat QRhiGles2InitParams:: format

The QSurfaceFormat , initialized to QSurfaceFormat::defaultFormat () by default.

QOpenGLContext *QRhiGles2InitParams:: shareContext

Optional, the QOpenGLContext to share resource with. QRhi creates its own context, and setting this member to a valid QOpenGLContext leads to calling setShareContext () with it.

QWindow *QRhiGles2InitParams:: window

Optional, but setting it is recommended when targeting a QWindow 采用 QRhi .