![]() |
CopperSpice API
1.8.2
|
Represents a native OpenGL context which is used to render OpenGL content on a QSurface. More...
Public Methods | |
QOpenGLContext (QObject *parent=nullptr) | |
~QOpenGLContext () | |
bool | create () |
GLuint | defaultFramebufferObject () const |
void | doneCurrent () |
QSet< QByteArray > | extensions () const |
QOpenGLExtraFunctions * | extraFunctions () const |
QSurfaceFormat | format () const |
QOpenGLFunctions * | functions () const |
bool | hasExtension (const QByteArray &extension) const |
bool | isOpenGLES () const |
bool | makeCurrent (QSurface *surface) |
QScreen * | screen () const |
void | setFormat (const QSurfaceFormat &format) |
void | setScreen (QScreen *screen) |
void | setShareContext (QOpenGLContext *shareContext) |
QOpenGLContext * | shareContext () const |
QOpenGLContextGroup * | shareGroup () const |
![]() | |
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< QString > | dynamicPropertyNames () const |
virtual bool | event (QEvent *event) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
template<typename T > | |
T | findChild (const QString &childName=QString ()) const |
template<class T > | |
QList< T > | findChildren (const QRegularExpression ®Exp, 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 QMetaObject * | metaObject () const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const |
QObject * | parent () const |
template<class T = QVariant> | |
T | 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) |
QThread * | thread () const |
Static Public Methods | |
static QOpenGLContext * | currentContext () |
static QOpenGLContext * | globalShareContext () |
static OpenGLModuleType | openGLModuleType () |
![]() | |
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 QMetaObject & | staticMetaObject () |
static QString | tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >()) |
Friends | |
class | QGLContext |
class | QGLPixelBuffer |
class | QOpenGLFramebufferObject |
Additional Inherited Members | |
![]() | |
void | destroyed (QObject *obj=nullptr) |
void | objectNameChanged (const QString &objectName) |
![]() | |
void | deleteLater () |
![]() | |
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) |
![]() | |
objectName | |
![]() | |
T | qobject_cast (QObject *object) |
QObjectList | |
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 CopperSpice OpenGL classes like QOpenGLFunctions, QOpenGLBuffer, QOpenGLShaderProgram, and QOpenGLFramebufferObject. Another option is to call functions in the C OpenGL API directly. The latter is necessary when using OpenGL 1.x or OpenGL ES 1.x.
|
explicit |
Creates a new OpenGL context with the given parent. Before the context can be used call setFormat() and then create().
QOpenGLContext::~QOpenGLContext | ( | ) |
Destroys the QOpenGLContext object. If this QOpenGLContext is active for the current thread then doneCurrent() will be called.
bool QOpenGLContext::create | ( | ) |
Attempts to create the OpenGL context with the current configuration. The current configuration includes the format, the share context, and the screen. Returns true if the native context was successfully created and is ready to be used with makeCurrent(), swapBuffers(), etc.
If the OpenGL implementation on your system does not support the requested version of OpenGL context, then QOpenGLContext will try to create the closest matching version. The actual created context properties can be queried using the QSurfaceFormat returned by the format() function. For example, if you request a context that supports OpenGL 4.3 Core profile but the driver and/or hardware only supports version 3.2 Core profile contexts then you will get a 3.2 Core profile context.
If the context already exists, this method destroys the existing context first and then creates a new one.
|
static |
Returns the last context which called makeCurrent() in the current thread or a nullptr if no context is active.
GLuint QOpenGLContext::defaultFramebufferObject | ( | ) | const |
This method returns the default framebuffer object for the current surface.
On some platforms the default framebuffer object depends on the surface being rendered to and might not have an index of 0. Instead of calling glBindFramebuffer(0) call glBindFramebuffer(ctx->defaultFramebufferObject()). If you use the glBindFramebuffer() in QOpenGLFunctions the context frame buffer object will be set correctly.
void QOpenGLContext::doneCurrent | ( | ) |
Equivalent to calling makeCurrent() with a null surface. Calling this method results in no context being current in the current thread.
QSet< QByteArray > QOpenGLContext::extensions | ( | ) | const |
Returns the set of OpenGL extensions supported by this context. The context or a sharing context must be current.
QOpenGLExtraFunctions * QOpenGLContext::extraFunctions | ( | ) | const |
Returns the QOpenGLExtraFunctions instance for this context. QOpenGLContext offers this as a convenient way to access QOpenGLExtraFunctions without having to manage it manually. The context or a sharing context must be current. The returned QOpenGLExtraFunctions instance is ready to be used and it does not need initializeOpenGLFunctions() to be called.
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.
QOpenGLFunctions * QOpenGLContext::functions | ( | ) | const |
Get the QOpenGLFunctions instance for this context. QOpenGLContext offers this as a convenient way to access QOpenGLFunctions without having to manage it manually. The context or a sharing context must be current. The returned QOpenGLFunctions instance is ready to be used and it does not need initializeOpenGLFunctions() to be called.
|
static |
Returns the shared OpenGL context for the application, if one is available. Otherwise, returns a nullptr. This is useful if you need to upload OpenGL objects (buffers, textures, etc.) before creating or showing a QOpenGLWidget.
You must set the Qt::AA_ShareOpenGLContexts flag on QApplication before creating the QApplication object, otherwise CopperSpice may not create a global shared context.
bool QOpenGLContext::hasExtension | ( | const QByteArray & | extension | ) | const |
Returns true if this OpenGL context supports the specified OpenGL extension, otherwise returns false. The context or a sharing context must be current.
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().
bool QOpenGLContext::makeCurrent | ( | QSurface * | surface | ) |
Sets the current context in the current thread to render to the given surface. Returns true if successful otherwise returns false. The latter may happen if the surface is not exposed or the graphics hardware is not available due to the application being suspended.
If surface is a nullptr then calling this method is equivalent to calling doneCurrent().
Avoid calling this method from a different thread than the one the QOpenGLContext instance lives in. If you wish to use QOpenGLContext from a different thread you should first make sure it's not current in the current thread, by calling doneCurrent() if necessary. Then call moveToThread(otherThread) before using it in the other thread.
|
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 method isOpenGLES().
This method can only be called after a QApplication has been created.
QScreen * QOpenGLContext::screen | ( | ) | const |
Returns the screen this context is displayed on.
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.
void QOpenGLContext::setScreen | ( | QScreen * | screen | ) |
Sets the screen this context will be displayed on.
void QOpenGLContext::setShareContext | ( | QOpenGLContext * | shareContext | ) |
Configures this context to share textures, shaders, and other OpenGL resources with the given 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.
QOpenGLContextGroup * QOpenGLContext::shareGroup | ( | ) | const |
Returns the share group this context belongs to.