pyglet.graphics.shader
- exception MissingAttributeException
Exception for when a Shader has a missing attribute name.
- exception MissingUniformException
Exception for when a Shader uniform is missing due to optimization or mispelling.
- exception ShaderException
- exception UnsupportedShaderType
Exception for trying to create an unsupported shader.
- class ComputeShaderProgram(source: str) None
Backend-agnostic compute shader program container.
Create a resource identity.
- class PushConstants(
- stages: tuple[Literal['vertex', 'fragment', 'geometry', 'compute', 'tesscontrol', 'tessevaluation']],
- constants: list[tuple[str, Literal['mat4', 'vec4', 'vec3', 'vec2', 'float', 'int', 'uint', 'bool']]],
- class Sampler(
- name: str,
- desc_set: int,
- binding: int,
- count: int = 1,
- stages: Sequence[Literal['vertex', 'fragment', 'geometry', 'compute', 'tesscontrol', 'tessevaluation']] = ('fragment',),
- class Shader(
- source_string: str,
- shader_type: Literal['vertex', 'fragment', 'geometry', 'compute', 'tesscontrol', 'tessevaluation'],
Graphics shader.
Shader objects may be compiled on instantiation if OpenGL or already compiled in Vulkan. You can reuse a Shader object in multiple ShaderPrograms.
Initialize a shader type.
- classmethod supported_shaders() tuple[Literal['vertex', 'fragment', 'geometry', 'compute', 'tesscontrol', 'tessevaluation'], ...]
Return the supported shader types for this shader class.
- static get_string_class() type[ShaderSource]
Return the proper ShaderSource class used to validate the shader.
- Return type:
- shader_type: ShaderType
- class ShaderProgram(
- *shaders: _AbstractShader,
- vertex_layout: VertexLayout | None,
Backend-agnostic shader program container.
Concrete backends are responsible for compiling/linking shaders, introspecting attributes and uniforms, and providing API-specific program state management.
Initialize a shader program with an optional default attribute layout.
vertex_layout=Nonekeeps the introspected attribute formats. AnVertexLayoutchanges only the buffer interpretation of the named attributes; their component counts remain defined by the shader.
- class ShaderProgramView(
- program: _AbstractShaderProgram,
- attribute_formats: dict[str, AttributeFormat],
- attribute_keys: tuple[tuple[Any, ...], ...],
An interned ShaderProgram view with a specific vertex layout.
A view shares its owning program’s linked shader and uniforms, but caches its own vertex formats, instance divisors, and vertex-domain metadata.
Initialize a shader program with an optional default attribute layout.
vertex_layout=Nonekeeps the introspected attribute formats. AnVertexLayoutchanges only the buffer interpretation of the named attributes; their component counts remain defined by the shader.- set_instance_attributes(
- **attributes: int,
Deprecated adapter for creating a view with layout-owned divisors.
- Return type:
- vertex_list(
- count: int,
- mode: GeometryMode,
- batch: Batch | None = None,
- group: Group | None = None,
- storage: VertexStorage | None = None,
- vertex_layout: VertexLayout | None = None,
- **data: Any,
Create a VertexList using this view’s attribute layout.
- Parameters:
count (
int) – The number of vertices in the list.mode (
GeometryMode) – AGeometryModevalue determining how the vertices are drawn.batch (
Batch|None) – Batch to add the VertexList to, orNoneto use the default batch.group (
Group|None) – Group to add the VertexList to, orNoneto create a defaultShaderGroupfor this view.storage (
VertexStorage|None) – Storage created by the selected batch to use for the geometry, orNoneto use that batch’s default storage.vertex_layout (
VertexLayout|None) – Optional override for the vertex attribute formats.Noneuses this view’s geometry layout.data (
Any) – Initial data for each vertex attribute.
- Return type:
- vertex_list_indexed(
- count: int,
- mode: GeometryMode,
- indices: Sequence[int],
- batch: Batch | None = None,
- group: Group | None = None,
- **data: Any,
Create a IndexedVertexList.
- Parameters:
count (
int) – The number of vertices in the list.mode (
GeometryMode) – AGeometryModevalue, such asPOINTS,LINES, orTRIANGLES. 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|None) – Batch to add the VertexList to, orNoneif a Batch will not be used. Using a Batch is strongly recommended.group (
Group|None) – Group to add the VertexList to, orNoneto create a defaultShaderGroupfor this program.data (
Any) – Initial data for each vertex attribute.
- Return type:
- vertex_list_instanced(
- count: int,
- mode: GeometryMode,
- batch: Batch | None = None,
- group: Group | None = None,
- **data: Any,
- Return type:
- vertex_list_instanced_indexed(
- count: int,
- *,
- mode: GeometryMode,
- indices: Sequence[int],
- batch: Batch | None = None,
- group: Group | None = None,
- **data: Any,
- Return type:
- property attribute_formats: dict[str, AttributeFormat]
Geometry formats used to store values for the shader inputs.
- property attribute_key: tuple[Any, ...]
Stable, cached key describing the geometry formats by name.
- property attribute_keys: tuple[tuple[Any, ...], ...]
Stable tuple describing geometry formats independently of shader locations.
- property attributes: dict[str, ShaderAttribute]
Shader input 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 geometry_layout: VertexLayout
Geometry layout derived by this legacy shader convenience API.
- property program: _AbstractShaderProgram
The ShaderProgram that owns this layout.
- class ShaderSource(source: str, source_type: Any) None
String source of shader used during load of a Shader instance.
Initialize source text for a backend shader type.
- class TransformFeedbackShaderProgram(
- *shaders: _AbstractShader,
- varyings: Sequence[str],
- varying_buffer_type: Literal['interleaved', 'separate'] = 'separate',
- vertex_layout: VertexLayout | None,
Backend-agnostic transform feedback shader program container.
Initialize a transform feedback shader program.
- Parameters:
shaders (
_AbstractShader) – One or moreShaderinstances.varyings (
Sequence[str]) – Names of vertex/geometry shader output variables to capture with transform feedback.varying_buffer_type (
Literal['interleaved','separate']) – Buffer packing mode for captured outputs:"separate"(one buffer per varying) or"interleaved"(single interleaved buffer).
Notes
This class is replaced by a backend-specific implementation at import time when a supported backend is active.
- class UBOBindingManager(max_binding_count: int) None
Manages global Uniform Block binding assignments.
- get_binding(
- shader_program: _AbstractShaderProgram,
- ub_name: str,
Retrieve a global Uniform Block binding ID.
- Return type:
- class UniformArrayBase( ) None
Backend-agnostic base for uniform array wrappers.
- get() UniformArrayBase
- Return type:
- class UniformBase(
- *,
- name: str,
- uniform_type: int,
- size: int,
- location: Any,
- program: Any,
- matrix_types: tuple[int, ...],
- array_wrapper_factory: Callable[[Any, Callable, Callable, Any, bool], UniformArrayBase],
Backend-agnostic base for uniform wrappers.
- count
- get
- length
- location
- name
- program
- set
- size
- type
- class UniformBlock(
- program: _AbstractShaderProgram,
- name: str,
- index: int,
- size: int,
- binding: int,
- uniforms: dict,
- uniform_count: int,
Initialize a uniform block for a ShaderProgram.
- bind(ubo: UniformBufferObject) None
Bind a UBO to the binding point of this uniform block.
- Return type:
- create_ubo( ) UniformBufferObject
Create a new UniformBufferObject from this uniform block.
- Return type:
- create_ubo_region( ) UniformBufferRegion
Create a ring-buffered region for updating and binding 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.Warning
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.- Return type:
- program: CallableProxyType[Callable[..., Any] | Any] | Any
- uniform_count
- view_cls: type[ctypes.Structure]
- class UniformBlockDesc(*args, **kwargs)
- get_default_shader() ShaderProgram
A default shader for rendering primitives.
- Return type: