Uranium
Application Framework
UM.View.GL.ShaderProgram.ShaderProgram Class Reference

Public Member Functions

None __init__ (self)
 
None load (self, str file_name, str version="")
 
bool setVertexShader (self, str shader)
 
bool setFragmentShader (self, str shader)
 
bool setGeometryShader (self, str shader)
 
None build (self)
 
None setUniformValue (self, str name, Union[Vector, Matrix, Color, List[float], List[List[float]], float, int] value, **Any kwargs)
 
None setTexture (self, int texture_unit, Texture texture)
 
None enableAttribute (self, str name, str type, int offset, int stride=0)
 
None disableAttribute (self, str name)
 
None bind (self)
 
None release (self)
 
None addBinding (self, str key, str value)
 
None removeBinding (self, str key)
 
None updateBindings (self, **kwargs)
 
None addAttributeBinding (self, str key, str value)
 
None removeAttributeBinding (self, str key)
 

Detailed Description

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.

Member Function Documentation

◆ addAttributeBinding()

None UM.View.GL.ShaderProgram.ShaderProgram.addAttributeBinding (   self,
str  key,
str  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.

:param key: The identifier used in the shader for the attribute.
:param value: The name to bind to this attribute.

◆ addBinding()

None UM.View.GL.ShaderProgram.ShaderProgram.addBinding (   self,
str  key,
str  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.

:param key: The name of the uniform to bind.
:param value: The string used to look up values for this uniform.

◆ bind()

None UM.View.GL.ShaderProgram.ShaderProgram.bind (   self)
Bind the shader to use it for rendering.

◆ build()

None UM.View.GL.ShaderProgram.ShaderProgram.build (   self)
Build the complete shader program out of the separately provided sources.

◆ disableAttribute()

None UM.View.GL.ShaderProgram.ShaderProgram.disableAttribute (   self,
str  name 
)
Disable a vertex attribute so it is no longer used.

:param name: The name of the attribute to use.

◆ enableAttribute()

None UM.View.GL.ShaderProgram.ShaderProgram.enableAttribute (   self,
str  name,
str  type,
int  offset,
int   stride = 0 
)
Enable a vertex attribute to be used.

:param name: The name of the attribute to enable.
:param type: The type of the attribute. Should be a python type.
:param offset: The offset into a bound buffer where the data for this attribute starts.
:param stride: The stride of the attribute.

:note If the shader is not bound, this will bind the shader.

◆ load()

None UM.View.GL.ShaderProgram.ShaderProgram.load (   self,
str  file_name,
str   version = "" 
)
Load a shader program file.

This method loads shaders from a simple text file, using Python's configparser
as parser.

:note When writing shader program files, please note that configparser expects
indented lines for multiline values. Since the shaders are provided as a single
multiline string, make sure to indent them properly.

:param file_name: The shader file to load.
:param 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

:exception{InvalidShaderProgramError} Raised when the file provided does not contain any valid shaders.

◆ release()

None UM.View.GL.ShaderProgram.ShaderProgram.release (   self)
Release the shader so it will no longer be used for rendering.

◆ removeAttributeBinding()

None UM.View.GL.ShaderProgram.ShaderProgram.removeAttributeBinding (   self,
str  key 
)
Remove an attribute binding.

:param key: The name of the attribute binding to remove.

◆ removeBinding()

None UM.View.GL.ShaderProgram.ShaderProgram.removeBinding (   self,
str  key 
)
Remove a uniform value binding.

:param key: The uniform to remove.

◆ setFragmentShader()

bool UM.View.GL.ShaderProgram.ShaderProgram.setFragmentShader (   self,
str  shader 
)
Set the fragment shader to use.

:param shader: :type{string} The fragment shader to use.

◆ setTexture()

None UM.View.GL.ShaderProgram.ShaderProgram.setTexture (   self,
int  texture_unit,
Texture  texture 
)
Set a texture that should be bound to a specified texture unit when this shader is bound.

:param texture_unit: :type{int} The texture unit to bind the texture to.
:param texture: :type{Texture} The texture object to bind to the texture unit.

◆ setUniformValue()

None UM.View.GL.ShaderProgram.ShaderProgram.setUniformValue (   self,
str  name,
Union[Vector, Matrix, Color, List[float], List[List[float]], float, int]  value,
**Any  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.

:param name: The name of the uniform variable.
:param value: The value to set the variable to.
:param kwargs: Keyword arguments.
Possible keywords:
- cache: False when the value should not be cached for later calls to bind().

◆ setVertexShader()

bool UM.View.GL.ShaderProgram.ShaderProgram.setVertexShader (   self,
str  shader 
)
Set the vertex shader to use.

:param shader: :type{string} The vertex shader to use.

◆ updateBindings()

None UM.View.GL.ShaderProgram.ShaderProgram.updateBindings (   self,
**  kwargs 
)
Update the values of bindings.

:param kwargs: Keyword arguments.
Each key should correspond to a binding name, with the
value being the value of the uniform.

:note By default, these values are not cached as they are expected to be continuously
updated.

The documentation for this class was generated from the following file: