shaders.Shader
pykraken.shaders.Shader Encapsulates a GPU shader and its associated render state.
At a glance
6 membersReference
PYTHON APIConstructor
methodshaders.Shader(fragment_base_path: str | PathLike, uniform_buffer_count: int = 0, sampler_count: int = 1, storage_buffer_sizes: Sequence[int] = [])Create a Shader instance from a fragment shader file.
Args
- fragment_base_path (
str) — Base file name of the fragment shader. The appropriate backend extension will be appended automatically. - uniform_buffer_count (
int, optional) — Number of uniform buffers used by the shader. Default is 0. - sampler_count (
int, optional) — Number of samplers used by the shader. Default is 1. - storage_buffer_sizes (
Sequence[int], optional) — The storage buffer sizes in bytes used by the shader. Default is an empty sequence.
Raises
- RuntimeError — If the shader cannot be loaded or created.
bind
methodbind(self) -> NoneBinds this shader state to the current render pass, making it active for subsequent draw calls.
Raises
- RuntimeError — If the shader state cannot be bound.
set_storage_buffer_data
methodset_storage_buffer_data(self, binding: int, data: Buffer, /) -> NoneSets the data for a data storage buffer for the fragment shader at the specified binding.
Currently untested with GLSL.
Args
- binding (
int) — Shader storage buffer binding. - data (
Buffer) — Buffer-compatible object containing the bytes to be given to the shader buffer.
Raises
- TypeError — If the object does not provide compatible storage buffer data.
- RuntimeError — If the storage buffer data cannot be set.
set_texture_sampler
methodset_texture_sampler(self, binding: int, texture: Texture, sampler: shaders.Sampler) -> NoneSet the texture and sampler used for a fragment shader texture binding.
Args
- binding (
int) — Sampler binding index. - texture (
Texture) — Texture to bind. Must have theShaderSampledusage flag. - sampler (
Sampler) — Sampler to use for the texture.
Raises
- RuntimeError — If the texture is not usable as a shader resource.
- ValueError — If the binding index is out of range.
set_uniform
methodset_uniform(self, binding: int, data: Buffer, /) -> NoneSet uniform data for the fragment shader at the specified binding point.
Args
- binding (
int) — Uniform buffer binding index. - data (
Buffer) — Buffer-compatible object containing the uniform bytes.
Raises
- TypeError — If the object does not provide compatible uniform data.
- RuntimeError — If the uniform data cannot be set.
unbind
methodunbind(self) -> NoneUnbinds the current shader state, reverting to the default render state.