moGL
travis-test-3
Modern OpenGL wrapper, thin C++14 header-only layer on top of the OpenGL 4.5+ core spec
|
00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 #ifndef MOGL_SHADERPROGRAM_INCLUDED 00012 #define MOGL_SHADERPROGRAM_INCLUDED 00013 00014 #include <map> 00015 00016 #include <mogl/object/handle.hpp> 00017 #include <mogl/object/shader/shader.hpp> 00018 00019 namespace mogl 00020 { 00021 class ShaderProgram : public Handle<GLuint> 00022 { 00023 public: 00024 ShaderProgram(); 00025 ~ShaderProgram(); 00026 00027 public: 00028 void attach(const Shader& object); 00029 void detach(const Shader& object); 00030 void bindAttribLocation(GLuint location, const std::string& attribute); 00031 bool link(); 00032 void use(); 00033 const std::string& getLog() const; 00034 GLuint getAttribLocation(const std::string& name) const; 00035 GLuint getUniformLocation(const std::string& name) const; 00036 void setTransformFeedbackVaryings(GLsizei count, 00037 const char** varyings, 00038 GLenum bufferMode); 00039 00040 public: 00041 void setVertexAttribPointer(GLuint location, 00042 GLint size, 00043 GLenum type, 00044 GLboolean normalized = GL_FALSE, 00045 GLsizei stride = 0, 00046 const GLvoid* pointerOffset = nullptr); 00047 void setVertexAttribPointer(const std::string& name, 00048 GLint size, 00049 GLenum type, 00050 GLboolean normalized = GL_FALSE, 00051 GLsizei stride = 0, 00052 const GLvoid* pointerOffset = nullptr); 00053 00054 public: 00055 template <class T> void setUniform(const std::string& name, T v1); 00056 template <class T> void setUniform(const std::string& name, T v1, T v2); 00057 template <class T> void setUniform(const std::string& name, T v1, T v2, T v3); 00058 template <class T> void setUniform(const std::string& name, T v1, T v2, T v3, T v4); 00059 template <std::size_t Size, class T> 00060 void setUniformPtr(const std::string& name, const T* ptr, GLsizei count = 1); 00061 template <std::size_t Columns, std::size_t Rows, class T> 00062 void setUniformMatrixPtr(const std::string& name, const T* ptr, GLboolean transpose = GL_FALSE, GLsizei count = 1); 00063 template <std::size_t Size, class T> 00064 void setUniformMatrixPtr(const std::string& name, const T* ptr, GLboolean transpose = GL_FALSE, GLsizei count = 1); 00065 00066 public: 00067 void setUniformSubroutine(GLenum type, const std::string& uniform, const std::string& subroutine); 00068 00069 public: 00070 void printDebug(); 00071 void get(GLenum property, GLint* value); // Direct call to glGetProgramiv() 00072 GLint get(GLenum property); 00073 void set(GLenum property, GLint value); 00074 bool isHandleValid() const override final; 00075 00076 private: 00077 void retrieveLocations(); 00078 void retrieveSubroutines(GLenum type); 00079 00080 private: 00081 using HandleMap = std::map<std::string, GLuint>; 00082 struct SubroutineUniform { 00083 GLuint uniform; 00084 HandleMap subroutines; 00085 }; 00086 using SubroutineMap = std::map<std::string, SubroutineUniform>; 00087 using ShaderSubroutineMap = std::map<GLenum, SubroutineMap>; 00088 00089 std::string _log; 00090 HandleMap _attribs; 00091 HandleMap _uniforms; 00092 ShaderSubroutineMap _subroutines; 00093 }; 00094 } 00095 00096 #include "shaderprogram.inl" 00097 00098 #endif // MOGL_SHADERPROGRAM_INCLUDED