Uranium
Application Framework
|
An abstract class for dealing with shader programs. More...
Public Member Functions | |
def | __init__ (self) |
def | load |
Load a shader program file. More... | |
def | setVertexShader (self, shader) |
Set the vertex shader to use. More... | |
def | setFragmentShader (self, shader) |
Set the fragment shader to use. More... | |
def | setGeometryShader (self, shader) |
def | build (self) |
Build the complete shader program out of the separately provided sources. More... | |
def | setUniformValue (self, name, value, kwargs) |
Set a named uniform variable. More... | |
def | setTexture (self, texture_unit, texture) |
Set a texture that should be bound to a specified texture unit when this shader is bound. More... | |
def | enableAttribute |
Enable a vertex attribute to be used. More... | |
def | disableAttribute |
Disable a vertex attribute so it is no longer used. More... | |
def | bind (self) |
Bind the shader to use it for rendering. More... | |
def | release (self) |
Release the shader so it will no longer be used for rendering. More... | |
def | addBinding (self, key, value) |
Add a uniform value binding. More... | |
def | removeBinding |
Remove a uniform value binding. More... | |
def | updateBindings (self, kwargs) |
Update the values of bindings. More... | |
def | addAttributeBinding (self, key, value) |
Add an attribute binding. More... | |
def | removeAttributeBinding |
Remove an attribute binding. More... | |
An abstract class for dealing with shader programs.
This class provides an interface an some basic elements for dealing with shader programs. Shader programs are described in a simple text file based on the Python configparser module. These files contain the shaders for the different shader program stages, in addition to defaults that should be used for uniform values and uniform and attribute bindings.
def UM.View.GL.ShaderProgram.ShaderProgram.addAttributeBinding | ( | self, | |
key, | |||
value | |||
) |
Add an attribute binding.
Attribute bindings are similar to uniform value bindings, except they specify what what attribute name binds to which attribute in the shader.
TODO: Actually use these bindings. However, that kind of depends on a more freeform MeshData object as freeform bindings are rather useless when we only have 5 supported attributes.
key | The identifier used in the shader for the attribute. |
value | The name to bind to this attribute. |
def UM.View.GL.ShaderProgram.ShaderProgram.addBinding | ( | self, | |
key, | |||
value | |||
) |
Add a uniform value binding.
Uniform value bindings are used to provide an abstraction between uniforms as set from code and uniforms as used from shaders. Each binding specifies a uniform name as key that should be mapped to a string that can be used to look up the value of the uniform.
key | The name of the uniform to bind. |
value | The string used to look up values for this uniform. |
def UM.View.GL.ShaderProgram.ShaderProgram.bind | ( | self, | |
None | |||
) |
Bind the shader to use it for rendering.
def UM.View.GL.ShaderProgram.ShaderProgram.build | ( | self | ) |
Build the complete shader program out of the separately provided sources.
def UM.View.GL.ShaderProgram.ShaderProgram.disableAttribute | ( | self, | |
name | |||
) |
Disable a vertex attribute so it is no longer used.
name | The name of the attribute to use. |
def UM.View.GL.ShaderProgram.ShaderProgram.enableAttribute | ( | self, | |
name | |||
) |
Enable a vertex attribute to be used.
name | The name of the attribute to enable. |
type | The type of the attribute. Should be a python type. |
offset | The offset into a bound buffer where the data for this attribute starts. |
stride | The stride of the attribute. |
def UM.View.GL.ShaderProgram.ShaderProgram.load | ( | self, | |
file_name, | |||
version = "" |
|||
) |
Load a shader program file.
This method loads shaders from a simple text file, using Python's configparser as parser.
file_name | The shader file to load. |
version | can be used for a special version of the shader. it will be appended to the keys [vertex, fragment, geometry] in the shader file |
def UM.View.GL.ShaderProgram.ShaderProgram.release | ( | self, | |
None | |||
) |
Release the shader so it will no longer be used for rendering.
def UM.View.GL.ShaderProgram.ShaderProgram.removeAttributeBinding | ( | self, | |
key | |||
) |
Remove an attribute binding.
key | The name of the attribute binding to remove. |
def UM.View.GL.ShaderProgram.ShaderProgram.removeBinding | ( | self, | |
key | |||
) |
Remove a uniform value binding.
key | The uniform to remove. |
def UM.View.GL.ShaderProgram.ShaderProgram.setFragmentShader | ( | self, | |
shader | |||
) |
Set the fragment shader to use.
shader | string The fragment shader to use. |
def UM.View.GL.ShaderProgram.ShaderProgram.setTexture | ( | self, | |
texture_unit, | |||
texture | |||
) |
Set a texture that should be bound to a specified texture unit when this shader is bound.
texture_unit | int The texture unit to bind the texture to. |
texture | Texture The texture object to bind to the texture unit. |
def UM.View.GL.ShaderProgram.ShaderProgram.setUniformValue | ( | self, | |
name, | |||
value, | |||
kwargs | |||
) |
Set a named uniform variable.
Unless otherwise specified as argument, the specified value will be cached so that it does not matter whether bind() has already been called. Instead, if the shader is not currently bound, the next call to bind() will update the uniform values.
name | The name of the uniform variable. |
value | The value to set the variable to. |
kwargs | Keyword arguments. Possible keywords:
|
def UM.View.GL.ShaderProgram.ShaderProgram.setVertexShader | ( | self, | |
shader | |||
) |
Set the vertex shader to use.
shader | string The vertex shader to use. |
def UM.View.GL.ShaderProgram.ShaderProgram.updateBindings | ( | self, | |
kwargs, | |||
None | |||
) |
Update the values of bindings.
kwargs | Keyword arguments. Each key should correspond to a binding name, with the value being the value of the uniform. |