CopperSpice API  1.8.1
QOpenGLContext Class Reference

The QOpenGLContext class represents a native OpenGL context which is used to render OpenGL content on a QSurface. More...

Inheritance diagram for QOpenGLContext:
QObject

Public Methods

 QOpenGLContext (QObject *parent=nullptr)
 
 ~QOpenGLContext ()
 
QSurfaceFormat format () const
 
bool isOpenGLES () const
 
QScreenscreen () const
 
void setFormat (const QSurfaceFormat &format)
 
void setScreen (QScreen *screen)
 
void setShareContext (QOpenGLContext *shareContext)
 
QOpenGLContext * shareContext () const
 
- 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
 

Static Public Methods

static QOpenGLContext * currentContext ()
 
static OpenGLModuleType openGLModuleType ()
 
- 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 >())
 

Friends

class QGLContext
 
class QGLPixelBuffer
 

Additional Inherited Members

- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 
- Public Slots inherited from QObject
void deleteLater ()
 
- 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)
 
- Properties inherited from QObject
 objectName
 

Detailed Description

The QOpenGLContext class represents a native OpenGL context which is used to render OpenGL content on a QSurface.

This class represents the OpenGL state of an underlying OpenGL context. To configure a context set the screen and format to match the target surface. A surface is a specific region of the screen where OpenGL content will be displayed. It may be necessary to share resources by calling setShareContext(). Once the context has been configured then call create(). Check the return value or call isValid() to determine if the context was successfully initialized.

A context can be activated for a given surface by calling makeCurrent(). When OpenGL rendering is complete call swapBuffers() to swap the front and back buffers of the surface. At this point the new content becomes visible to the user. QOpenGLContext requires calling makeCurrent() one more time before rendering a new frame.

If the context is temporarily unused, it can be useful to delete the context to free resources. Your application should connect to the aboutToBeDestroyed() signal to clean up any resources which have been allocated.

Once a QOpenGLContext is marked activated your application can render to the context using the OpenGL classes like QOpenGLFunctions, QOpenGLBuffer, QOpenGLShaderProgram, and QOpenGLFramebufferObject. It is also possible to use the platform's OpenGL API directly, without using the CopperSpice classes, although there may be portability issues. The latter is necessary when wanting to use OpenGL 1.x or OpenGL ES 1.x.

Note
Additional documentation pending.

Constructor & Destructor Documentation

QOpenGLContext::QOpenGLContext ( QObject parent = nullptr)
explicit

Creates a new OpenGL context with the given parent. Before the context can be used call setFormat() and then create().

See also
create(), makeCurrent()
QOpenGLContext::~QOpenGLContext ( )

Destroys the QOpenGLContext object. If this QOpenGLContext is active for the current thread, then doneCurrent() wiil be called.

Method Documentation

QOpenGLContext * QOpenGLContext::currentContext ( )
static

Returns the last context which called makeCurrent() in the current thread or a nullptr if no context is active.

QSurfaceFormat QOpenGLContext::format ( ) const

Returns the format of the underlying platform context, if create() has been called. Otherwise, returns the requested format.

The requested and the actual format may differ. Requesting a given OpenGL version does not mean the resulting context will target exactly the requested version. It is only guaranteed that the version/profile/options combination for the created context is compatible with the request, as long as the driver is able to provide such a context.

For example, requesting an OpenGL version 3.x core profile context may result in an OpenGL 4.x core profile context. Similarly, a request for OpenGL 2.1 may result in an OpenGL 3.0 context with deprecated functions enabled. Finally, depending on the driver, unsupported versions may result in either a context creation failure or in a context for the highest supported version.

Similar differences are possible in the buffer sizes, for example, the resulting context may have a larger depth buffer than requested. This is perfectly normal.

See also
setFormat()
bool QOpenGLContext::isOpenGLES ( ) const

Returns true if the context is an OpenGL ES context. If the context has not yet been created, the result is based on the requested format set via setFormat().

See also
create(), format(), setFormat()
QOpenGLContext::OpenGLModuleType QOpenGLContext::openGLModuleType ( )
static

Returns the underlying OpenGL implementation type. On platforms where the OpenGL implementation is not dynamically loaded, the return value is determined during compile time and never changes.

A desktop OpenGL implementation may be capable of creating ES-compatible contexts too. Therefore in most cases it is more appropriate to check QSurfaceFormat::renderableType() or use the convenience function isOpenGLES().

This method requires a QApplication instance has been created.

QScreen * QOpenGLContext::screen ( ) const

Returns the screen this context is displayed on.

See also
setScreen()
void QOpenGLContext::setFormat ( const QSurfaceFormat format)

Sets the format the OpenGL context should be compatible with. Call create() so the new format will take effect.

When the format is not explicitly set via this function, the format returned by QSurfaceFormat::defaultFormat() will be used. This means that when having multiple contexts, individual calls to this function can be replaced by one single call to QSurfaceFormat::setDefaultFormat() before creating the first context.

See also
format()
void QOpenGLContext::setScreen ( QScreen screen)

Sets the screen this context will be displayed on.

See also
screen()
void QOpenGLContext::setShareContext ( QOpenGLContext *  shareContext)

Configures this context to share textures, shaders, and other OpenGL resources with given shareContext.

See also
shareContext()
QOpenGLContext * QOpenGLContext::shareContext ( ) const

Returns the share context this context was created with. If the underlying platform was not able to support the requested sharing this method will return a nullptr.

See also
setShareContext()