ComputeShader
- class moderngl.ComputeShader
A Compute Shader is a Shader Stage that is used entirely for computing arbitrary information.
While it can do rendering, it is generally used for tasks not directly related to drawing.
- Compute shaders support uniforms are other member object just like a
Storage buffers can be bound using
Buffer.bind_to_storage_buffer()
.Uniform buffers can be bound using
Buffer.bind_to_uniform_block()
.Images can be bound using
Texture.bind_to_image()
.
Create
- Context.compute_shader(source: str) ComputeShader
A
ComputeShader
is a Shader Stage that is used entirely for computing arbitrary information. While it can do rendering, it is generally used for tasks not directly related to drawing.- Parameters:
source (str) – The source of the compute shader.
- Returns:
ComputeShader
object
Methods
- ComputeShader.run(group_x: int = 1, group_y: int = 1, group_z: int = 1) None
Run the compute shader.
- Parameters:
group_x (int) – The number of work groups to be launched in the X dimension.
group_y (int) – The number of work groups to be launched in the Y dimension.
group_z (int) – The number of work groups to be launched in the Z dimension.
- ComputeShader.get(key: str, default: Any) Union[Uniform, UniformBlock, Subroutine, Attribute, Varying]
Returns a Uniform, UniformBlock, Subroutine, Attribute or Varying.
- Parameters:
default – This is the value to be returned in case key does not exist.
- Returns:
- ComputeShader.release() None
Release the ModernGL object.
- ComputeShader.__eq__(other: Any)
Compares to compute shaders ensuring the internal opengl name/id is the same.
- ComputeShader.__getitem__(key: str) Union[Uniform, UniformBlock, Subroutine, Attribute, Varying]
Get a member such as uniforms, uniform blocks, subroutines, attributes and varyings by name.
# Get a uniform uniform = program['color'] # Uniform values can be set on the returned object # or the `__setitem__` shortcut can be used. program['color'].value = 1.0, 1.0, 1.0, 1.0 # Still when writing byte data we need to use the `write()` method program['color'].write(buffer)
- ComputeShader.__setitem__(key: str, value: Any)
Set a value of uniform or uniform block.
# Set a vec4 uniform uniform['color'] = 1.0, 1.0, 1.0, 1.0 # Optionally we can store references to a member and set the value directly uniform = program['color'] uniform.value = 1.0, 0.0, 0.0, 0.0 uniform = program['cameraMatrix'] uniform.write(camera_matrix)
- ComputeShader.__iter__() Generator[str, None, None]
Yields the internal members names as strings.
This includes all members such as uniforms, attributes etc.
Attributes
- ComputeShader.glo
The internal OpenGL object.
This values is provided for debug purposes only.
- Type:
int
- ComputeShader.mglo
Internal representation for debug purposes only.
- ComputeShader.extra
Any - Attribute for storing user defined objects
- ComputeShader.ctx
The context this object belongs to