1 #pragma once 2 3 #include <string> 4 #include <vector> 5 6 #include <libcurv/viewer/glfw.h> 7 #include <glm/glm.hpp> 8 9 #include "texture.h" 10 #include "fbo.h" 11 12 class Shader { 13 14 public: 15 Shader(); 16 virtual ~Shader(); 17 getProgram()18 const GLuint getProgram() const { return m_program; }; getFragmentShader()19 const GLuint getFragmentShader() const { return m_fragmentShader; }; getVertexShader()20 const GLuint getVertexShader() const { return m_vertexShader; }; 21 needBackbuffer()22 const bool needBackbuffer() const { return m_backbuffer; }; needTime()23 const bool needTime() const { return m_time; }; needDelta()24 const bool needDelta() const { return m_delta; }; needDate()25 const bool needDate() const { return m_date; }; needMouse()26 const bool needMouse() const { return m_mouse; }; need_iMouse()27 const bool need_iMouse() const { return m_imouse; }; needView2d()28 const bool needView2d() const { return m_view2d; }; needView3d()29 const bool needView3d() const { return m_view3d; }; 30 31 void use() const; 32 bool isInUse() const; 33 34 const GLint getAttribLocation(const std::string& _attribute) const; 35 bool load(const std::string& _fragmentSrc, const std::string& _vertexSrc, bool _verbose = false); 36 37 void setUniform(const std::string& _name, int _x); 38 39 void setUniform(const std::string& _name, float _x); 40 void setUniform(const std::string& _name, float _x, float _y); 41 void setUniform(const std::string& _name, float _x, float _y, float _z); 42 void setUniform(const std::string& _name, float _x, float _y, float _z, float _w); 43 44 void setUniform(const std::string& _name, const float *_array, unsigned int _size); 45 46 void setUniform(const std::string& _name, const Texture* _tex, unsigned int _texLoc); 47 void setUniform(const std::string& _name, const Fbo* _fbo, unsigned int _texLoc); 48 setUniform(const std::string & _name,const glm::vec2 & _value)49 void setUniform(const std::string& _name, const glm::vec2& _value) { setUniform(_name,_value.x,_value.y); } setUniform(const std::string & _name,const glm::vec3 & _value)50 void setUniform(const std::string& _name, const glm::vec3& _value) { setUniform(_name,_value.x,_value.y,_value.z); } setUniform(const std::string & _name,const glm::vec4 & _value)51 void setUniform(const std::string& _name, const glm::vec4& _value) { setUniform(_name,_value.x,_value.y,_value.z,_value.w); } 52 53 void setUniform(const std::string& _name, const glm::mat2& _value, bool transpose = false); 54 void setUniform(const std::string& _name, const glm::mat3& _value, bool transpose = false); 55 void setUniform(const std::string& _name, const glm::mat4& _value, bool transpose = false); 56 57 void detach(GLenum type); 58 59 private: 60 61 GLuint compileShader(const std::string& src, GLenum type, bool verbose); 62 GLint getUniformLocation(const std::string& _uniformName) const; 63 64 GLuint m_program; 65 GLuint m_fragmentShader; 66 GLuint m_vertexShader; 67 68 bool m_backbuffer; 69 bool m_time; 70 bool m_delta; 71 bool m_date; 72 bool m_mouse; 73 bool m_imouse; 74 bool m_view2d; 75 bool m_view3d; 76 }; 77