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 vispy.app module “provides” a context, and therefore depends on this module. Although the GLContext class is aimed for use by vispy.app (for practical reasons), it should be possible to use GLContext without using vispy.app 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 vispy.app

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

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

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

Bases: vispy.gloo.wrappers.BaseGlooFunctions

An object encapsulating data necessary for a OpenGL context

Parameters
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.

Parameters
namestr

The name.

refobject

The reference.

flush_commands(event=None)

Flush

Parameters
eventinstance of Event

The event.

get_viewport()
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_viewport(*args)

Set the OpenGL viewport

This is a wrapper for gl.glViewport.

Parameters
*argstuple

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 vispy.app.canvas.backends. 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.

vispy.gloo.context.forget_canvas(canvas)

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

vispy.gloo.context.get_current_canvas()

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.

vispy.gloo.context.get_default_config()

Get the default OpenGL context configuration

Returns
configdict

Dictionary of config values.

vispy.gloo.context.set_current_canvas(canvas)

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