renderstack::program Class Reference

wrapper for gl program

#include <program.hpp>

Public Member Functions

 program ()
 program (std::string const &vertex_shader, std::string const &fragment_shader, enum mesh_mode mode)
void create ()
void set (std::string const &vertex_shader, std::string const &fragment_shader, enum mesh_mode mode)
void link ()
int gl_program_object () const
void set_mesh_mode (enum mesh_mode mode)
enum mesh_mode mesh_mode () const
void use () const
bool has_uniform (std::string const &name) const
bool has_attribute (std::string const &name) const
class uniformuniform (std::string const &name)
class uniform const & uniform (std::string const &name) const
class program_attributeattribute (std::string const &name)
class program_attribute const & attribute (std::string const &name) const
void make_shader (int shader_type, std::string const &source)
class attribute_mappingsattribute_mappings ()
class attribute_mappings const & attribute_mappings () const

Data Fields

std::vector< class
program_attribute
m_attributes
std::vector< class uniformm_uniforms
std::vector< class shaderm_shaders
int m_gl_program_object
enum mesh_mode m_mesh_mode
class attribute_mappings m_attribute_mappings

Detailed Description

Definition at line 126 of file program.hpp.


Constructor & Destructor Documentation

renderstack::program::program (  ) 

Definition at line 115 of file program.cpp.

00116 :   m_mesh_mode(mesh_mode_polygon_fill)
00117 ,   m_gl_program_object((int)(~0))
00118 {
00119     m_gl_program_object = (int)(~0);
00120 }

renderstack::program::program ( std::string const &  vertex_shader,
std::string const &  fragment_shader,
enum mesh_mode  mode 
)

Definition at line 122 of file program.cpp.

00127 :   m_mesh_mode(mode)
00128 ,   m_gl_program_object((int)(~0))
00129 {
00130     create();
00131     make_shader(GL_VERTEX_SHADER,    vertex_shader_source);
00132     make_shader(GL_FRAGMENT_SHADER,  fragment_shader_source);
00133     link();
00134 }


Member Function Documentation

void renderstack::program::create (  ) 

Definition at line 149 of file program.cpp.

00150 {
00151     ::GLboolean is_program = ::rs_gl_is_program(m_gl_program_object);
00152     if(is_program != GL_FALSE)
00153     {
00154         ::rs_gl_delete_program(m_gl_program_object);
00155     }
00156     m_gl_program_object = ::rs_gl_create_program();
00157 }

void renderstack::program::set ( std::string const &  vertex_shader,
std::string const &  fragment_shader,
enum mesh_mode  mode 
)

Definition at line 136 of file program.cpp.

00141 {
00142     m_mesh_mode = mode;
00143     create();
00144     make_shader(GL_VERTEX_SHADER,    vertex_shader);
00145     make_shader(GL_FRAGMENT_SHADER,  fragment_shader);
00146     link();
00147 }

void renderstack::program::link (  ) 

Definition at line 159 of file program.cpp.

00160 {
00161     int link_status;
00162     ::rs_gl_link_program  (m_gl_program_object);
00163     ::rs_gl_get_program_iv(m_gl_program_object, GL_LINK_STATUS, &link_status);
00164 
00165     if(link_status == GL_FALSE)
00166     {
00167         char      info_log[4096];
00168         ::GLsizei length = 0;
00169 
00170         ::memset(&info_log[0], 0, 4096);
00171 
00172         ::rs_gl_get_program_info_log(m_gl_program_object, 4096, &length, &info_log[0]);
00173         ::rs_gl_delete_program(m_gl_program_object);
00174 
00175         ::rs_log("program linking failed:\n%s", info_log);
00176     }
00177     ::rs_gl_use_program(m_gl_program_object);
00178     map_attributes();
00179     map_uniforms();
00180 }

int renderstack::program::gl_program_object (  )  const [inline]

Definition at line 135 of file program.hpp.

00135 { return m_gl_program_object; }

void renderstack::program::set_mesh_mode ( enum mesh_mode  mode  )  [inline]

Definition at line 137 of file program.hpp.

00137 { m_mesh_mode = mode; }

enum mesh_mode renderstack::program::mesh_mode (  )  const [inline]

Definition at line 138 of file program.hpp.

00138 { return m_mesh_mode; }

void renderstack::program::use (  )  const

Definition at line 245 of file program.cpp.

bool renderstack::program::has_uniform ( std::string const &  name  )  const

Definition at line 310 of file program.cpp.

00311 {
00312     for(
00313         std::vector<class uniform>::const_iterator i = m_uniforms.begin(); 
00314         i != m_uniforms.end();
00315         ++i
00316     )
00317     {
00318         class uniform const& uniform = *i;
00319         int diff = uniform.name().compare(name);
00320 
00321         if(diff == 0)
00322         {
00323             return true;
00324         }
00325     }
00326 
00327     return false;
00328 }

bool renderstack::program::has_attribute ( std::string const &  name  )  const

Definition at line 250 of file program.cpp.

00251 {
00252     for(
00253         std::vector<program_attribute>::const_iterator i = m_attributes.begin(); 
00254         i != m_attributes.end();
00255         ++i
00256     )
00257     {
00258         program_attribute const &attribute = *i;
00259         int diff = attribute.name().compare(name);
00260 
00261         if(diff == 0)
00262         {
00263             return true;
00264         }
00265     }
00266 
00267     return false;
00268 }

uniform & renderstack::program::uniform ( std::string const &  name  ) 

Definition at line 350 of file program.cpp.

00351 {
00352     for(
00353         std::vector<class uniform>::iterator i = m_uniforms.begin(); 
00354         i != m_uniforms.end();
00355         ++i
00356     )
00357     {
00358         class uniform &uniform = *i;
00359         int diff = uniform.name().compare(name);
00360 
00361         if(diff == 0)
00362         {
00363             return uniform;
00364         }
00365     }
00366 
00367     throw uniform_not_found_exception();
00368 }

uniform const & renderstack::program::uniform ( std::string const &  name  )  const

Definition at line 330 of file program.cpp.

00331 {
00332     for(
00333         std::vector<class uniform>::const_iterator i = m_uniforms.begin(); 
00334         i != m_uniforms.end();
00335         ++i
00336     )
00337     {
00338         class uniform const &uniform = *i;
00339         int diff = uniform.name().compare(name);
00340 
00341         if(diff == 0)
00342         {
00343             return uniform;
00344         }
00345     }
00346 
00347     throw uniform_not_found_exception();
00348 }

program_attribute & renderstack::program::attribute ( std::string const &  name  ) 

Definition at line 290 of file program.cpp.

00291 {
00292     for(
00293         std::vector<program_attribute>::iterator i = m_attributes.begin(); 
00294         i != m_attributes.end();
00295         ++i
00296     )
00297     {
00298         program_attribute &attribute = *i;
00299         int diff = attribute.name().compare(name);
00300 
00301         if(diff == 0)
00302         {
00303             return attribute;
00304         }
00305     }
00306 
00307     throw program_attribute_not_found_exception();
00308 }

program_attribute const & renderstack::program::attribute ( std::string const &  name  )  const

Definition at line 270 of file program.cpp.

00271 {
00272     for(
00273         std::vector<program_attribute>::const_iterator i = m_attributes.begin(); 
00274         i != m_attributes.end();
00275         ++i
00276     )
00277     {
00278         program_attribute const &attribute = *i;
00279         int diff = attribute.name().compare(name);
00280 
00281         if(diff == 0)
00282         {
00283             return attribute;
00284         }
00285     }
00286 
00287     throw program_attribute_not_found_exception();
00288 }

void renderstack::program::make_shader ( int  shader_type,
std::string const &  source 
)

Definition at line 103 of file program.cpp.

00107 {
00108     class shader shader(shader_type, source);
00109     ::rs_gl_attach_shader(m_gl_program_object, shader.gl_shader_object());
00110 
00111     /*  calls copy constructor  */ 
00112     m_shaders.push_back(shader);
00113 }

class attribute_mappings& renderstack::program::attribute_mappings (  )  [inline]

Definition at line 148 of file program.hpp.

00148 { return m_attribute_mappings; }

class attribute_mappings const& renderstack::program::attribute_mappings (  )  const [inline]

Definition at line 149 of file program.hpp.

00149 { return m_attribute_mappings; }


Field Documentation

Definition at line 156 of file program.hpp.

Definition at line 157 of file program.hpp.

Definition at line 158 of file program.hpp.

Definition at line 160 of file program.hpp.

Definition at line 161 of file program.hpp.

Definition at line 163 of file program.hpp.


The documentation for this class was generated from the following files:
Generated on Sun Apr 11 12:23:12 2010 for RenderStack by  doxygen 1.6.3