pyglet.graphics.shader

exception ShaderException
class Attribute

Abstract accessor for an attribute in a mapped buffer.

__init__(name, location, count, gl_type, normalize)

Create the attribute accessor.

Parameters:
namestr

Name of the vertex attribute.

locationint

Location (index) of the vertex attribute.

countint

Number of components in the attribute.

gl_typeint

OpenGL type enumerant; for example, GL_FLOAT

normalize: bool

True if OpenGL should normalize the values

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:
bufferAttributeBufferObject

The buffer to map.

startint

Offset of the first vertex to map.

countint

Number of vertices to map

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.

dataseq

A sequence of data components.

class ComputeShaderProgram

OpenGL Compute Shader Program

__init__(source: str)

Create an OpenGL ComputeShaderProgram from source.

bind() None
Return type:

None

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

Return type:

None

static stop()
static unbind()
use() None
Return type:

None

property id: int
property uniform_blocks: dict
property uniforms
class Shader

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

__init__(source_string: str, shader_type: str)
delete()
property id
class ShaderProgram

OpenGL shader program.

__init__(*shaders: Shader)
bind()
delete()
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: dict

Attribute metadata dictionary

This property returns a dictionary containing metadata of all Attributes that were introspected in this ShaderProgram. Modifying this dictionary has no effect.

property id
property uniform_blocks: dict

A dictionary of introspected UniformBlocks

This property returns a dictionary of UniformBlock instances. They can be accessed by name. For example:

block = my_shader_program.uniform_blocks['WindowBlock']
ubo = block.create_ubo()
property uniforms: dict

Uniform metadata dictionary

This property returns a dictionary containing metadata of all Uniforms that were introspected in this ShaderProgram. Modifying this dictionary has no effect. To set or get a uniform, the uniform name is used as a key on the ShaderProgram instance. For example:

my_shader_program[uniform_name] = 123
value = my_shader_program[uniform_name]
class ShaderSource

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.

__init__(source: str, source_type: c_uint)

Create a shader source wrapper.

validate() str

Return the validated shader source.

Return type:

str

class UniformBlock
__init__(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
__init__(view_class, buffer_size, index)
bind(index=None)
read()

Read the byte contents of the buffer

buffer
property id
index
view