4.1.3.12. Shader

This modules provides classes to manager OpenGL Shader.

class PyOpenGLng.HighLevelApi.Shader.GlShader(shader_type=None, file_name=None, source_code=None)[source]

Bases: object

This class defines a shader source code.

Instances have an internal source code buffer to accumulate the source code before to compile it. We can get the content of this buffer using the str(). And we can test if the shader is compiled using a Boolean evaluation of the instance.

The shader type can be passed to the constructor or retrieved from a source file, where a comment line with the following pattern must be present:

// #shader_type SHADER_TYPE

where SHADER_TYPE could be either vertex, fragment and geometry. It is case insensitive.

Source files are preprocessed so as to replace line of the form:

#include(file.glsl)

the path is relative to the parent source file.

FRAGMENT_SHADER = 35632
GEOMETRY_SHADER = 36313
SHADER_TYPES = (35633, 35632, 36313)
VERTEX_SHADER = 35633
_load_from_file(file_name)[source]

Load source code from file and preprocess it.

_logger = <logging.Logger object at 0x4d02490>
_preprocessor(source_code, path)[source]

Preprocess the source code.

_set_shader_type(shader_type)[source]

Set the shader type. It raise an exception if the shader is already set.

_set_shader_type_from_source_code()[source]

Set the shader type from the source code.

clear_source()[source]

Clear the internal source code buffer.

compile()[source]

Compile the shader.

load_from_file(file_name)[source]

Load the source code from the file given by file_name, preprocess it and append it to the internal buffer. The shader type is determined from the source.

load_from_string(source)[source]

Append the source string to the internal buffer.

class PyOpenGLng.HighLevelApi.Shader.GlShaderManager[source]

Bases: object

This class provides a shader manager where each shader or program are identified by a name and the shader sources are loaded from files.

The shaders or programs can be accessed using an attribute or a dictionary interface. For example to get the shader fixed_fragment we can use either:

shader_manager.fixed_fragment
shader_manager.['fixed_fragment']

We can test if an identifier exists using:

'fixed_fragment' in shader_manager
_instance = None
_rlock = <_RLock owner=None count=0>
has_visual()[source]

Link a program with the given list of shader names. This program is identified by shader_name. The argument program_interface can be used to set the program interface.

load_from_file(shader_name, shader_file_name)[source]

Load a shader from a source file and compile it. This shader is identified by shader_name.

class PyOpenGLng.HighLevelApi.Shader.GlShaderProgram(name)[source]

Bases: object

This class defines a shader program.

We can access the uniforms and vertex attributes defined in the shader program using the two class attributes: uniforms and attributes, respectively. Both act as class that has an attribute for each uniform and vertex attribute.

For example we can set a colour uniform using:

shader_program.uniforms.colour = (1., 1., 1.)

and get back its values using:

shader_program.uniforms.colour

We can also use a dictionary interface:

# to set the values
shader_program.uniforms['colour'] = (1., 1., 1.)
# to get the values
shader_program.uniforms['colour']

Moreover we can test if an uniform is defined using:

'colour' in shader_program.uniforms

Similarly, we can access a vertex attribute using:

shader_program.attributes.positions

For example to attach a VBO:

shader_program.attributes.positions.bind_to_buffer(positions_vbo)
_logger = <logging.Logger object at 0x3ebee10>
attach_shader(shader)[source]

Attach a shader.

bind()[source]

Bind the shader.

bind_attribute_location_array(name, location)[source]

Bind an attribute location. The program should not be linked.

Link the program.

set_program_interface(program_interface)[source]

Set the programming interface.

set_uniform_block_binding(name, binding_point)[source]

Set the binding point for an uniform block.

set_uniform_block_bindings()[source]

Set the uniform block binding points as defined by the programming interface.

unbind()[source]

Unbind the shader.

class PyOpenGLng.HighLevelApi.Shader.GlShaderProgramAttributes(shader_program)[source]

Bases: PyOpenGLng.Tools.AttributeDictionaryInterface.AttributeDictionaryInterface

This class is a wrapper to access the vertex attributes within a shader program.

class PyOpenGLng.HighLevelApi.Shader.GlShaderProgramInterface(uniform_blocks, attributes)[source]

Bases: object

This class defines a programming interface for a program.

_init_attributes(attributes)[source]
_init_uniform_blocks(uniform_blocks)[source]
class PyOpenGLng.HighLevelApi.Shader.GlShaderProgramInterfaceAttribute(name, location)[source]

Bases: object

This class defines a programming interface for an attribute as a pair (name, location)

bind_to_buffer(vbo)[source]

Bind the vertex attribute to a Vertex Buffer Object.

class PyOpenGLng.HighLevelApi.Shader.GlShaderProgramInterfaceUniformBlock(name, binding_point)[source]

Bases: object

This class defines a programming interface for an uniform block as a pair (name, binding_point)

class PyOpenGLng.HighLevelApi.Shader.GlShaderProgramUniformBlocks(shader_program)[source]

Bases: PyOpenGLng.Tools.AttributeDictionaryInterface.AttributeDictionaryInterface

This class is a wrapper to access the uniform blocks within a shader program.

class PyOpenGLng.HighLevelApi.Shader.GlShaderProgramUniforms(shader_program)[source]

Bases: PyOpenGLng.Tools.AttributeDictionaryInterface.AttributeDictionaryInterfaceDescriptor

This class is a wrapper to access the uniforms within a shader program.

class PyOpenGLng.HighLevelApi.Shader.GlUniform(shader_program, name, location, gl_type, size, within_uniform_block=False, offset=-1)[source]

Bases: PyOpenGLng.HighLevelApi.Shader.GlVariable

This class defines a uniform within a shader program.

The argument shader_program is the GlShaderProgram instance, name is the name of the uniform in the source code, location is the location of the uniform, gl_type the OpenGL data type and size is the number of elements of the uniform.

VARIABLE_LABEL = 'Uniform'
get()[source]

Return the uniform value(s).

set(value)[source]

Set the uniform value(s).

class PyOpenGLng.HighLevelApi.Shader.GlUniformBlock(name, location, uniforms)[source]

Bases: PyOpenGLng.Tools.AttributeDictionaryInterface.AttributeDictionaryInterface

This class defines an uniform block.

uniform_block_location()[source]
uniform_block_name()[source]
class PyOpenGLng.HighLevelApi.Shader.GlUniformMatrix(shader_program, name, location, gl_type, size, within_uniform_block=False, offset=-1)[source]

Bases: PyOpenGLng.HighLevelApi.Shader.GlUniformNd

This class defines a matrix uniform.

The argument shader_program is the GlShaderProgram instance, name is the name of the uniform in the source code, location is the location of the uniform, gl_type the OpenGL data type and size is the number of elements of the uniform.

set(value)[source]

Set the uniform value(s).

class PyOpenGLng.HighLevelApi.Shader.GlUniformNd(shader_program, name, location, gl_type, size, within_uniform_block=False, offset=-1)[source]

Bases: PyOpenGLng.HighLevelApi.Shader.GlUniform

This class is a base class for vector and matrix uniforms.

The argument shader_program is the GlShaderProgram instance, name is the name of the uniform in the source code, location is the location of the uniform, gl_type the OpenGL data type and size is the number of elements of the uniform.

_check_value(value)[source]

Check the value dimension and shape.

get()[source]

Return the uniform value(s).

class PyOpenGLng.HighLevelApi.Shader.GlUniformSampler(shader_program, name, location, gl_type, size, within_uniform_block=False, offset=-1)[source]

Bases: PyOpenGLng.HighLevelApi.Shader.GlUniform

This class defines a sampler uniform.

The argument shader_program is the GlShaderProgram instance, name is the name of the uniform in the source code, location is the location of the uniform, gl_type the OpenGL data type and size is the number of elements of the uniform.

class PyOpenGLng.HighLevelApi.Shader.GlUniformVariable(shader_program, name, location, gl_type, size, within_uniform_block=False, offset=-1)[source]

Bases: PyOpenGLng.HighLevelApi.Shader.GlUniform

This class defines a variable uniform.

The argument shader_program is the GlShaderProgram instance, name is the name of the uniform in the source code, location is the location of the uniform, gl_type the OpenGL data type and size is the number of elements of the uniform.

class PyOpenGLng.HighLevelApi.Shader.GlUniformVector(shader_program, name, location, gl_type, size, within_uniform_block=False, offset=-1)[source]

Bases: PyOpenGLng.HighLevelApi.Shader.GlUniformNd

This class defines a vector uniform.

The argument shader_program is the GlShaderProgram instance, name is the name of the uniform in the source code, location is the location of the uniform, gl_type the OpenGL data type and size is the number of elements of the uniform.

set(value)[source]

Set the uniform value(s).

class PyOpenGLng.HighLevelApi.Shader.GlVariable(shader_program, name, location, gl_type, size, within_uniform_block=False, offset=-1)[source]

Bases: object

This class is a base class for Attributes and Uniforms.

The argument shader_program is the GlShaderProgram instance, name is the name of the uniform in the source code, location is the location of the uniform, gl_type the OpenGL data type and size is the number of elements of the uniform.

VARIABLE_LABEL = None

This attribute is used to set the variable label: attribute or uniform.

class PyOpenGLng.HighLevelApi.Shader.GlVertexAttribute(shader_program, name, location, gl_type, size, within_uniform_block=False, offset=-1)[source]

Bases: PyOpenGLng.HighLevelApi.Shader.GlVariable

This class defines a vertex attributes.

The argument shader_program is the GlShaderProgram instance, name is the name of the uniform in the source code, location is the location of the uniform, gl_type the OpenGL data type and size is the number of elements of the uniform.

VARIABLE_LABEL = 'Attribute'
bind_to_buffer(vbo)[source]

Bind the vertex attribute to a Vertex Buffer Object.

PyOpenGLng.HighLevelApi.Shader.sorted_by_location(a_list)[source]
PyOpenGLng.HighLevelApi.Shader.sorted_by_offset(a_list)[source]

Previous topic

4.1.3.11. STL

Next topic

4.1.3.13. Solids

This Page