CLASS v1.8.0

shaders.Shader

pykraken.shaders.Shader

Encapsulates a GPU shader and its associated render state.

Reference

PYTHON API
shaders.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

method
bind(self) -> None

Binds 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(self, binding: int, data: Buffer, /) -> None

Sets 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(self, binding: int, texture: Texture, sampler: shaders.Sampler) -> None

Set the texture and sampler used for a fragment shader texture binding.

Args

  • binding (int) — Sampler binding index.
  • texture (Texture) — Texture to bind. Must have the ShaderSampled usage 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(self, binding: int, data: Buffer, /) -> None

Set 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

method
unbind(self) -> None

Unbinds the current shader state, reverting to the default render state.

Find your next step

Start typing to search the manual.