ComputeShaders¶
-
Context.
compute_shader
(source) → ModernGL.programs.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: compute shader program Return type: ComputeShader
-
class
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.
-
run
(group_x=1, group_y=1, group_z=1)¶ 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.
-
source
¶ str – The source code of the compute shader.
-
uniforms
¶ UniformMap
– The uniforms of the program. The return value is a dictinary like object. It can be used to accessUniform
objects by name.Examples
Set the value of the uniforms:
# uniform vec3 eye_pos; >>> program.uniforms['eye_pos'].value = (10.0, 20.0, 0.0) # uniform sampler2D my_textures[3]; >>> program.uniforms['my_texture'].value = [0, 3, 2] # The values of `my_textures` will be: my_textures[0] = GL_TEXTURE0 # GL_TEXTURE0 my_textures[1] = GL_TEXTURE0 + 3 # GL_TEXTURE3 my_textures[2] = GL_TEXTURE0 + 2 # GL_TEXTURE2
Get information about the uniforms:
>>> program.uniforms['eye_pos'].location 0 >>> program.uniforms['eye_pos'].dimension 3 >>> program.uniforms['eye_pos'].value (10.0, 20.0, 0.0) >>> program.uniforms['my_textures'].dimension 1 >>> program.uniforms['my_textures'].array_length 3
-
uniform_blocks
¶ UniformBlockMap
– The uniform blocks of the program. The return value is a dictinary like object. It can be used to accessUniformBlock
objects by name.Examples
Get the location of the uniform block:
# uniform custom_material { # ... # }; >>> program.uniform_blocks['custom_material'].location 16
-