Shader.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 fragmentShader;
  9. GLuint program;
  10. public:
  11. Shader(const char* vertexPath, const char* fragmentPath);
  12. ~Shader();
  13. Shader(const Shader& other) = delete;
  14. Shader(Shader&& other) = delete;
  15. Shader& operator=(const Shader& other) = delete;
  16. Shader& operator=(Shader&& other) = delete;
  17. bool hasError() const;
  18. void use() const;
  19. void setMatrix(const GLchar* name, const GLfloat* data);
  20. void setInt(const GLchar* name, GLint data);
  21. void setFloat(const GLchar* name, GLfloat data);
  22. void setVector(const GLchar* name, const Vector2& v);
  23. void setVector(const GLchar* name, const Vector3& v);
  24. void setVector(const GLchar* name, const Vector4& v);
  25. private:
  26. typedef Array<GLchar, 1024 * 128> Code;
  27. typedef Array<GLchar, 1024> ErrorLog;
  28. bool readFileAndCompile(const char* path, GLuint& shader, GLenum shaderType);
  29. bool readFile(Code& code, const char* path) const;
  30. bool compile(GLuint& shader, const Code& code, GLenum shaderType);
  31. };
  32. #endif