Shader.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef SHADER_H
  2. #define SHADER_H
  3. #include <GL/glew.h>
  4. #include "math/Vector.h"
  5. #include "utils/Array.h"
  6. class Shader final {
  7. GLuint vertexShader;
  8. GLuint geometryShader;
  9. GLuint fragmentShader;
  10. GLuint program;
  11. public:
  12. Shader(const char* vertexPath, const char* fragmentPath,
  13. const char* geometryPath = nullptr);
  14. ~Shader();
  15. Shader(const Shader& other) = delete;
  16. Shader(Shader&& other) = delete;
  17. Shader& operator=(const Shader& other) = delete;
  18. Shader& operator=(Shader&& other) = delete;
  19. bool hasError() const;
  20. void use() const;
  21. void setMatrix(const GLchar* name, const GLfloat* data);
  22. void setInt(const GLchar* name, GLint data);
  23. void setFloat(const GLchar* name, GLfloat data);
  24. void setVector(const GLchar* name, const Vector2& v);
  25. void setVector(const GLchar* name, const Vector3& v);
  26. void setVector(const GLchar* name, const Vector4& v);
  27. private:
  28. void clean();
  29. typedef Array<GLchar, 1024 * 128> Code;
  30. typedef Array<GLchar, 1024> ErrorLog;
  31. bool readFileAndCompile(const char* path, GLuint& shader,
  32. GLenum shaderType);
  33. bool readFile(Code& code, const char* path) const;
  34. bool compile(GLuint& shader, const Code& code, GLenum shaderType);
  35. };
  36. #endif