Tucano  0.1
A library for rapid prototyping with modern OpenGL and GLSL
effect.hpp
Go to the documentation of this file.
1 
23 #ifndef __EFFECT__
24 #define __EFFECT__
25 
26 #include <Eigen/Dense>
27 #include <vector>
28 #include <tucano/shader.hpp>
29 
30 namespace Tucano
31 {
32 
43 class Effect {
44 
45 public:
46 
51  Effect (string shadersDir = "shaders/") : shaders_dir(shadersDir)
52  {
53  #ifdef TUCANOSHADERDIR
54  setShadersDir(stringify(TUCANOSHADERDIR));
55  #endif
56  }
57 
64  virtual void initialize (void) = 0;
65 
73  virtual Shader* loadShader (string shader_name)
74  {
75  Shader* shader_ptr = new Shader(shader_name, shaders_dir);
76  shader_ptr->initialize();
77  shaders_list.push_back(shader_ptr);
78  return shader_ptr;
79  }
80 
81  virtual void loadShader (Shader& shader, string shader_name)
82  {
83  shader.load(shader_name, shaders_dir);
84  shader.initialize();
85  shaders_list.push_back(&shader);
86  }
87 
95  virtual Shader* loadShader (string shader_name, string vertex_name, string frag_name, string geom_name)
96  {
97  Shader* shader_ptr = new Shader(shader_name, vertex_name, frag_name, geom_name);
98  shader_ptr->initialize();
99  shaders_list.push_back(shader_ptr);
100  return shader_ptr;
101  }
102 
108  void setShadersDir (string dir)
109  {
110  shaders_dir = dir;
111  }
112 
118  virtual void reloadShaders (void)
119  {
120  for (unsigned int i = 0; i < shaders_list.size(); ++i)
121  {
122  shaders_list[i]->reloadShaders();
123  }
124  }
125 
126 
127 
128 protected:
129 
130 
132  std::vector< Shader* > shaders_list;
133 
135  string shaders_dir;
136 
137 };
138 }
139 #endif
string shaders_dir
Directory in which the shader files are stored.
Definition: effect.hpp:135
virtual void initialize(void)=0
Initializes all effect&#39;s funcionality.
Definition: bufferobject.hpp:34
void initialize(void)
Calls all the functions related to the shader initialization, i.e., creates, loads the shaders from t...
Definition: shader.hpp:641
std::vector< Shader * > shaders_list
Vector of pointers to shaders used in this effect, in case the user needs multiple pass rendering...
Definition: effect.hpp:132
A Shader object represents one GLSL program.
Definition: shader.hpp:45
virtual void reloadShaders(void)
Reloads all shaders needed for effect usage.
Definition: effect.hpp:118
virtual Shader * loadShader(string shader_name, string vertex_name, string frag_name, string geom_name)
Loads a shader by complete filenames (with extensions), initializes it, and inserts in shaders list...
Definition: effect.hpp:95
Effect(string shadersDir="shaders/")
Default constructor.
Definition: effect.hpp:51
virtual Shader * loadShader(string shader_name)
Loads a shader by filename, initializes it, and inserts in shaders list.
Definition: effect.hpp:73
void load(string name, string shader_dir="")
Loads a shader given a directory and a name. Searches for all shader extensions in directory...
Definition: shader.hpp:436
#define stringify(x)
Definition: misc.hpp:33
virtual void loadShader(Shader &shader, string shader_name)
Definition: effect.hpp:81
void setShadersDir(string dir)
Definition: effect.hpp:108
The Effect class is a holder for Shaders. It is completely optional, but is contains a few methods fo...
Definition: effect.hpp:43