QtBase  v6.3.1
Signals | Public Member Functions | List of all members
QOffscreenSurface Class Reference

The QOffscreenSurface class represents an offscreen surface in the underlying platform. More...

#include <qoffscreensurface.h>

Inheritance diagram for QOffscreenSurface:
Inheritance graph
[legend]
Collaboration diagram for QOffscreenSurface:
Collaboration graph
[legend]

Signals

void screenChanged (QScreen *screen)
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 

Public Member Functions

 QOffscreenSurface (QScreen *screen=nullptr, QObject *parent=nullptr)
 
 ~QOffscreenSurface ()
 
SurfaceType surfaceType () const override
 
void create ()
 
void destroy ()
 
bool isValid () const
 
void setFormat (const QSurfaceFormat &format)
 
QSurfaceFormat format () const override
 
QSurfaceFormat requestedFormat () const
 
QSize size () const override
 
QScreenscreen () const
 
void setScreen (QScreen *screen)
 
QPlatformOffscreenSurfacehandle () const
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 
virtual ~QObject ()
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
QString objectName () const
 
void setObjectName (const QString &name)
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 
bool isWindowType () const
 
bool signalsBlocked () const noexcept
 
bool blockSignals (bool b) noexcept
 
QThreadthread () const
 
void moveToThread (QThread *thread)
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 
template<typename T >
T findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
const QObjectListchildren () const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 
void dumpObjectInfo () const
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 
bool inherits (const char *classname) const
 
- Public Member Functions inherited from QSurface
virtual ~QSurface ()
 
SurfaceClass surfaceClass () const
 
bool supportsOpenGL () const
 

Additional Inherited Members

- Public Types inherited from QSurface
enum  SurfaceClass { Window , Offscreen }
 
enum  SurfaceType {
  RasterSurface , OpenGLSurface , RasterGLSurface , OpenVGSurface ,
  VulkanSurface , MetalSurface , Direct3DSurface
}
 
- Public Slots inherited from QObject
void deleteLater ()
 
- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 
- Protected Member Functions inherited from QSurface
 QSurface (SurfaceClass type)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Protected Attributes inherited from QSurface
SurfaceClass m_type
 
QSurfacePrivate * m_reserved
 
- Properties inherited from QObject
QString objectName
 the name of this object More...
 

Detailed Description

The QOffscreenSurface class represents an offscreen surface in the underlying platform.

\inmodule QtGui

Since
5.1

QOffscreenSurface is intended to be used with QOpenGLContext to allow rendering with OpenGL in an arbitrary thread without the need to create a 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.

An application will typically use 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.

Note
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 \l{QOpenGLContext::makeCurrent()}{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() or QWindow::format() {after the context or window has been created}. Passing the format returned from QWindow::requestedFormat() to 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.

Definition at line 56 of file qoffscreensurface.h.

Constructor & Destructor Documentation

◆ QOffscreenSurface()

QOffscreenSurface::QOffscreenSurface ( QScreen targetScreen = nullptr,
QObject parent = nullptr 
)
explicit
Since
5.10

Creates an offscreen surface for the targetScreen with the given parent.

The underlying platform surface is not created until create() is called.

See also
setScreen(), create()

Definition at line 104 of file qoffscreensurface.cpp.

Here is the call graph for this function:

◆ ~QOffscreenSurface()

QOffscreenSurface::~QOffscreenSurface ( )

Destroys the offscreen surface.

Definition at line 123 of file qoffscreensurface.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ create()

void QOffscreenSurface::create ( )

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.

Call destroy() to free the platform resources if necessary.

Note
Some platforms require this function to be called on the main (GUI) thread.
See also
destroy()

Definition at line 151 of file qoffscreensurface.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy()

void QOffscreenSurface::destroy ( )

Releases the native platform resources associated with this offscreen surface.

See also
create()

Definition at line 187 of file qoffscreensurface.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ format()

QSurfaceFormat QOffscreenSurface::format ( ) const
overridevirtual

Returns the actual format of this offscreen surface.

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.

See also
create(), requestedFormat()

Implements QSurface.

Definition at line 256 of file qoffscreensurface.cpp.

Here is the caller graph for this function:

◆ handle()

QPlatformOffscreenSurface * QOffscreenSurface::handle ( ) const

Returns the platform offscreen surface corresponding to the offscreen surface.

Definition at line 339 of file qoffscreensurface.cpp.

◆ isValid()

bool QOffscreenSurface::isValid ( ) const

Returns true if this offscreen surface is valid; otherwise returns false.

The offscreen surface is valid if the platform resources have been successfully allocated.

See also
create()

Definition at line 210 of file qoffscreensurface.cpp.

◆ requestedFormat()

QSurfaceFormat QOffscreenSurface::requestedFormat ( ) const

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.

This is the value set with setFormat().

See also
setFormat(), format()

Definition at line 241 of file qoffscreensurface.cpp.

Here is the caller graph for this function:

◆ screen()

QScreen * QOffscreenSurface::screen ( ) const

Returns the screen to which the offscreen surface is connected.

See also
setScreen()

Definition at line 280 of file qoffscreensurface.cpp.

Here is the caller graph for this function:

◆ screenChanged

QOffscreenSurface::screenChanged ( QScreen screen)
signal

This signal is emitted when an offscreen surface's screen changes, either by being set explicitly with setScreen(), or automatically when the window's screen is removed.

Here is the caller graph for this function:

◆ setFormat()

void QOffscreenSurface::setFormat ( const QSurfaceFormat format)

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.

See also
create(), destroy()

Definition at line 225 of file qoffscreensurface.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setScreen()

void QOffscreenSurface::setScreen ( QScreen newScreen)

Sets the screen to which the offscreen surface is connected.

If the offscreen surface has been created, it will be recreated on the newScreen.

See also
screen()

Definition at line 293 of file qoffscreensurface.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ size()

QSize QOffscreenSurface::size ( ) const
overridevirtual

Returns the size of the offscreen surface.

Implements QSurface.

Definition at line 269 of file qoffscreensurface.cpp.

Here is the caller graph for this function:

◆ surfaceType()

QOffscreenSurface::SurfaceType QOffscreenSurface::surfaceType ( ) const
overridevirtual

Returns the surface type of the offscreen surface.

The surface type of an offscreen surface is always QSurface::OpenGLSurface.

Implements QSurface.

Definition at line 133 of file qoffscreensurface.cpp.


The documentation for this class was generated from the following files: