shader.hpp 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // shader.hpp: Loads shaders into opengl
  2. #ifndef IS_SHADER_H_
  3. #define IS_SHADER_H_
  4. #include <string>
  5. #include <cstdio>
  6. #include <vector>
  7. #ifdef OPENGL_ENABLED
  8. #include <glm/glm.hpp>
  9. #include <glm/gtc/type_ptr.hpp>
  10. #include <GL/glew.h>
  11. #endif
  12. #include <string>
  13. #include <fstream>
  14. #include <streambuf>
  15. namespace slop {
  16. class Shader {
  17. public:
  18. Shader( std::string name, std::string vert, std::string frag, std::string shadertype = "other" );
  19. ~Shader();
  20. unsigned int getProgram();
  21. std::string m_name;
  22. void bind();
  23. void unbind();
  24. void setParameter( std::string name, int foo );
  25. void setParameter( std::string name, float foo );
  26. #ifdef OPENGL_ENABLED
  27. void setParameter( std::string name, glm::mat4 foo );
  28. void setParameter( std::string name, glm::vec4 foo );
  29. void setParameter( std::string name, glm::vec2 foo );
  30. #endif
  31. void setAttribute( std::string name, unsigned int buffer, unsigned int stepsize );
  32. int m_type;
  33. private:
  34. std::vector<unsigned int> m_activeattribs;
  35. bool m_good;
  36. unsigned int getUniformLocation( std::string );
  37. int compile( unsigned int shader );
  38. int link( unsigned int vert, unsigned int frag );
  39. unsigned int m_program;
  40. };
  41. };
  42. #endif // IS_SHADER_H_