2
0

Shader.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // ----------------------------------------------------------------
  2. // From Game Programming in C++ by Sanjay Madhav
  3. // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
  4. //
  5. // Released under the BSD License
  6. // See LICENSE in root directory for full details.
  7. // ----------------------------------------------------------------
  8. #pragma once
  9. #include <GL/glew.h>
  10. #include <string>
  11. #include "Math.h"
  12. class Shader
  13. {
  14. public:
  15. Shader();
  16. ~Shader();
  17. // Load the vertex/fragment shaders with the given names
  18. bool Load(const std::string& vertName, const std::string& fragName);
  19. void Unload();
  20. // Set this as the active shader program
  21. void SetActive();
  22. // Sets a Matrix uniform
  23. void SetMatrixUniform(const char* name, const Matrix4& matrix);
  24. private:
  25. // Tries to compile the specified shader
  26. bool CompileShader(const std::string& fileName,
  27. GLenum shaderType,
  28. GLuint& outShader);
  29. // Tests whether shader compiled successfully
  30. bool IsCompiled(GLuint shader);
  31. // Tests whether vertex/fragment programs link
  32. bool IsValidProgram();
  33. private:
  34. // Store the shader object IDs
  35. GLuint mVertexShader;
  36. GLuint mFragShader;
  37. GLuint mShaderProgram;
  38. };