Molecule Viewer
 All Classes Functions Variables Enumerations Pages
Shader.hpp
1 #ifndef _SHADER_HPP_
2 #define _SHADER_HPP_
3 
4 #include "common.hpp"
5 #include <QtDebug>
6 
7 
9 
14 class Shader {
15 
16  public:
17 
19  enum Coordinates {
20  Position = 1,
21  Radius = 2,
22  Color = 3,
23  UVQuad = 4
24  };
25 
27  enum Uniforms {
28  ProjectionMatrix = 5,
29  ModelViewMatrix = 6,
30  OcclusionTexture = 8,
31  LightPosition = 9,
32  OcclusionDirections = 10,
33  ShadowTex = 11,
34  ShadowMVMatrix = 12,
35  ShadowPMatrix = 13,
36  ContourData = 14,
37  ShadowActive = 15,
38  OcclusionActive = 16,
39  AmbientIntensity = 17,
40  DirectIntensity = 18,
41  Glossiness = 19,
42  FarPlane = 20
43  };
44 
46 
47  Shader(const string &path);
48 
50  ~Shader();
51 
53  GLuint GetAddress(int address);
54 
56  void bind() const {
57  glUseProgram(_program);
58  }
59 
61  void unbind() const {
62  glUseProgram(0);
63  }
64 
66  GLint get_attrib_location(const std::string &name) const {
67  return glGetAttribLocation(_program, name.c_str());
68  }
69 
71  GLint get_uniform_location(const std::string &name) const {
72  return glGetUniformLocation(_program, name.c_str());
73  }
74 
76  void bind_frag_data_location(const std::string &name) {
77  if(_program > 0)
78  {
79  glBindFragDataLocation(_program, 0, name.c_str() );
80  link();
81  }
82  }
83 
85 
86  operator bool () {
87  return _success;
88  }
89 
90  private:
91 
92  bool _success;
93  GLuint _vertex_shader;
94  GLuint _fragment_shader;
95  GLuint _shadow_shader;
96  GLuint _geometry_shader;
97  GLuint _program;
98 
99  std::map<int, GLuint> _shaderAddresses;
100 
101  GLuint compile(GLenum type, const string &source);
102  void link (void);
103  void shader_log(GLuint shader);
104  void program_log(GLuint program);
105  void GenerateAddresses(void);
106 };
107 
108 #endif //#ifndef _SHADER_HPP_
109