vispy.gloo.context module#

Functionality to deal with GL Contexts in vispy. This module is defined in gloo, because gloo (and the layers that depend on it) need to be context aware. The module “provides” a context, and therefore depends on this module. Although the GLContext class is aimed for use by (for practical reasons), it should be possible to use GLContext without using by overloading it in an appropriate manner.

An GLContext object acts as a placeholder on which different parts of vispy (or other systems) can keep track of information related to an OpenGL context.

class vispy.gloo.context.FakeCanvas#

Bases: object

Fake canvas to allow using gloo without

Instantiate this class to collect GLIR commands from gloo interactions. Call flush() in your draw event handler to execute the commands in the active contect.


Flush commands. Call this after setting to context to current.

class vispy.gloo.context.GLContext(config=None, shared=None)#

Bases: BaseGlooFunctions

An object encapsulating data necessary for a OpenGL context

configdict | None

The requested configuration.

sharedinstance of GLContext | None

The shared context.

property capabilities#

The OpenGL capabilities

property config#

A dictionary describing the configuration of this GL context.

create_shared(name, ref)#

For the app backends to create the GLShared object.


The name.


The reference.



eventinstance of Event

The event.

property glir#

The glir queue for the context. This queue is for objects that can be shared accross canvases (if they share a contex).


Set the OpenGL viewport

This is a wrapper for gl.glViewport.


X and Y coordinates, plus width and height. Can be passed in as individual components, or as a single tuple with four values.

property shared#

Get the object that represents the namespace that can potentially be shared between multiple contexts.

class vispy.gloo.context.GLShared#

Bases: object

Representation of a “namespace” that can be shared between different contexts. App backends can associate themselves with this object via add_ref().

This object can be used to establish whether two contexts/canvases share objects, and can be used as a placeholder to store shared information, such as glyph atlasses.

add_ref(name, ref)#

Add a reference for the backend object that gives access to the low level context. Used in The given name must match with that of previously added references.

property name#

The name of the canvas backend that this shared namespace is associated with. Can be None.

property parser#

The GLIR parser (shared between contexts)

property ref#

A reference (stored internally via a weakref) to an object that the backend system can use to obtain the low-level information of the “reference context”. In Vispy this will typically be the CanvasBackend object.


Forget about the given canvas. Used by the canvas when closed.


Get the currently active canvas

Returns None if there is no canvas available. A canvas is made active on initialization and before the draw event is emitted.

When a gloo object is created, it is associated with the currently active Canvas, or with the next Canvas to be created if there is no current Canvas. Use Canvas.set_current() to manually activate a canvas.


Get the default OpenGL context configuration


Dictionary of config values.


Make a canvas active. Used primarily by the canvas itself.