cgv
cgv::render::shader_program Class Reference

#include <shader_program.h>

Inheritance diagram for cgv::render::shader_program:
cgv::render::shader_program_base cgv::render::render_component

Public Member Functions

 shader_program (bool _show_code_errors=false)
 create empty shader program More...
 
 ~shader_program ()
 call destruct method
 
bool create (const context &ctx)
 create the shader program
 
void destruct (const context &ctx)
 destruct shader program
 
bool attach_code (const context &ctx, const shader_code &code)
 attach a compiled shader code instance that is managed outside of program
 
bool detach_code (const context &ctx, const shader_code &code)
 detach a shader code
 
bool attach_code (const context &ctx, const std::string &source, ShaderType st)
 attach a shader code given as string and managed the created shader code object
 
bool attach_file (const context &ctx, const std::string &file_name, ShaderType st=ST_DETECT, std::string defines="")
 read shader code from file, compile and attach to program
 
bool attach_files (const context &ctx, const std::string &base_name, std::string defines="")
 read shader code from files with the given base name, compile and attach them
 
bool attach_dir (const context &ctx, const std::string &dir_name, bool recursive)
 collect shader code files from directory, compile and attach.
 
bool attach_program (const context &ctx, const std::string &file_name, bool show_error=false, std::string defines="")
 collect shader code files declared in shader program file, compile and attach them
 
bool link (const context &ctx, bool show_error=false)
 link shaders to an executable program
 
bool is_linked () const
 return whether program is linked
 
bool build_files (const context &ctx, const std::string &base_name, bool show_error=false)
 successively calls create, attach_files and link.
 
bool build_dir (const context &ctx, const std::string &dir_name, bool recursive=false, bool show_error=false)
 successively calls create, attach_dir and link.
 
bool build_program (const context &ctx, const std::string &file_name, bool show_error=false, std::string defines="")
 successively calls create, attach_program and link.
 
void set_geometry_shader_info (PrimitiveType input_type, PrimitiveType output_type, int max_output_count=0)
 configure the geometry shader, if count < 1 set it to get_max_nr_geometry_shader_output_vertices More...
 
bool enable (context &ctx)
 enable the shader program
 
bool disable (context &ctx)
 disable shader program and restore fixed functionality
 
bool is_enabled () const
 check whether program is currently enabled
 
int get_uniform_location (const context &ctx, const std::string &name) const
 query location index of an uniform
 
bool set_material_uniform (const context &ctx, const std::string &name, const cgv::media::illum::surface_material &material, bool generate_error=false)
 set a uniform of type material
 
bool set_textured_material_uniform (const context &ctx, const std::string &name, const textured_material &material, bool generate_error=false)
 set a uniform of type textured_material
 
bool set_light_uniform (const context &ctx, const std::string &name, const cgv::media::illum::light_source &light, bool generate_error=false)
 set a uniform of type light source
 
template<typename T >
bool set_uniform (const context &ctx, const std::string &name, const T &value, bool generate_error=false)
 
template<typename T >
bool set_uniform_array (const context &ctx, const std::string &name, const T &array)
 set uniform array from array array where number elements can be derived from array through array_descriptor_traits; supported array types include cgv::math::vec and std::vector
 
template<typename T >
bool set_uniform_array (const context &ctx, const std::string &name, const T *array, size_t nr_elements, bool generate_error=false)
 set uniform array from an array with nr_elements elements of type T pointed to by array
 
template<typename T >
bool set_uniform (const context &ctx, int loc, const T &value)
 
template<typename T >
bool set_uniform_array (const context &ctx, int loc, const T &array)
 set uniform array from array array where number elements can be derived from array through array_descriptor_traits; supported array types include cgv::math::vec and std::vector
 
template<typename T >
bool set_uniform_array (const context &ctx, int loc, const T *array, size_t nr_elements)
 set uniform array from an array with nr_elements elements of type T pointed to by array
 
int get_attribute_location (const context &ctx, const std::string &name) const
 query location index of an attribute
 
template<typename T >
bool set_attribute (const context &ctx, const std::string &name, const T &value)
 set constant default value of a vertex attribute by attribute name, if name does not specify an attribute, an error message is generated
 
template<typename T >
bool set_attribute (const context &ctx, int loc, const T &value)
 set constant default value of a vertex attribute by location index
 
virtual bool is_created () const
 return whether component has been created
 
void put_id_void (void *ptr) const
 
template<typename T >
void put_id (T &id) const
 cast the refence to rendering api specific representation of component id to the specified type
 

Static Public Member Functions

static bool collect_file (const std::string &file_name, std::vector< std::string > &file_names)
 resolve file name with shader_code::find_file and add file to list if found
 
static bool collect_files (const std::string &base_name, std::vector< std::string > &file_names)
 
static bool collect_dir (const std::string &dir_name, bool recursive, std::vector< std::string > &file_names)
 
static bool collect_program (const std::string &file_name, std::vector< std::string > &file_names)
 
static unsigned int get_max_nr_geometry_shader_output_vertices (const context &ctx)
 return the maximum number of output vertices of a geometry shader
 

Public Attributes

const contextctx_ptr
 keep pointer to my context
 
std::string last_error
 a string that contains the last error
 

Protected Member Functions

bool attach_files (const context &ctx, const std::vector< std::string > &file_names, std::string defines="")
 attach a list of files
 
void update_state (const context &ctx)
 ensure that the state has been set in the context
 

Detailed Description

a shader program combines several shader code fragments to a complete definition of the shading pipeline.

Constructor & Destructor Documentation

◆ shader_program()

cgv::render::shader_program::shader_program ( bool  _show_code_errors = false)

create empty shader program

create empty shader program and set the option whether errors during shader code attachment should be printed to std::cerr

Member Function Documentation

◆ collect_dir()

bool cgv::render::shader_program::collect_dir ( const std::string &  dir_name,
bool  recursive,
std::vector< std::string > &  file_names 
)
static

collect shader code files from directory. If the directory does not exist search it in the shader path of the shader configuration returned by get_shader_config(). Returns true if at least one shader code file has been collected.

◆ collect_files()

bool cgv::render::shader_program::collect_files ( const std::string &  base_name,
std::vector< std::string > &  file_names 
)
static

collect shader code files that extent the given base name. Returns true if at least one shader code file has been collected.

◆ collect_program()

bool cgv::render::shader_program::collect_program ( const std::string &  file_name,
std::vector< std::string > &  file_names 
)
static

collect shader code files declared in a shader program file. Program files have the extension glpr and contain lines of the form command:argument. The following commands can be used

  • file:file_name ... calls attach_file(ctx,file_name)
  • vertex_file:file_name ... calls attach_file(ctx,file_name,ST_VERTEX)
  • geometry_file:file_name ... calls attach_file(ctx,file_name,ST_GEOMETRY)
  • fragment_file:file_name ... calls attach_file(ctx,file_name,ST_FRAGMENT)
  • files:base_name ... calls attach_files(ctx,base_name)
  • dir:dir_name ... calls attach_dir(ctx,dir_name,false)
  • rec_dir:dir_name ... calls attach_dir(ctx,dir_name,true)
  • program:file_name ... calls attach_program(file_name) recursively take care, not to generate cyclic includes.
  • geometry_shader_info:input_type;output_type;max_output_count ... calls set_geometry_shader_info with input_type, output_type and max_output_count as arguments, where the primitive types are one out of points,lines,lines_adjacency,line_strip,line_strip_adjacency,line_loop, triangles,triangles_adjacency,triangle_strip,triangle_strip_adjacency,triangle_fan, quads,quad_strip,polygon. Returns true if at least one shader code file has been collected.

◆ put_id_void()

void cgv::render::render_component::put_id_void ( void *  ptr) const
inherited

copy the rendering api specific id the component to the memory location of the given pointer. For opengl this the passed pointer should be of type GLint or GLuint.

◆ set_geometry_shader_info()

void cgv::render::shader_program::set_geometry_shader_info ( PrimitiveType  input_type,
PrimitiveType  output_type,
int  max_output_count = 0 
)

configure the geometry shader, if count < 1 set it to get_max_nr_geometry_shader_output_vertices

configure the geometry shader

◆ set_uniform() [1/2]

template<typename T >
bool cgv::render::shader_program::set_uniform ( const context ctx,
const std::string &  name,
const T &  value,
bool  generate_error = false 
)
inline

Set the value of a uniform by name, where the type can be any of int, unsigned, float, vec<int>, vec<unsigned>, vec<float>, mat<float> and the vectors are of dimension 2, 3 or 4 and the matrices of dimensions 2, 3 or 4.

◆ set_uniform() [2/2]

template<typename T >
bool cgv::render::shader_program::set_uniform ( const context ctx,
int  loc,
const T &  value 
)
inline

Set the value of a uniform by name, where the type can be any of int, unsigned, float, vec<int>, vec<unsigned>, vec<float>, mat<float> and the vectors are of dimension 2, 3 or 4 and the matrices of dimensions 2, 3 or 4.


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