pyglet.graphics.shader
- exception ShaderException
- class Attribute
Abstract accessor for an attribute in a mapped buffer.
- __init__( ) None
Create the attribute accessor.
- Parameters:
name (
str) – Name of the vertex attribute.location (
int) – Location (index) of the vertex attribute.count (
int) – Number of components in the attribute.gl_type (
int) – OpenGL type enumerant; for example,GL_FLOATnormalize (
bool) – True if OpenGL should normalize the valuesinstance (
bool) – True if OpenGL should treat this as an instanced attribute.
- get_region(
- buffer: AttributeBufferObject,
- start: int,
- count: int,
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:
buffer (
AttributeBufferObject) – The buffer to map.start (
int) – Offset of the first vertex to map.count (
int) – Number of vertices to map
- Return type:
Array[Type[_SimpleCData]]
- set_pointer(ptr: int) None
Setup this attribute to point to the currently bound buffer at the given offset.
offsetshould be based on the currently bound buffer’sptrmember.
- class ComputeShaderProgram
OpenGL Compute Shader Program.
- static dispatch( ) 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:
- property uniform_blocks: dict[str, pyglet.graphics.shader.UniformBlock]
- class Shader
OpenGL shader.
Shader objects are compiled on instantiation. You can reuse a Shader object in multiple ShaderPrograms.
- class ShaderProgram
OpenGL shader program.
- vertex_list( ) VertexList
Create a VertexList.
- Parameters:
count (
int) – The number of vertices in the list.mode (
int) – OpenGL drawing mode enumeration; for example, one ofGL_POINTS,GL_LINES,GL_TRIANGLES, etc. This determines how the list is drawn in the given batch.batch (
Batch) – Batch to add the VertexList to, orNoneif a Batch will not be used. Using a Batch is strongly recommended.group (
Group) – Group to add the VertexList to, orNoneif no group is required.data (
Any) – Attribute formats and initial data for the vertex list.
- Return type:
- vertex_list_indexed(
- count: int,
- mode: int,
- indices: Sequence[int],
- batch: Batch = None,
- group: Group = None,
- **data: Any,
Create a IndexedVertexList.
- Parameters:
count (
int) – The number of vertices in the list.mode (
int) – OpenGL drawing mode enumeration; for example, one ofGL_POINTS,GL_LINES,GL_TRIANGLES, etc. This determines how the list is drawn in the given batch.indices (
Sequence[int]) – Sequence of integers giving indices into the vertex list.batch (
Batch) – Batch to add the VertexList to, orNoneif a Batch will not be used. Using a Batch is strongly recommended.group (
Group) – Group to add the VertexList to, orNoneif no group is required.data (
Any) – Attribute formats and initial data for the vertex list.
- Return type:
- vertex_list_instanced(
- count: int,
- mode: int,
- instance_attributes: Sequence[str],
- batch: Batch = None,
- group: Group = None,
- **data: Any,
- Return type:
- vertex_list_instanced_indexed(
- count: int,
- mode: int,
- indices: Sequence[int],
- instance_attributes: Sequence[str],
- batch: Batch = None,
- group: Group = None,
- **data: Any,
- Return type:
- property attributes: dict[str, Any]
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 uniform_blocks: dict[str, pyglet.graphics.shader.UniformBlock]
A dictionary of introspected UniformBlocks.
This property returns a dictionary of
UniformBlockinstances. They can be accessed by name. For example:block = my_shader_program.uniform_blocks['WindowBlock'] ubo = block.create_ubo()
- property uniforms: dict[str, Any]
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 doesn’t contain several statements in one line.
- class UniformBlock
- __init__(
- program: ShaderProgram,
- name: str,
- index: int,
- size: int,
- binding: int,
- uniforms: dict[int, tuple[str, Union[Type[ctypes.c_int], Type[ctypes.c_float], Type[ctypes.c_ubyte], int], int, int]],
- uniform_count: int,
Initialize a uniform block for a ShaderProgram.
- create_ubo() UniformBufferObject
Create a new UniformBufferObject from this uniform block.
- Return type:
- set_binding(binding: int) None
Rebind the Uniform Block to a new binding index number.
This only affects the program this Uniform Block is derived from.
Binding value of 0 is reserved for the Pyglet’s internal uniform block named
WindowBlock. :rtype:NoneWarning
By setting a binding manually, the user is expected to manage all Uniform Block bindings for all shader programs manually. Since the internal global ID’s will be unaware of changes set by this function, collisions may occur if you use a lower number.
Note
You must call
create_uboto get another Uniform Buffer Object after calling this, as the previous buffers are still bound to the old binding point.
- binding: int
- index: int
- name: str
- program: CallableProxyType[Callable[..., Any] | Any] | Any
- size: int
- uniform_count
- uniforms: dict[int, tuple[str, GLDataType, int, int]]
- view_cls: type[Structure] | None