vispy.gloo.wrappers module#

vispy.gloo.wrappers.GL_PRESETS = {'additive': {'blend': True, 'blend_equation': 'func_add', 'blend_func': ('src_alpha', 'one'), 'cull_face': False, 'depth_test': False}, 'opaque': {'blend': False, 'cull_face': False, 'depth_test': True}, 'translucent': {'blend': True, 'blend_equation': 'func_add', 'blend_func': ('src_alpha', 'one_minus_src_alpha', 'zero', 'one'), 'cull_face': False, 'depth_test': True}}#

Some OpenGL state presets for common use cases: ‘opaque’, ‘translucent’, ‘additive’.

To be used in set_state().

class vispy.gloo.wrappers.GlooFunctions#

Bases: BaseGlooFunctions

property glir#

The GLIR queue corresponding to the current canvas

vispy.gloo.wrappers.clear(color=True, depth=True, stencil=True)#

Clear the screen buffers

This is a wrapper for gl.glClear.

Parameters:
colorbool | str | tuple | instance of Color

Clear the color buffer bit. If not bool, set_clear_color will be used to set the color clear value.

depthbool | float

Clear the depth buffer bit. If float, set_clear_depth will be used to set the depth clear value.

stencilbool | int

Clear the stencil buffer bit. If int, set_clear_stencil will be used to set the stencil clear index.

vispy.gloo.wrappers.finish()#

Wait for GL commands to to finish

This creates a GLIR command for glFinish and then processes the GLIR commands. If the GLIR interpreter is remote (e.g. WebGL), this function will return before GL has finished processing the commands.

vispy.gloo.wrappers.flush()#

Flush GL commands

This is a wrapper for glFlush(). This also flushes the GLIR command queue.

vispy.gloo.wrappers.get_gl_configuration()#

Read the current gl configuration

This function uses constants that are not in the OpenGL ES 2.1 namespace, so only use this on desktop systems.

Returns:
configdict

The currently active OpenGL configuration.

vispy.gloo.wrappers.get_state_presets()#

The available GL state presets.

Returns:
presetsdict

The dictionary of presets usable with set_state().

vispy.gloo.wrappers.read_pixels(viewport=None, alpha=True, mode='color', out_type='unsigned_byte')#

Read pixels from the currently selected buffer.

Under most circumstances, this function reads from the front buffer. Unlike all other functions in vispy.gloo, this function directly executes an OpenGL command.

Parameters:
viewportarray-like | None

4-element list of x, y, w, h parameters. If None (default), the current GL viewport will be queried and used.

alphabool

If True (default), the returned array has 4 elements (RGBA). If False, it has 3 (RGB). This only effects the color mode.

modestr

Type of buffer data to read. Can be one of ‘colors’, ‘depth’, or ‘stencil’. See returns for more information.

out_typestr | dtype

Can be ‘unsigned_byte’ or ‘float’. Note that this does not use casting, but instead determines how values are read from the current buffer. Can also be numpy dtypes np.uint8, np.ubyte, or np.float32.

Returns:
pixelsarray

3D array of pixels in np.uint8 or np.float32 format. The array shape is (h, w, 3) or (h, w, 4) for colors mode, with the top-left corner of the framebuffer at index [0, 0] in the returned array. If ‘mode’ is depth or stencil then the last dimension is 1.

vispy.gloo.wrappers.set_blend_color(color)#

Set the blend color

Parameters:
colorstr | tuple | instance of Color

Color to use. See vispy.color.Color for options.

vispy.gloo.wrappers.set_blend_equation(mode_rgb, mode_alpha=None)#

Specify the equation for RGB and alpha blending

Parameters:
mode_rgbstr

Mode for RGB.

mode_alphastr | None

Mode for Alpha. If None, mode_rgb is used.

Notes

See set_blend_equation for valid modes.

vispy.gloo.wrappers.set_blend_func(srgb='one', drgb='zero', salpha=None, dalpha=None)#

Specify pixel arithmetic for RGB and alpha

Parameters:
srgbstr

Source RGB factor.

drgbstr

Destination RGB factor.

salphastr | None

Source alpha factor. If None, srgb is used.

dalphastr

Destination alpha factor. If None, drgb is used.

vispy.gloo.wrappers.set_clear_color(color='black', alpha=None)#

Set the screen clear color

This is a wrapper for gl.glClearColor.

Parameters:
colorstr | tuple | instance of Color

Color to use. See vispy.color.Color for options.

alphafloat | None

Alpha to use.

vispy.gloo.wrappers.set_clear_depth(depth=1.0)#

Set the clear value for the depth buffer

This is a wrapper for gl.glClearDepth.

Parameters:
depthfloat

The depth to use.

vispy.gloo.wrappers.set_clear_stencil(index=0)#

Set the clear value for the stencil buffer

This is a wrapper for gl.glClearStencil.

Parameters:
indexint

The index to use when the stencil buffer is cleared.

vispy.gloo.wrappers.set_color_mask(red, green, blue, alpha)#

Toggle writing of frame buffer color components

Parameters:
redbool

Red toggle.

greenbool

Green toggle.

bluebool

Blue toggle.

alphabool

Alpha toggle.

vispy.gloo.wrappers.set_cull_face(mode='back')#

Set front, back, or both faces to be culled

Parameters:
modestr

Culling mode. Can be “front”, “back”, or “front_and_back”.

vispy.gloo.wrappers.set_depth_func(func='less')#

Specify the value used for depth buffer comparisons

Parameters:
funcstr

The depth comparison function. Must be one of ‘never’, ‘less’, ‘equal’, ‘lequal’, ‘greater’, ‘gequal’, ‘notequal’, or ‘always’.

vispy.gloo.wrappers.set_depth_mask(flag)#

Toggle writing into the depth buffer

Parameters:
flagbool

Whether depth writing should be enabled.

vispy.gloo.wrappers.set_depth_range(near=0.0, far=1.0)#

Set depth values

Parameters:
nearfloat

Near clipping plane.

farfloat

Far clipping plane.

vispy.gloo.wrappers.set_front_face(mode='ccw')#

Set which faces are front-facing

Parameters:
modestr

Can be ‘cw’ for clockwise or ‘ccw’ for counter-clockwise.

vispy.gloo.wrappers.set_hint(target, mode)#

Set OpenGL drawing hint

Parameters:
targetstr

The target, e.g. ‘fog_hint’, ‘line_smooth_hint’, ‘point_smooth_hint’.

modestr

The mode to set (e.g., ‘fastest’, ‘nicest’, ‘dont_care’).

vispy.gloo.wrappers.set_line_width(width=1.0)#

Set line width

Parameters:
widthfloat

The line width.

vispy.gloo.wrappers.set_polygon_offset(factor=0.0, units=0.0)#

Set the scale and units used to calculate depth values

Parameters:
factorfloat

Scale factor used to create a variable depth offset for each polygon.

unitsfloat

Multiplied by an implementation-specific value to create a constant depth offset.

vispy.gloo.wrappers.set_sample_coverage(value=1.0, invert=False)#

Specify multisample coverage parameters

Parameters:
valuefloat

Sample coverage value (will be clamped between 0. and 1.).

invertbool

Specify if the coverage masks should be inverted.

vispy.gloo.wrappers.set_scissor(x, y, w, h)#

Define the scissor box

Parameters:
xint

Left corner of the box.

yint

Lower corner of the box.

wint

The width of the box.

hint

The height of the box.

vispy.gloo.wrappers.set_state(preset=None, **kwargs)#

Set the OpenGL rendering state, optionally using a preset.

Parameters:
preset{‘opaque’, ‘translucent’, ‘additive’}, optional

A named state preset for typical use cases.

**kwargskeyword arguments

Other supplied keyword arguments will override any preset defaults. Options to be enabled or disabled should be supplied as booleans (e.g., 'depth_test=True', cull_face=False), non-boolean entries will be passed as arguments to set_* functions (e.g., blend_func=('src_alpha', 'one') will call set_blend_func()).

Notes

This serves three purposes:

  1. Set GL state using reasonable presets.

  2. Wrapping glEnable/glDisable functionality.

  3. Convienence wrapping of other gloo.set_* functions.

For example, one could do the following:

>>> from vispy import gloo
>>> gloo.set_state('translucent', depth_test=False, clear_color=(1, 1, 1, 1))  # noqa, doctest:+SKIP

This would take the preset defaults for ‘translucent’, turn depth testing off (which would normally be on for that preset), and additionally set the glClearColor parameter to be white.

Another example to showcase glEnable/glDisable wrapping:

>>> gloo.set_state(blend=True, depth_test=True, polygon_offset_fill=False)  # noqa, doctest:+SKIP

This would be equivalent to calling

>>> from vispy.gloo import gl
>>> gl.glDisable(gl.GL_BLEND)
>>> gl.glEnable(gl.GL_DEPTH_TEST)
>>> gl.glEnable(gl.GL_POLYGON_OFFSET_FILL)

Or here’s another example:

>>> gloo.set_state(clear_color=(0, 0, 0, 1), blend=True, blend_func=('src_alpha', 'one'))  # noqa, doctest:+SKIP

Thus arbitrary GL state components can be set directly using set_state. Note that individual functions are exposed e.g., as set_clear_color, with some more informative docstrings about those particular functions.

vispy.gloo.wrappers.set_stencil_func(func='always', ref=0, mask=8, face='front_and_back')#

Set front or back function and reference value

Parameters:
funcstr

See set_stencil_func.

refint

Reference value for the stencil test.

maskint

Mask that is ANDed with ref and stored stencil value.

facestr

Can be ‘front’, ‘back’, or ‘front_and_back’.

vispy.gloo.wrappers.set_stencil_mask(mask=8, face='front_and_back')#

Control the front or back writing of individual bits in the stencil

Parameters:
maskint

Mask that is ANDed with ref and stored stencil value.

facestr

Can be ‘front’, ‘back’, or ‘front_and_back’.

vispy.gloo.wrappers.set_stencil_op(sfail='keep', dpfail='keep', dppass='keep', face='front_and_back')#

Set front or back stencil test actions

Parameters:
sfailstr

Action to take when the stencil fails. Must be one of ‘keep’, ‘zero’, ‘replace’, ‘incr’, ‘incr_wrap’, ‘decr’, ‘decr_wrap’, or ‘invert’.

dpfailstr

Action to take when the stencil passes.

dppassstr

Action to take when both the stencil and depth tests pass, or when the stencil test passes and either there is no depth buffer or depth testing is not enabled.

facestr

Can be ‘front’, ‘back’, or ‘front_and_back’.

vispy.gloo.wrappers.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.