pyglet.graphics.shader
- exception ShaderException
- class Attribute
Abstract accessor for an attribute in a mapped buffer.
- __init__(
- name: str,
- location: int,
- components: int,
- data_type: Literal['f', 'i', 'I', 'h', 'H', 'b', 'B', 'q', 'Q', '?', 'd'],
- normalize: bool = False,
- instance: bool = False,
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 valuesinstance (
bool
) – True if OpenGL should treat this as an instanced attribute.
- set_data_type( )
Set data type to a new format.
Must be done before you render anything, or may cause unexpected behavior.
This is done to normalize certain data types after a shader is loaded or inspected.
- 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 ShaderBase
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.
- __init__(
- source_string: str,
- shader_type: Literal['vertex', 'fragment', 'geometry', 'compute', 'tesscontrol', 'tessevaluation'],
Initialize a shader type.
- class ShaderProgramBase
- __init__(*shaders: ShaderBase) None
- get_uniform_block_cls() type[pyglet.graphics.shader.UniformBlockBase]
- Return type:
- set_attributes(
- *attributes: Attribute,
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( ) VertexList
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 (
Batch
) – Batch to add the VertexList to, orNone
if a Batch will not be used. Using a Batch is strongly recommended.group (
Group
) – Group to add the VertexList to, orNone
if 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: Batch = None,
- group: Group = 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 (
Batch
) – Batch to add the VertexList to, orNone
if a Batch will not be used. Using a Batch is strongly recommended.group (
Group
) – Group to add the VertexList to, orNone
if 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: Sequence[str],
- batch: Batch = None,
- group: Group = None,
- **data: Any,
- Return type:
- vertex_list_instanced_indexed(
- count: int,
- mode: GeometryMode,
- 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 id
- property uniform_blocks: dict[str, pyglet.graphics.shader.UniformBlockBase]
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()
- class ShaderSource
String source of shader used during load of a Shader instance.
- class UniformBlockBase
- __init__(
- program: ShaderProgramBase,
- name: str,
- index: int,
- size: int,
- binding: int,
- uniforms: dict,
- uniform_count: int,
Initialize a uniform block for a ShaderProgram.
- bind(ubo: UniformBufferObjectBase) None
Bind the Uniform Buffer Object to the binding point of this Uniform Block.
- Return type:
- create_ubo() UniformBufferObjectBase
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:None
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_ubo
to 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
- view_cls: type[ctypes.Structure] | None