zMol
A viewer for molecular data using OpenGL and ambient occlusion
Public Member Functions
zmol::program Class Reference

#include <glsl.hpp>

Inherits zmol::noncopyable_::noncopyable.

List of all members.

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

Detailed Description

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.


Constructor & Destructor Documentation

zmol::program::program ( )

Constructor. Creates a program object using glCreateProgram().

zmol::program::~program ( )

Destructor. Destroys a program object using glDeleteProgram().


Member Function Documentation

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.)

Parameters:
p_shaderShader 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.)

Parameters:
p_shaderShader 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.

Parameters:
p_attribute_nameName of the attribute.
Returns:
Index of the attribute, or -1 if no attribute with the given name was found.
std::string zmol::program::get_info_log ( ) const

Returns information about linking errors.

Note:
Even though this can be called anytime, it is only really useful to call it when link() returned false. Otherwise, the log may contain confusing or nonsensical information.
Returns:
Information about what went wrong in the linking step.
GLuint zmol::program::get_name ( ) const
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.

Parameters:
p_block_nameName of the active uniform block.
Returns:
Index of the active uniform block, or GL_INVALID_INDEX if no block with the given name was found.
GLint zmol::program::get_uniform_location ( std::string const &  p_uniform_name) const

Returns the location of the uniform with the given name.

Parameters:
p_uniform_nameName of the uniform.
Returns:
Location of the attribute, or -1 if no uniform with the given name was found.
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.

Returns:
true if linking succeeded, false otherwise.
void zmol::program::unbind ( )

Unbinds the program object from the OpenGL context, using glUseProgram().