|
Katana Plug-in APIs 0.1
|
00001 // Copyright (c) 2016 The Foundry Visionmongers Ltd. All Rights Reserved. 00002 00003 #ifndef GLSHADERPROGRAM_H_ 00004 #define GLSHADERPROGRAM_H_ 00005 00006 #ifdef _WIN32 00007 #include <Windows.h> 00008 #endif 00009 00010 #include <FnAttribute/FnAttribute.h> 00011 #include <FnViewer/plugin/FnMathTypes.h> 00012 00013 #include <GL/glew.h> 00014 #include <string> 00015 #include <map> 00016 00017 namespace Foundry 00018 { 00019 namespace Katana 00020 { 00021 namespace ViewerUtils 00022 { 00023 00024 using Foundry::Katana::ViewerAPI::Matrix44d; 00025 00027 enum ShaderType 00028 { 00029 VERTEX = GL_VERTEX_SHADER, 00030 FRAGMENT = GL_FRAGMENT_SHADER, 00031 GEOMETRY = GL_GEOMETRY_SHADER, 00032 TESS_CONTROL = GL_TESS_CONTROL_SHADER, 00033 TESS_EVALUATION = GL_TESS_EVALUATION_SHADER, 00034 COMPUTE = GL_COMPUTE_SHADER 00035 }; 00036 00041 class GLShaderProgram 00042 { 00043 public: 00044 GLShaderProgram(); 00045 ~GLShaderProgram(); 00046 00048 void cleanup(); 00049 00054 void compileShader(const std::string& filename, ShaderType type); 00055 00060 void compileShader(const std::string& name, ShaderType type, const std::string& shaderSource); 00061 00063 GLuint getUniformLocation(const std::string& name); 00064 00066 void link(); 00067 00069 void use(); 00070 00072 GLuint getHandle() const { return m_handle; } 00073 00075 bool isLinked() const { return m_isLinked; } 00076 00078 void bindAttribLocation(GLuint location, const std::string& name); 00079 00081 void bindFragDataLocation(GLuint location, const std::string& name); 00082 00084 void setUniform(const std::string& name, float val); 00085 00087 void setUniform(const std::string& name, float x, float y); 00088 00090 void setUniform(const std::string& name, float x, float y, float z); 00091 00093 void setUniform(const std::string& name, float x, float y, float z, float w); 00094 00096 void setUniform(const std::string& name, int val); 00097 00099 void setUniform(const std::string& name, bool val); 00100 00103 void setUniform(const std::string& name, FnAttribute::FloatAttribute val); 00104 00107 void setUniform(const std::string& name, FnAttribute::DoubleAttribute val); 00108 00110 void setUniform(const std::string& name, const Matrix44d& matrix); 00111 00113 void setUniformMatrix4d(const std::string& name, const double* matrix); 00114 00115 private: 00117 const std::string readFile(const std::string& filename); 00119 GLuint m_handle; 00121 bool m_isLinked; 00123 std::map<std::string, GLuint> m_uniformLocations; 00124 }; 00125 00126 } // ViewerUtils 00127 } // Katana 00128 } // Foundry 00129 #endif /* GLSHADERPROGRAM_H_ */
1.7.3