GlobeEngine
Shader.h
Go to the documentation of this file.
1 
9 #ifndef GlobeEngine_Shader_h
10 #define GlobeEngine_Shader_h
11 
12 #include "OpenGL_Includes.h"
13 #include "ShaderProgram.h"
14 #include "ShaderParser.h"
15 #include <fstream>
16 #include <vmmlib/vmmlib.hpp>
17 #include <iostream>
18 #include <string>
19 #include <map>
20 #include <memory>
21 #include <vector>
22 
23 namespace ge {
24 
25  class Shader
26  {
27  public:
29 
30  Shader();
31  ~Shader();
32  // deep copy
33  Shader(const std::shared_ptr<Shader> copy) {
34  this->handle = copy->handle;
35  this->vertexArrayAttributeCount = copy->vertexArrayAttributeCount;
36  this->repoPath = copy->repoPath;
37  this->globalSourcePath = copy->globalSourcePath;
38  this->shadertype = copy->shadertype;
39  this->programs = copy->programs;
40  this->vertexArrayAttributeLocations = copy->vertexArrayAttributeLocations;
41  }
42 
43  void clear();
44  void load(std::string _inputPath, ge::Shader::ShaderType _type, std::string _genericShaderPath="");
45  void load(std::string _repopath, std::string _relPath, ge::Shader::ShaderType _type, std::string _genericShaderPath = "");
46  void loadFromSourceVertFrag(std::string _vertSource, std::string _fragSource);
47  //void loadWithDefine(std::string _inputPath, ge::Shader::ShaderType _type, int _defineValue);
48  GLuint getVertexArrayAttributeCount() const;
49 
50  GLuint getHandle();
51 
55  void recompile(ShaderProgram::ReloadType _type = ShaderProgram::ReloadType::FROMFILE);
56 
57  void bind() const;
58  void unbind() const;
59 
60 #ifndef GENGINE_GL_BELOW_410
61 
66  void dispatchCompute(GLuint _numGroupsX, GLuint _numGroupsY, GLuint _numGroupsZ) const;
67 
71  void dispatchCompute(vmml::Vector3ui _numGroups) const;
72  static void printComputeCapabilities();
73 #endif
74 
75  /* uniform calls */
76 #if defined GENGINE_GL_ES
77 #else
78  void setUniform1d(std::string _name, double _value) const;
79  void setUniformVector2d(std::string _name, vmml::Vector2d _value) const;
80  void setUniformVector3d(std::string _name, vmml::Vector3d _value) const;
81  void setUniformVector4d(std::string _name, vmml::Vector4d _value) const;
82  void setUniformMatrix3d(std::string _name, vmml::Matrix3d _value, bool _transpose=false) const;
83  void setUniformMatrix4d(std::string _name, vmml::Matrix4d _value, bool _transpose = false) const;
84  void setUniformBlockBinding(std::string _ublockName, GLuint _ublockBinding);
85  void setUniformBlockBinding(GLuint _ublockIdx, GLuint _ublockBinding);
86  GLuint getUniformBlockIndex(std::string _input);
87 #endif
88  void setUniform1i(std::string _name, int _value)const;
89  void setUniform1f(std::string _name, float _value) const;
90  void setUniformVector2i(std::string _name, vmml::Vector2i _value) const;
91  void setUniformVector2f(std::string _name, vmml::Vector2f _value) const;
92  void setUniformVector3f(std::string _name, vmml::Vector3f _value) const;
93  void setUniformVector4f(std::string _name, vmml::Vector4f _value) const;
94  void setUniformVector4f(std::string _name, const float* _values) const;
95  void setUniformMatrix3f(std::string _name, vmml::Matrix3f _value, bool _transpose=false) const;
96  void setUniformMatrix4f(std::string _name, vmml::Matrix4f _value, bool _transpose = false) const;
97 
98  void setUniformArrayf(std::string _name, int _count, const GLfloat* _values) const;
99 
100  void setDefine1i(std::string _in, int _value);
102 
103  private:
104 
105  void setupPrograms(std::vector<std::string> _inputPathOrSource, bool _isSource);
106 
107  void bindAttributeLocation(unsigned int _location, std::string _name);
108  void unbindAttributeLocation(unsigned int _location);
109  void linkShader();
110  void getOpenGLError(std::string _input);
111 
112  private:
113  void load(std::vector<std::string> _inputPathOrSource, bool _isSource);
114  void createShaderHandle();
115  void attachProgramID(GLuint _programID);
116  void setupPropertyBuffer();
117  void addAttributeProperty(ShaderProperty::IOType _iotype, std::string _property);
118 
119  std::map<int, std::string> vertexArrayAttributeLocations;
120 
121  GLuint handle;
122  GLuint vertexArrayAttributeCount;
123 
124  std::vector< std::shared_ptr<ge::ShaderProgram> > programs;
125  std::string repoPath;
126 
127  // generic sources
128  std::string globalSourcePath;
129  ge::Shader::ShaderType shadertype;
130 
131  };
132 
133  typedef std::map<std::string, std::shared_ptr<ge::Shader> > ShaderMap;
134  typedef std::pair<std::string, std::shared_ptr<ge::Shader> > ShaderMapPair;
135 
136 }
137 #endif
ShaderType
Definition: Shader.h:28
void setUniformBlockBinding(std::string _ublockName, GLuint _ublockBinding)
Definition: Shader.cpp:432
void unbind() const
Definition: Shader.cpp:448
void setUniformVector4f(std::string _name, vmml::Vector4f _value) const
Definition: Shader.cpp:389
void setUniform1f(std::string _name, float _value) const
Definition: Shader.cpp:319
void setUniform1d(std::string _name, double _value) const
Definition: Shader.cpp:331
void setDefinesToZeroWithoutRecompile()
Definition: Shader.cpp:156
GLuint getUniformBlockIndex(std::string _input)
Definition: Shader.cpp:440
void setUniformVector3d(std::string _name, vmml::Vector3d _value) const
Definition: Shader.cpp:341
void setUniform1i(std::string _name, int _value) const
Definition: Shader.cpp:310
std::pair< std::string, std::shared_ptr< ge::Shader > > ShaderMapPair
Definition: Shader.h:134
static void printComputeCapabilities()
Definition: Shader.cpp:461
Shader()
Definition: Shader.cpp:20
void bind() const
Definition: Shader.cpp:444
void setUniformMatrix3d(std::string _name, vmml::Matrix3d _value, bool _transpose=false) const
Definition: Shader.cpp:356
void setUniformMatrix4d(std::string _name, vmml::Matrix4d _value, bool _transpose=false) const
Definition: Shader.cpp:351
void loadFromSourceVertFrag(std::string _vertSource, std::string _fragSource)
Definition: Shader.cpp:75
void setUniformMatrix4f(std::string _name, vmml::Matrix4f _value, bool _transpose=false) const
Definition: Shader.cpp:407
void setUniformVector2f(std::string _name, vmml::Vector2f _value) const
Definition: Shader.cpp:371
IOType
Definition: ShaderParser.h:21
void setDefine1i(std::string _in, int _value)
Definition: Shader.cpp:149
void setUniformVector4d(std::string _name, vmml::Vector4d _value) const
Definition: Shader.cpp:346
Definition: Shader.h:28
void setUniformMatrix3f(std::string _name, vmml::Matrix3f _value, bool _transpose=false) const
Definition: Shader.cpp:416
std::map< std::string, std::shared_ptr< ge::Shader > > ShaderMap
Definition: Shader.h:133
ReloadType
Definition: ShaderProgram.h:27
Definition: Shader.h:28
Definition: AvalancheTrainingSimulationEngine.h:28
void clear()
Definition: Shader.cpp:34
~Shader()
Definition: Shader.cpp:26
void recompile(ShaderProgram::ReloadType _type=ShaderProgram::ReloadType::FROMFILE)
Definition: Shader.cpp:162
void dispatchCompute(GLuint _numGroupsX, GLuint _numGroupsY, GLuint _numGroupsZ) const
Definition: Shader.cpp:453
void setUniformVector2i(std::string _name, vmml::Vector2i _value) const
Definition: Shader.cpp:362
Definition: Shader.h:25
void setUniformArrayf(std::string _name, int _count, const GLfloat *_values) const
Definition: Shader.cpp:426
void setUniformVector3f(std::string _name, vmml::Vector3f _value) const
Definition: Shader.cpp:380
Shader(const std::shared_ptr< Shader > copy)
Definition: Shader.h:33
void load(std::string _inputPath, ge::Shader::ShaderType _type, std::string _genericShaderPath="")
Definition: Shader.cpp:52
GLuint getHandle()
Definition: Shader.cpp:280
GLuint getVertexArrayAttributeCount() const
Definition: Shader.cpp:306
void setUniformVector2d(std::string _name, vmml::Vector2d _value) const
Definition: Shader.cpp:336