Vis 2
Kinetic Visualization for 3D shape and structure
 All Classes Namespaces Functions Pages
Shader.h
1 //Author: Christian Hafner
2 #pragma once
3 
4 #include "include_opengl.h"
5 #include <regex>
6 #include <string>
7 #include <unordered_map>
8 
14 {
15 public:
16  ShaderTypeIDs();
17 
18  unsigned get(GLenum shaderType);
19 
20 private:
21  std::unordered_map<GLenum, unsigned> _shaderTypes;
22 };
23 
24 class Shader
25 {
26 public:
27  Shader();
31  Shader(const std::string& name);
32  ~Shader();
33 
37  bool attachShaderSource(int type, const std::string& source);
42  bool attachShaderFile(int type, const std::string& path);
43 
47  bool compileShaders();
48 
55  void setTransformFeedbackVaryings(int numVaryings, const GLchar** varyings, GLenum mode);
56 
60  bool link();
64  bool link(const std::string& out);
70  bool link(int numLocations, const std::string* out);
71 
75  void bind() const;
79  void unbind() const;
80 
84  GLint getUniformLocation(const std::string& name) const;
85 
91  GLint getSubroutineUniformLocation(GLenum shaderType, const std::string& name);
92 
98  GLuint getSubroutineIndex(GLenum shaderType, const std::string& name);
99 
103  GLint getAttribLocation(const std::string& name) const;
104 
105  void preprocess(unsigned numKeys, const std::regex* keys, const std::string* values);
106 
107  const std::string& getName() const;
108 
109  GLuint getProgram() const;
110 
111 private:
112  std::string _name;
113  GLuint _programHandle;
114  GLuint _shaderHandles[8];
115  bool _compiled, _linked;
116 
117  int _numVaryings;
118  const GLchar** _varyings;
119  GLenum _bufferMode;
120 
121  std::string _source[8];
122  std::string _sourceFolder[8];
123 
124  void processIncludes(std::string& source, const std::string& folder);
125 
126  std::string getShaderTypeString(GLint type);
127 
128  ShaderTypeIDs _shaderTypeIDs;
129 
130  static GLenum SHADER_TYPES[8];
131 };
bool compileShaders()
Definition: Shader.cpp:118
bool attachShaderSource(int type, const std::string &source)
Definition: Shader.cpp:48
GLint getSubroutineUniformLocation(GLenum shaderType, const std::string &name)
Definition: Shader.cpp:246
bool attachShaderFile(int type, const std::string &path)
Definition: Shader.cpp:60
Definition: Shader.h:13
void bind() const
Definition: Shader.cpp:232
bool link()
Definition: Shader.cpp:172
GLuint getSubroutineIndex(GLenum shaderType, const std::string &name)
Definition: Shader.cpp:251
void unbind() const
Definition: Shader.cpp:236
Definition: Shader.h:24
GLint getUniformLocation(const std::string &name) const
Definition: Shader.cpp:241
void setTransformFeedbackVaryings(int numVaryings, const GLchar **varyings, GLenum mode)
Definition: Shader.cpp:156
GLint getAttribLocation(const std::string &name) const
Definition: Shader.cpp:256