The QOffscreenSurface class represents an offscreen surface in the underlying platform. 更多...
| 頭: | #include <QOffscreenSurface> |
| qmake: | QT += gui |
| Since: | Qt 5.1 |
| 繼承: | QObject and QSurface |
| QOffscreenSurface (QScreen * targetScreen , QObject * parent ) | |
| QOffscreenSurface (QScreen * targetScreen = nullptr) | |
| virtual | ~QOffscreenSurface () |
| void | create () |
| void | destroy () |
| bool | isValid () const |
| void * | nativeHandle () const |
| QSurfaceFormat | requestedFormat () const |
| QScreen * | screen () const |
| void | setFormat (const QSurfaceFormat & format ) |
| void | setNativeHandle (void * handle ) |
| void | setScreen (QScreen * newScreen ) |
| virtual QSurfaceFormat | format () const override |
| virtual QSize | size () const override |
| virtual QSurface::SurfaceType | surfaceType () const override |
| void | screenChanged (QScreen * screen ) |
| const QMetaObject | staticMetaObject |
The QOffscreenSurface class represents an offscreen surface in the underlying platform.
QOffscreenSurface is intended to be used with QOpenGLContext 以允許在任意綫程采用 OpenGL 渲染而無需創建 QWindow .
Even though the surface is typically renderable, the surface's pixels are not accessible. QOffscreenSurface should only be used to create OpenGL resources such as textures or framebuffer objects.
應用程序通常使用 QOffscreenSurface to perform some time-consuming tasks in a separate thread in order to avoid stalling the main rendering thread. Resources created in the QOffscreenSurface 's context can be shared with the main OpenGL context. Some common use cases are asynchronous texture uploads or rendering into a QOpenGLFramebufferObject .
How the offscreen surface is implemented depends on the underlying platform, but it will typically use a pixel buffer (pbuffer). If the platform doesn't implement or support offscreen surfaces, QOffscreenSurface will use an invisible QWindow internally.
注意: Due to the fact that QOffscreenSurface is backed by a QWindow on some platforms, cross-platform applications must ensure that create () is only called on the main (GUI) thread. The QOffscreenSurface is then safe to be used with makeCurrent() on other threads, but the initialization and destruction must always happen on the main (GUI) thread.
注意: In order to create an offscreen surface that is guaranteed to be compatible with a given context and window, make sure to set the format to the context's or the window's actual format, that is, the QSurfaceFormat returned from QOpenGLContext::format () 或 QWindow::format () after the context or window has been created . Passing the format returned from QWindow::requestedFormat () 到 setFormat () may result in an incompatible offscreen surface since the underlying windowing system interface may offer a different set of configurations for window and pbuffer surfaces.
注意: Some platforms may utilize a surfaceless context extension (for example EGL_KHR_surfaceless_context) when available. In this case there will be no underlying native surface. For the use cases of QOffscreenSurface (rendering to FBOs, texture upload) this is not a problem.
創建離屏錶麵為 targetScreen 采用給定 parent .
不創建底層平颱錶麵直到 create () 被調用。
該函數在 Qt 5.10 引入。
另請參閱 setScreen () 和 create ().
創建離屏錶麵為 targetScreen .
不創建底層平颱錶麵直到 create () 被調用。
另請參閱 setScreen () 和 create ().
[虛擬]
QOffscreenSurface::
~QOffscreenSurface
()
銷毀離屏錶麵。
Allocates the platform resources associated with the offscreen surface.
It is at this point that the surface format set using setFormat () gets resolved into an actual native surface.
調用 destroy () 以釋放平颱資源,若有必要。
注意: Some platforms require this function to be called on the main (GUI) thread.
另請參閱 destroy ().
Releases the native platform resources associated with this offscreen surface.
另請參閱 create ().
[override virtual]
QSurfaceFormat
QOffscreenSurface::
format
() const
重實現自 QSurface::format ().
返迴此離屏錶麵的實際格式。
After the offscreen surface has been created, this function will return the actual surface format of the surface. It might differ from the requested format if the requested format could not be fulfilled by the platform.
另請參閱 setFormat (), create (),和 requestedFormat ().
返迴
true
if this offscreen surface is valid; otherwise returns
false
.
The offscreen surface is valid if the platform resources have been successfuly allocated.
另請參閱 create ().
Returns an optional native handle to which the offscreen surface is connected.
該函數在 Qt 5.9 引入。
另請參閱 setNativeHandle ().
Returns the requested surfaceformat of this offscreen surface.
If the requested format was not supported by the platform implementation, the requestedFormat will differ from the actual offscreen surface format.
此值的設置是采用 setFormat ().
另請參閱 setFormat () 和 format ().
Returns the screen to which the offscreen surface is connected.
另請參閱 setScreen ().
[signal]
void
QOffscreenSurface::
screenChanged
(
QScreen
*
screen
)
This signal is emitted when an offscreen surface's screen 改變,通過明確設置采用 setScreen (),或自動當移除窗口屏幕時。
Sets the offscreen surface format .
The surface format will be resolved in the create () function. Calling this function after create () will not re-resolve the surface format of the native surface.
另請參閱 format (), create (),和 destroy ().
Sets the native handle to which the offscreen surface is connected to handle .
The native handle will be resolved in the create () function. Calling this function after create () will not re-create a native surface.
注意: The interpretation of the native handle is platform specific. Only some platforms will support adopting native handles of offscreen surfaces and platforms that do not implement this support will ignore the handle.
該函數在 Qt 5.9 引入。
另請參閱 nativeHandle ().
Sets the screen to which the offscreen surface is connected.
If the offscreen surface has been created, it will be recreated on the newScreen .
另請參閱 screen ().
[override virtual]
QSize
QOffscreenSurface::
size
() const
重實現自 QSurface::size ().
Returns the size of the offscreen surface.
[override virtual]
QSurface::SurfaceType
QOffscreenSurface::
surfaceType
() const
重實現自 QSurface::surfaceType ().
Returns the surface type of the offscreen surface.
The surface type of an offscreen surface is always QSurface::OpenGLSurface .