CopperSpice API  1.9.2
QOffscreenSurface Class Reference

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

Inheritance diagram for QOffscreenSurface:
QObject QSurface

Public Signals

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

Public Methods

 QOffscreenSurface (QScreen *screen=nullptr)
 
virtual ~QOffscreenSurface ()
 
void create ()
 
void destroy ()
 
QSurfaceFormat format () const override
 
bool isValid () const
 
QSurfaceFormat requestedFormat () const
 
QScreenscreen () const
 
void setFormat (const QSurfaceFormat &format)
 
void setScreen (QScreen *screen)
 
QSize size () const override
 
SurfaceType surfaceType () const override
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 
- Public Methods inherited from QSurface
virtual ~QSurface ()
 
bool supportsOpenGL () const
 
SurfaceClass surfaceClass () const
 

Additional Inherited Members

- Public Types inherited from QSurface
enum  SurfaceClass
 
enum  SurfaceType
 
- Public Slots inherited from QObject
void deleteLater ()
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 
- Protected Methods inherited from QSurface
 QSurface (SurfaceClass type)
 
- Properties inherited from QObject
 objectName
 

Detailed Description

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

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 does not 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() 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.

Constructor & Destructor Documentation

QOffscreenSurface::QOffscreenSurface ( QScreen screen = nullptr)
explicit

Creates an offscreen surface for the screen. The underlying platform surface is not created until create() is called.

See also
setScreen(), create()
QOffscreenSurface::~QOffscreenSurface ( )
virtual

Destroys the offscreen surface.

Method Documentation

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()
void QOffscreenSurface::destroy ( )

Releases the native platform resources associated with this offscreen surface.

See also
create()
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::format()

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()
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()
QScreen * QOffscreenSurface::screen ( ) const

Returns the screen to which the offscreen surface is connected.

See also
setScreen()
void QOffscreenSurface::screenChanged ( QScreen screen)
signal

This signal is emitted when the screen for an offscreen surface changes. This can occur by explicitly calling setScreen() or happened automatically when the window's screen is removed.

void QOffscreenSurface::setFormat ( const QSurfaceFormat format)

Sets the offscreen surface format. The surface format will be resolved in the by create(). Calling this method after create() will not re-resolve the surface format of the native surface.

See also
create(), destroy()
void QOffscreenSurface::setScreen ( QScreen screen)

Sets the screen to which the offscreen surface is connected. If the offscreen surface has been created, it will be recreated on the screen.

See also
screen()
QSize QOffscreenSurface::size ( ) const
overridevirtual

Returns the size of the offscreen surface.

Implements QSurface::size()

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::surfaceType()