zMol
A viewer for molecular data using OpenGL and ambient occlusion
|
#include <glsl.hpp>
Inherits zmol::noncopyable_::noncopyable.
Public Member Functions | |
program () | |
~program () | |
GLuint | get_name () const |
void | attach_shader (shader::sharedptr const &p_shader) |
void | detach_shader (shader::sharedptr const &p_shader) |
bool | link () |
void | bind () |
void | unbind () |
GLint | get_attribute_location (std::string const &p_attribute_name) const |
GLint | get_uniform_location (std::string const &p_uniform_name) const |
GLuint | get_uniform_block_index (std::string const &p_block_name) const |
std::string | get_info_log () const |
Program object wrapper class.
The class creates a program object in the constructor, and destroys it in the destructor. This makes proper use of the C++ RAII idiom, and ensures exception safety (-> no resource leak).
Ownership of shader instances can be transferred to program instances. This is useful to make sure that shaders are cleaned up when no programs that need them are around. The attach_shader() call adds a shader's sharedptr to an internal list, the detach_shader() call removes a shader's sharedptr from that list.
zmol::program::program | ( | ) |
Constructor. Creates a program object using glCreateProgram().
zmol::program::~program | ( | ) |
Destructor. Destroys a program object using glDeleteProgram().
void zmol::program::attach_shader | ( | shader::sharedptr const & | p_shader | ) |
Attaches a shader to this program object. Since the shader may be shared by several programs, a shared_ptr is used to keep track of the shader ownership. (This is also why shader instances must always be allocated on the heap, and not on the stack.)
p_shader | Shader to attach to this program |
void zmol::program::bind | ( | ) |
Binds the program object to the OpenGL context, using glUseProgram().
void zmol::program::detach_shader | ( | shader::sharedptr const & | p_shader | ) |
Detaches a shader to this program object. Since the shader may be shared by several programs, a shared_ptr is used to keep track of the shader ownership. (This is also why shader instances must always be allocated on the heap, and not on the stack.)
p_shader | Shader to detach from this program |
GLint zmol::program::get_attribute_location | ( | std::string const & | p_attribute_name | ) | const |
Returns the index of the attribute with the given name.
p_attribute_name | Name of the attribute. |
std::string zmol::program::get_info_log | ( | ) | const |
Returns information about linking errors.
|
inline |
Returns the OpenGL name of the program object.
GLuint zmol::program::get_uniform_block_index | ( | std::string const & | p_block_name | ) | const |
Returns the index of the active uniform block with the given name.
p_block_name | Name of the active uniform block. |
GLint zmol::program::get_uniform_location | ( | std::string const & | p_uniform_name | ) | const |
Returns the location of the uniform with the given name.
p_uniform_name | Name of the uniform. |
bool zmol::program::link | ( | ) |
Link the program, using the attached shaders. If something goes wrong during linking, false is returned, and get_info_log() can be used to get details.
void zmol::program::unbind | ( | ) |
Unbinds the program object from the OpenGL context, using glUseProgram().