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

#include <glsl.hpp>

Inherits zmol::noncopyable_::noncopyable.

List of all members.

Public Member Functions

 shader (GLenum const p_type)
 ~shader ()
GLuint get_name () const
bool compile_and_store (std::string const &p_code)
std::string get_info_log () const

Detailed Description

Shader object wrapper class.

The class creates a shader 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. See program and build_program for details.

Note:
Always construct a shader instance on the heap, and wrap it in a shader::sharedptr instance.

Constructor & Destructor Documentation

zmol::shader::shader ( GLenum const  p_type)
explicit

Constructor. Creates a shader object using glCreateShader().

Note:
Always construct a shader instance on the heap, and wrap it in a sharedptr instance.
Parameters:
p_typeType of the shader (GL_VERTEX_SHADER/GL_FRAGMENT_SHADER/...).
zmol::shader::~shader ( )

Destructor. Destroys a shader object using glDeleteShader().


Member Function Documentation

bool zmol::shader::compile_and_store ( std::string const &  p_code)

Compiles shader code and stores it in the shader object. If any compilation errors happen, get_info_log() will return details.

Note:
Depending on the OpenGL drivers, some errors may not be caught by the compiler, but by the linker. In other words, even if compilation succeeds, check if linking succeeds as well.
Parameters:
p_codeGLSL source code to compile and store.
Returns:
true if compilation was successful, false otherwise.
std::string zmol::shader::get_info_log ( ) const

Returns information about compilation errors.

Note:
Even though this can be called anytime, it is only really useful to call it when compile_and_store() returned false. Otherwise, the log may contain confusing or nonsensical information.
Returns:
Information about what went wrong in the compilation step.
GLuint zmol::shader::get_name ( ) const
inline

Returns the OpenGL name of the shader object.