pyglet.graphics.shader
- exception ShaderException
- class Attribute
Describes an attribute in a shader.
- __init__(
- name: str,
- location: int,
- components: int,
- data_type: Literal['f', 'i', 'I', 'h', 'H', 'b', 'B', 'q', 'Q', '?', 'd'],
- normalize: bool = False,
- divisor: int = 0,
Create the attribute accessor.
- Parameters:
name (
str) – Name of the vertex attribute.location (
int) – Location (index) of the vertex attribute.components (
int) – Number of components in the attribute.data_type (
Literal['f','i','I','h','H','b','B','q','Q','?','d']) – Data type intended for use with the attribute.normalize (
bool) – True if OpenGL should normalize the valuesdivisor (
int) – The divisor value if this is an instanced attribute.
- set_data_type( ) None
Set datatype to a new format and normalization.
Must be done before this attribute is used, or may cause unexpected behavior.
- Return type:
-
fmt:
AttributeFormat
- class AttributeFormat
A format describing the properties of an Attribute.
- class AttributeView
Describes a view of the attribute at its bound buffer.
- class GraphicsAttribute
A combination of format and view to give the overall attribute information.
- __init__(
- attribute: Attribute,
- view: AttributeView,
- class PushConstants
PushConstants(stages: ‘tuple[ShaderType]’, constants: ‘list[tuple[str, GLSLDataTypes]]’)
- __init__(
- stages: tuple[Literal['vertex', 'fragment', 'geometry', 'compute', 'tesscontrol', 'tessevaluation']],
- constants: list[tuple[str, Literal['mat4', 'vec4', 'vec3', 'vec2', 'float', 'int', 'uint', 'bool']]],
- class Sampler
Sampler(name: ‘str’, desc_set: ‘int’, binding: ‘int’, count: ‘int’ = 1, stages: ‘Sequence[ShaderType]’ = (‘fragment’,))
- class Shader
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.
- abstractmethod classmethod supported_shaders() tuple[Literal['vertex', 'fragment', 'geometry', 'compute', 'tesscontrol', 'tessevaluation'], ...]
Return the supported shader types for this shader class.
- abstractmethod static get_string_class() type[ShaderSource]
Return the proper ShaderSource class used to validate the shader.
- Return type:
- class ShaderProgram
-
- get_uniform_block_cls() type[UniformBlock]
- Return type:
- set_attributes(*attributes: Attribute) None
Define the attributes of the vertex shader.
On some backends like OpenGL, this is unnecessary unless you want to redefine the buffers.
- Return type:
- set_uniform_blocks(
- *uniform_blocks: UniformBlockDesc,
- Return type:
- vertex_list(
- count: int,
- mode: GeometryMode,
- batch: GLBatch | None = None,
- group: Group | None = None,
- **data: Any,
Create a VertexList.
- Parameters:
count (
int) – The number of vertices in the list.mode (
GeometryMode) – 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 (
GLBatch|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, orNoneif no group is required.data (
Any) – Attribute formats and initial data for the vertex list.
- Return type:
- vertex_list_indexed(
- count: int,
- mode: GeometryMode,
- indices: Sequence[int],
- batch: GLBatch | None = None,
- group: Group | None = None,
- **data: Any,
Create a IndexedVertexList.
- Parameters:
count (
int) – The number of vertices in the list.mode (
GeometryMode) – 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 (
GLBatch|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, orNoneif no group is required.data (
Any) – Attribute formats and initial data for the vertex list.
- Return type:
- vertex_list_instanced(
- count: int,
- mode: GeometryMode,
- instance_attributes: dict[str, int],
- batch: GLBatch | None = None,
- group: Group | None = None,
- **data: Any,
- Return type:
- vertex_list_instanced_indexed(
- count: int,
- *,
- mode: GeometryMode,
- indices: Sequence[int],
- instance_attributes: Sequence[str],
- batch: GLBatch | None = None,
- group: Group | None = 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 id
- property uniform_blocks: dict[str, 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()
- class ShaderSource
String source of shader used during load of a Shader instance.
- class UBOBindingManager
Manages global Uniform Block binding assignments.
- add_explicit_binding(
- shader_program: ShaderProgram,
- ub_name: str,
- binding: int,
Used when a uniform block has set its own binding point.
- Return type:
- get_binding(
- shader_program: ShaderProgram,
- ub_name: str,
Retrieve a global Uniform Block binding ID.
- Return type:
- class UniformArrayBase
Backend-agnostic base for uniform array wrappers.
- get() UniformArrayBase
- Return type:
- class UniformBase
Backend-agnostic base for uniform wrappers.
- __init__(
- *,
- 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],
- count
- get
- length
- location
- name
- program
- set
- size
- type
- class UniformBlock
- __init__(
- program: ShaderProgram,
- 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 the Uniform Buffer Object to the binding point of this Uniform Block.
- Return type:
- create_ubo() UniformBufferObject
Create a new UniformBufferObject from this uniform block.
- Return type:
UniformBufferObject
- 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:
- binding: int
- index: int
- name: str
- program: CallableProxyType[Callable[..., Any] | Any] | Any
- size: int
- uniform_count
- uniforms: dict
- view_cls: type[ctypes.Structure]