Shader.h 970 B

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