Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
technique.h
Go to the documentation of this file.
1 #ifndef __TECHNIQUE_H__INCLUDED__
2 #define __TECHNIQUE_H__INCLUDED__
3 
4 #include <string>
5 #include <vector>
6 
7 #include <boost/smart_ptr.hpp>
8 
9 class Texture;
10 class Technique;
11 
12 typedef boost::shared_ptr< Technique >TechniquePtr;
13 
14 class Technique
15 {
16  std::string name;
17  std::string fallback;
18  bool compiled;
19  int programVersion;
20 
21 public:
22  class Pass
23  {
25  int program;
26 
28  int programVersion;
29 
31  std::string vertexProgram;
32 
34  std::string fragmentProgram;
35 
36 public:
37  enum Tristate
38  {
39  False=0,
40  True =1,
41  Auto =2
42  };
43 
44  enum Type
45  {
55 
60  };
61 
62  enum BlendMode
63  {
66 
68  Add,
69 
72 
75 
78 
81 
84  };
85 
87  {
95  };
96 
97  enum Face
98  {
104  };
105 
106  enum PolyMode
107  {
111  };
112 
113  struct TextureUnit
114  {
116  {
119 
122 
125 
128 
131  };
132 
133  enum Kind
134  {
137 
140 
143 
146 
149  };
150 
153 
155 
159 
160  // Backup of mutable fields for shader reloading
162 
164  std::string targetParamName;
166 
167  std::string sourcePath;
168  std::string defaultPath;
169 
171  boost::shared_ptr< Texture >texture;
172  };
173 
174  struct ShaderParam
175  {
176  enum Semantic
177  {
184 
193 
196 
199 
202 
205 
208 
211 
214 
217 
231  };
232 
233  std::string name;
234  int id;
236  bool optional;
237  float value[4];
238  };
239 
240 private:
241  typedef std::vector< TextureUnit >TextureUnitList;
242  typedef std::vector< ShaderParam >ShaderParamList;
243 
244  TextureUnitList textureUnits;
245  ShaderParamList shaderParams;
246 
247 public:
250 
255  bool sRGBAware;
256 
259 
262 
264  unsigned int perLightIteration;
265 
267  unsigned int maxIterations;
268 
271 
274 
277 
280 
283 
285  float offsetUnits;
286 
288  float lineWidth;
289 
291  int sequence;
292 
293  Pass();
294 
295  ~Pass();
296 
298  void setProgram( const std::string &vertex, const std::string &fragment );
299 
301  int getCompiledProgram() const
302  {
303  return program;
304  }
305 
317  void addTextureUnit( const std::string &source,
318  int target,
319  const std::string &deflt,
320  const std::string &paramName,
322 
330  void addShaderParam( const std::string&name, float value[4], bool optional );
331 
337  void addShaderParam( const std::string &name, ShaderParam::Semantic semantic, bool optional );
338 
340  size_t getNumTextureUnits() const
341  {
342  return textureUnits.size();
343  }
344 
346  const TextureUnit& getTextureUnit( int index ) const
347  {
348  return textureUnits[index];
349  }
350 
353  {
354  return textureUnits[index];
355  }
356 
358  size_t getNumShaderParams() const
359  {
360  return shaderParams.size();
361  }
362 
364  const ShaderParam& getShaderParam( int index ) const
365  {
366  return shaderParams[index];
367  }
368 
371  {
372  return shaderParams[index];
373  }
374 
376  void compile();
377 
379  bool isCompiled() const;
380 
382  bool isCompiled(int programVersion) const;
383  };
384 
385 protected:
386  typedef std::vector< Pass > PassList;
388 
389 public:
391  explicit Technique( const std::string &name );
392 
394  explicit Technique( const Technique &src );
395 
396  ~Technique();
397 
398  const std::string& getName() const
399  {
400  return name;
401  }
402  const std::string& getFallback() const
403  {
404  return fallback;
405  }
406 
408  bool isCompiled() const
409  {
410  return compiled;
411  }
412 
414  bool isCompiled(int programVersion) const
415  {
416  return compiled && this->programVersion == programVersion;
417  }
418 
419  void compile(); //Throws on error
420 
421  int getNumPasses() const
422  {
423  return passes.size();
424  }
425  const Pass& getPass( int idx ) const
426  {
427  return passes[idx];
428  }
429  Pass& getPass( int idx )
430  {
431  return passes[idx];
432  }
433 
435  static TechniquePtr getTechnique( const std::string &name );
436 };
437 
438 #endif //__TECHNIQUE_H__INCLUDED__
439