![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtGui More...
\inmodule QtGui
OpenGL specific initialization parameters.
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.
\badcode QOffscreenSurface *fallbackSurface = QRhiGles2InitParams::newFallbackSurface(); QRhiGles2InitParams params; params.fallbackSurface = fallbackSurface; params.window = window; rhi = QRhi::create(QRhi::OpenGLES2, ¶ms);
By default QRhi creates a 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
.
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.
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.