|
| ShaderProgram (const std::string &name="unknown") |
|
void | set_name (const std::string &name) |
|
const std::string & | name () const |
|
void | set_verbose (bool v) |
| Sets true to log any issues found.
|
|
unsigned int | get_program () const |
| Returns the program index.
|
|
void | clear () |
| Removes (deletes) all shaders.
|
|
bool | load_shader_from_file (ShaderType st, const std::string &file_name, const std::string &inc_id="#include") |
|
bool | load_shader_from_code (ShaderType st, const std::string &code) |
|
void | set_attrib_name (ShaderProgram::AttribType at, const std::string &name) const |
|
void | set_attrib_names (const std::vector< ShaderProgram::Attribute > &attributes) const |
|
bool | link_program () |
|
void | set_program_output (int index, const std::string &name) const |
|
int | program_output (const std::string &name) const |
|
void | bind () const |
| Starts using the program.
|
|
ShaderProgram * | set_uniform (const std::string &name, const void *value) |
|
ShaderProgram * | set_uniform (const std::string &name, int value) |
|
ShaderProgram * | set_uniform (const std::string &name, unsigned int value) |
|
ShaderProgram * | set_uniform (const std::string &name, float value) |
|
ShaderProgram * | set_block (const std::string &name, const void *value) |
|
ShaderProgram * | set_block_uniform (const std::string &blockName, const std::string &uniformName, const void *value) |
|
ShaderProgram * | set_block_uniform_array_element (const std::string &blockName, const std::string &uniformName, int arrayIndex, const void *value) |
|
ShaderProgram * | bind_texture (const std::string &name, unsigned int tex_id, int unit, unsigned int tex_target=0x0DE1) |
|
ShaderProgram * | release_texture (unsigned int tex_target=0x0DE1) |
|
void | release () const |
| Ends using the program.
|
|
int | get_attribute_location (const std::string &name) const |
|
bool | is_uniform_used (const std::string &name) |
|
bool | is_attribute_used (const std::string &name) |
|
bool | is_program_valid () const |
|
bool | is_program_linked () const |
| Returns true if program linked, false otherwise.
|
|
bool | is_bound () const |
| Returns true if the program is being used (i.e., between bind() and release()).
|
|
bool | shader_info_log (std::string &log, unsigned int shader) const |
| returns a string with a shader's infolog
|
|
bool | program_info_log (std::string &log) const |
| returns a string with the program's infolog
|
|
void | print_active_attributes () |
|
void | print_active_uniforms () |
|
void | print_active_uniform_blocks () |
|
bool | load_binary (const std::string &file_name) |
|
bool | save_binary (const std::string &file_name) |
|
OpenGL Shader Compilation.
To use the shader program class, you need to do the following:
- Call load_shader_from_code(ShaderProgram::VERTEX, vert_file) to create vertex shader and load_shader_from_code(ShaderProgram::FRAGMENT, frag_file) to create fragment shader (you may also need to create other types of shaders depending on your needs).
- Call set_attrib_name(ShaderProgram::POSITION, "position") for vertex attribute "position". You may also need to set other attributes like normal, color, etc. To know what vertex attributes need to be set, check your shader code or call print_active_attributes().
- Call link_program() to link the program.
For rendering
To retrieve the model view projection matrix, call camera's modelViewProjectionMatrix()
- Examples
- Tutorial_207_RealCamera, Tutorial_501_AmbientOcclusion, Tutorial_505_EyeDomeLighting, and Tutorial_506_DepthMaps.