pyglet.graphics.shader

exception ShaderException
class Attribute(name, location, count, gl_type, normalize)

Abstract accessor for an attribute in a mapped buffer.

enable()

Enable the attribute.

get_region(buffer, start, count)

Map a buffer region using this attribute as an accessor.

The returned region consists of a contiguous array of component data elements. For example, if this attribute uses 3 floats per vertex, and the count parameter is 4, the number of floats mapped will be 3 * 4 = 12.

Parameters
bufferAbstractMappable

The buffer to map.

startint

Offset of the first vertex to map.

countint

Number of vertices to map

Return type

AbstractBufferRegion

set_pointer(ptr)

Setup this attribute to point to the currently bound buffer at the given offset.

offset should be based on the currently bound buffer’s ptr member.

Parameters
offsetint

Pointer offset to the currently bound buffer for this attribute.

set_region(buffer, start, count, data)

Set the data over a region of the buffer.

Parameters
bufferAbstractMappable`

The buffer to modify.

startint

Offset of the first vertex to set.

countint

Number of vertices to set.

data : A sequence of data components.

class ComputeShaderProgram(source: str)

OpenGL Compute Shader Program

bind() None
static dispatch(x: int = 1, y: int = 1, z: int = 1, barrier: int = 4294967295) None

Launch one or more compute work groups.

The ComputeShaderProgram should be active (bound) before calling this method. The x, y, and z parameters specify the number of local work groups that will be dispatched in the X, Y and Z dimensions.

static stop()
static unbind()
use() None
property id: int
limits
property uniform_blocks: dict
property uniforms: dict
class Shader(source_string: str, shader_type: str)

OpenGL shader.

Shader objects are compiled on instantiation. You can reuse a Shader object in multiple ShaderPrograms.

shader_type is one of 'compute', 'fragment', 'geometry', 'tesscontrol', 'tessevaluation', or 'vertex'.

property id
class ShaderProgram(*shaders: Shader)

OpenGL shader program.

bind()
static stop()
static unbind()
use()
vertex_list(count, mode, batch=None, group=None, **data)

Create a VertexList.

Parameters
countint

The number of vertices in the list.

modeint

OpenGL drawing mode enumeration; for example, one of GL_POINTS, GL_LINES, GL_TRIANGLES, etc. This determines how the list is drawn in the given batch.

batch~pyglet.graphics.Batch

Batch to add the VertexList to, or None if a Batch will not be used. Using a Batch is strongly recommended.

group~pyglet.graphics.Group

Group to add the VertexList to, or None if no group is required.

**datastr or tuple

Attribute formats and initial data for the vertex list.

Return type

VertexList

vertex_list_indexed(count, mode, indices, batch=None, group=None, **data)

Create a IndexedVertexList.

Parameters
countint

The number of vertices in the list.

modeint

OpenGL drawing mode enumeration; for example, one of GL_POINTS, GL_LINES, GL_TRIANGLES, etc. This determines how the list is drawn in the given batch.

indicessequence of int

Sequence of integers giving indices into the vertex list.

batch~pyglet.graphics.Batch

Batch to add the VertexList to, or None if a Batch will not be used. Using a Batch is strongly recommended.

group~pyglet.graphics.Group

Group to add the VertexList to, or None if no group is required.

**datastr or tuple

Attribute formats and initial data for the vertex list.

Return type

IndexedVertexList

property attributes
property id
property uniform_blocks
property uniforms
class ShaderSource(source: str, source_type: c_uint)

GLSL source container for making source parsing simpler.

We support locating out attributes and applying #defines values.

NOTE: We do assume the source is neat enough to be parsed this way and don’t contain several statements in one line.

validate() str

Return the validated shader source.

class UniformBlock(program, name, index, size, uniforms)
create_ubo(index=0)

Create a new UniformBufferObject from this uniform block.

Parameters
indexint

The uniform buffer index the returned UBO will bind itself to. By default, this is 0.

Return type

UniformBufferObject

index
name
program
size
uniforms
view_cls
class UniformBufferObject(view_class, buffer_size, index)
bind(index=None)
read()

Read the byte contents of the buffer

buffer
property id
index
view