glpp::core::object::shader_program_t class

class for creating and managing shader programs in OpenGL

shader_program_t is a storage class for OpenGL shader programs, that creates, owns and manages buffer objects.

Constructors, destructors, conversion operators

template<class... shader_t>
shader_program_t(const shader_t&... shader) explicit
constructor

Public functions

void attatch(const shader_t& shader)
attatch shader_t to shader_shader_program_t
void link()
link shader program
void set_texture(const char* name, const texture_slot_t& texture)
set texture sampler to use a specific texture unit
void set_texture(GLint location, const texture_slot_t& texture)
set texture sampler to use a specific texture unit
template<class texture_slot_iterator>
void set_texture_array(const char* name, const texture_slot_iterator begin, const texture_slot_iterator end)
set texture sampler array to use specific texture units
template<class texture_slot_iterator>
void set_texture_array(GLint location, const texture_slot_iterator begin, const texture_slot_iterator end)
set texture sampler array to use specific texture units
template<class Value>
void set_uniform(const char* name, const Value& value)
set uniform
template<class Value>
void set_uniform(GLint location, const Value& value)
set uniform
template<class Value>
void set_uniform_array(const char* name, const Value* begin, const size_t size)
set uniform array
template<class Value>
void set_uniform_array(GLint location, const Value* begin, const size_t size)
set uniform array
auto uniform_location(const GLchar* name) const -> GLint
get uniform location of a uniform inside the shader program
void use() const
Make shader program active.

Function documentation

template<class... shader_t>
glpp::core::object::shader_program_t::shader_program_t(const shader_t&... shader) explicit

constructor

Construct a shader_program_t from a list of shaders. The shaders will be attatched and linked by the constructor call. After construction the shader_program_t is ready to be used for rendering.

void glpp::core::object::shader_program_t::attatch(const shader_t& shader)

attatch shader_t to shader_shader_program_t

Parameters
shader [in] shader stage that shall be attatched to the shader program

This method will attatch shader as a new shader stage to the shader_program_t. The shader_t object can safely be destructed after attatchment without invalidation the shader_program_t.

void glpp::core::object::shader_program_t::link()

link shader program

This function will link all attatched shaders to one pipeline. It will throw if the attatched shaders are not sufficient to create a valild shader pipeline.

void glpp::core::object::shader_program_t::set_texture(const char* name, const texture_slot_t& texture)

set texture sampler to use a specific texture unit

Parameters
name [in] name of texture in the shader code
texture [in] texture slot that shall be used

This function will set a texture sampler in the shader programm to use a specific texture slot/texture unit.

void glpp::core::object::shader_program_t::set_texture(GLint location, const texture_slot_t& texture)

set texture sampler to use a specific texture unit

Parameters
location [in] location of the texture in the shader program
texture [in] texture slot object of the texture that shall be bound

This function will set a texture sampler in the shader programm to use a specific texture slot/texture unit.

template<class texture_slot_iterator>
void glpp::core::object::shader_program_t::set_texture_array(const char* name, const texture_slot_iterator begin, const texture_slot_iterator end)

set texture sampler array to use specific texture units

Parameters
name [in] name of texture in the shader code
begin [in] begin of the texture slot range
end [in] end of the texture slot range

This function will set a texture sampler array in the shader programm to use specific texture slots/texture units.

template<class texture_slot_iterator>
void glpp::core::object::shader_program_t::set_texture_array(GLint location, const texture_slot_iterator begin, const texture_slot_iterator end)

set texture sampler array to use specific texture units

Parameters
location [in] location of the texture in the shader program
begin [in] begin of the texture slot range
end [in] end of the texture slot range

This function will set a texture sampler array in the shader programm to use specific texture slots/texture units.

template<class Value>
void glpp::core::object::shader_program_t::set_uniform(const char* name, const Value& value)

set uniform

Parameters
name [in] name of the uniform to be set
value [in] value that shall be set to the uniform

Sets the value of a uniform. The uniform is identified by name. The type of value can be a scalar-, vector- or matrix type from the glm library.

template<class Value>
void glpp::core::object::shader_program_t::set_uniform(GLint location, const Value& value)

set uniform

Parameters
location [in] location of the uniform to be set
value [in] value that shall be set to the uniform

Sets the value of a uniform. The uniform is identified by location. The type of value can be a scalar-, vector- or matrix type from the glm library.

template<class Value>
void glpp::core::object::shader_program_t::set_uniform_array(const char* name, const Value* begin, const size_t size)

set uniform array

Parameters
name [in] name of the uniform to be set
begin [in] begin of the value range
size [in] number of elements of value range

Sets the value of a uniform array. The uniform array is identified by name. The value_type of the provided range can be a scalar-, vector- or matrix type from the glm library. The range may or may not be contiguously in memory, but a non contiguous range will require an additonal allocation and copy of the values.

template<class Value>
void glpp::core::object::shader_program_t::set_uniform_array(GLint location, const Value* begin, const size_t size)

set uniform array

Parameters
location [in] location of the uniform to be set
begin [in] begin of the value range
size [in] number of elements of value range

Sets the value of a uniform array. The uniform array is identified by location. The value_type of the provided range can be a scalar-, vector- or matrix type from the glm library. The range may or may not be contiguously in memory, but a non contiguous range will require an additonal allocation and copy of the values.

GLint glpp::core::object::shader_program_t::uniform_location(const GLchar* name) const

get uniform location of a uniform inside the shader program

Parameters
name [in] name of the uniform
Returns uniform location

This member will return the location of a named uniform. This function requires a shader_program_t with attatched and linked shaders.

void glpp::core::object::shader_program_t::use() const

Make shader program active.

Bind this shader program to the global OpenGL state-machine state. Following draw calls will use the shaders and uniforms linked to this shader_program_t object.