2
0

Shader.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. // Sets a Vector3 uniform
  25. void SetVectorUniform(const char* name, const Vector3& vector);
  26. // Sets a float uniform
  27. void SetFloatUniform(const char* name, float value);
  28. private:
  29. // Tries to compile the specified shader
  30. bool CompileShader(const std::string& fileName,
  31. GLenum shaderType,
  32. GLuint& outShader);
  33. // Tests whether shader compiled successfully
  34. bool IsCompiled(GLuint shader);
  35. // Tests whether vertex/fragment programs link
  36. bool IsValidProgram();
  37. private:
  38. // Store the shader object IDs
  39. GLuint mVertexShader;
  40. GLuint mFragShader;
  41. GLuint mShaderProgram;
  42. };