Skip to content

PythonQt.QtGui.QOpenGLContext

QOpenGLContext

PythonQtInstanceWrapper object

Native bases: PythonQtInstanceWrapper

Supplemental documentation: Qt 5 reference:

Detailed Description

QOpenGLContext represents the OpenGL state of an underlying OpenGL context. To set up a context, set its screen and format such that they match those of the surface or surfaces with which the context is meant to be used, if necessary make it share resources with other contexts with setShareContext(), and finally call create(). Use the return value or isValid() to check if the context was successfully initialized.

A context can be made current against a given surface by calling makeCurrent(). When OpenGL rendering is done, call swapBuffers() to swap the front and back buffers of the surface, so that the newly rendered content becomes visible. To be able to support certain platforms, QOpenGLContext requires that you call makeCurrent() again before starting rendering a new frame, after calling swapBuffers().

If the context is temporarily not needed, such as when the application is not rendering, it can be useful to delete it in order to free resources. You can connect to the aboutToBeDestroyed() signal to clean up any resources that have been allocated with different ownership from the QOpenGLContext itself.

Once a QOpenGLContext has been made current, you can render to it in a platform independent way by using Qt's OpenGL enablers such as QOpenGLFunctions, QOpenGLBuffer, QOpenGLShaderProgram, and QOpenGLFramebufferObject. It is also possible to use the platform's OpenGL API directly, without using the Qt enablers, although potentially at the cost of portability. The latter is necessary when wanting to use OpenGL 1.x or OpenGL ES 1.x.

For more information about the OpenGL API, refer to the official OpenGL documentation.

For an example of how to use QOpenGLContext see the OpenGL Window example.

Thread Affinity

QOpenGLContext can be moved to a different thread with moveToThread(). Do not call makeCurrent() from a different thread than the one to which the QOpenGLContext object belongs. A context can only be current in one thread and against one surface at a time, and a thread only has one context current at a time.

Context Resource Sharing

Resources such as textures and vertex buffer objects can be shared between contexts. Use setShareContext() before calling create() to specify that the contexts should share these resources. QOpenGLContext internally keeps track of a QOpenGLContextGroup object which can be accessed with shareGroup(), and which can be used to find all the contexts in a given share group. A share group consists of all contexts that have been successfully initialized and are sharing with an existing context in the share group. A non-sharing context has a share group consisting of a single context.

Default Framebuffer

On certain platforms, a framebuffer other than 0 might be the default frame buffer depending on the current surface. Instead of calling glBindFramebuffer(0), it is recommended that you use glBindFramebuffer(ctx->defaultFramebufferObject()), to ensure that your application is portable between different platforms. However, if you use QOpenGLFunctions::glBindFramebuffer(), this is done automatically for you.

Source: https://doc.qt.io/archives/qt-5.15/qopenglcontext.html

Complete member index

Every captured member retains its own identity. Identical captured declaration text is linked once; this does not establish native inheritance or interchangeable objects.

Member Kind Signature Summary
LibGL attribute Any
LibGLES attribute Any
OpenGLModuleType attribute type Convert a number or string to an integer, or return 0 if no arguments are given.
__init__ function (self, *args: Any, **kwargs: Any) -> None Native constructor; consult class documentation for supported overloads. (shared captured text)
aboutToBeDestroyed function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QOpenGLContext.aboutToBeDestroyed; argument details are not documented.
areSharing function (self, first: Any, second: Any) -> bool X.areSharing(first, second) -> bool
blockSignals function (self, b: Any) -> bool X.blockSignals(b) -> bool (shared captured text)
childEvent function (self, event: Any) -> Any (shared captured text)
children function (self) -> tuple X.children() -> tuple (shared captured text)
className function (self, *args: Any, **kwargs: Any) -> Any Return the classname of the object (shared captured text)
connect function (self, signal: Any, receiver: Any, slot: Any, type: Any) -> bool X.connect(signal, receiver, slot, type) -> bool (shared captured text)
create function (self) -> bool X.create() -> bool
currentContext function (self) -> Any X.currentContext() -> PythonQt.QtGui.QOpenGLContext
customEvent function (self, event: Any) -> Any (shared captured text)
defaultFramebufferObject function (self) -> int X.defaultFramebufferObject() -> int
delete function (self, *args: Any, **kwargs: Any) -> Any Deletes the C++ object (at your own risk, my friend!) (shared captured text)
deleteLater function (self) -> Any (shared captured text)
destroyed function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QOpenGLContext.destroyed; argument details are not documented.
disconnect function (self, signal: Any, receiver: Any, slot: Any) -> bool X.disconnect(signal, receiver, slot) -> bool (shared captured text)
doneCurrent function (self) -> None Convenience function for calling [makeCurrent](https://doc.qt.io/archives/qt-5.15/qopenglcontext.html#makeCurrent) with a 0 surface.
dumpObjectInfo function (self) -> Any (shared captured text)
dumpObjectTree function (self) -> Any (shared captured text)
dynamicPropertyNames function (self) -> Any (shared captured text)
event function (self, event: Any) -> bool X.event(event) -> bool (shared captured text)
eventFilter function (self, watched: Any, event: Any) -> bool X.eventFilter(watched, event) -> bool (shared captured text)
extensions function (self) -> Any Returns the set of OpenGL extensions supported by this context.
findChild function (self, type: Any, name: Any) -> Any X.findChild(type, name) -> PythonQt.private.QObject (shared captured text)
findChildren function (self, type: Any, name: Any) -> tuple X.findChildren(type, name) -> tuple (shared captured text)
format function (self) -> Any X.format() -> PythonQt.QtGui.QSurfaceFormat
functions function (self) -> Any Get the [QOpenGLFunctions](https://doc.qt.io/archives/qt-5.15/qopenglfunctions.html) instance for this context.
globalShareContext function (self) -> Any X.globalShareContext() -> PythonQt.QtGui.QOpenGLContext
hasExtension function (self, extension: Any) -> bool X.hasExtension(extension) -> bool
help function (self, *args: Any, **kwargs: Any) -> Any Shows the help of available methods for this class (shared captured text)
inherits function (self, *args: Any, **kwargs: Any) -> Any Returns if the class inherits or is of given type name (shared captured text)
installEventFilter function (self, filterObj: Any) -> Any (shared captured text)
isOpenGLES function (self) -> bool X.isOpenGLES() -> bool
isSignalConnected function (self, signal: Any) -> bool X.isSignalConnected(signal) -> bool (shared captured text)
isValid function (self) -> bool X.isValid() -> bool
isWidgetType function (self) -> bool X.isWidgetType() -> bool (shared captured text)
isWindowType function (self) -> bool X.isWindowType() -> bool (shared captured text)
killTimer function (self, id: Any) -> Any (shared captured text)
makeCurrent function (self, surface: Any) -> bool X.makeCurrent(surface) -> bool
metaObject function (self) -> Any X.metaObject() -> PythonQt.QtCore.QMetaObject (shared captured text)
moveToThread function (self, thread: Any) -> Any (shared captured text)
nativeHandle function (self) -> Any X.nativeHandle() -> object
objectName attribute Any (shared captured text)
objectNameChanged function (self, *args: Any, **kwargs: Any) -> Any Native PythonQt.QtGui.QOpenGLContext.objectNameChanged; argument details are not documented.
openGLModuleHandle function (self) -> int Returns the platform-specific handle for the OpenGL implementation that is currently in use.
openGLModuleType function (self) -> Any Returns the underlying OpenGL implementation type.
parent function (self) -> Any X.parent() -> PythonQt.private.QObject (shared captured text)
property function (self, name: Any) -> Any X.property(name) -> object (shared captured text)
removeEventFilter function (self, obj: Any) -> Any (shared captured text)
screen function (self) -> Any X.screen() -> PythonQt.QtGui.QScreen
sender function (self) -> Any X.sender() -> PythonQt.private.QObject (shared captured text)
senderSignalIndex function (self) -> int X.senderSignalIndex() -> int (shared captured text)
setFormat function (self, format: Any) -> None Sets the format the OpenGL context should be compatible with.
setNativeHandle function (self, handle: Any) -> None Set the native handles for this context.
setObjectName function (self, name: Any) -> Any (shared captured text)
setParent function (self, parent: Any) -> Any (shared captured text)
setProperty function (self, name: Any, value: Any) -> bool X.setProperty(name, value) -> bool (shared captured text)
setScreen function (self, screen: Any) -> None Sets the screen the OpenGL context should be valid for.
setShareContext function (self, shareContext: Any) -> None Makes this context share textures, shaders, and other OpenGL resources with shareContext.
shareContext function (self) -> Any X.shareContext() -> PythonQt.QtGui.QOpenGLContext
shareGroup function (self) -> Any X.shareGroup() -> PythonQt.QtGui.QOpenGLContextGroup
signalsBlocked function (self) -> bool X.signalsBlocked() -> bool (shared captured text)
startTimer function (self, interval: Any, timerType: Any) -> int X.startTimer(interval, timerType) -> int (shared captured text)
supportsThreadedOpenGL function (self) -> bool X.supportsThreadedOpenGL() -> bool
surface function (self) -> Any X.surface() -> PythonQt.QtGui.QSurface
swapBuffers function (self, surface: Any) -> None Swap the back and front buffers of surface.
thread function (self) -> Any (shared captured text)
timerEvent function (self, event: Any) -> Any (shared captured text)
tr function (self, text: Any, ambig: Any, n: Any) -> str X.tr(text, ambig, n) -> str (shared captured text)