2
0

Shader.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. bool Load(const std::string& vertName, const std::string& fragName);
  18. void Unload();
  19. // Set this as the active shader program
  20. void SetActive();
  21. // Sets a Matrix uniform
  22. void SetMatrixUniform(const char* name, const Matrix4& matrix);
  23. // Sets an array of matrix uniforms
  24. void SetMatrixUniforms(const char* name, Matrix4* matrices, unsigned count);
  25. // Sets a Vector3 uniform
  26. void SetVectorUniform(const char* name, const Vector3& vector);
  27. void SetVector2Uniform(const char* name, const Vector2& vector);
  28. // Sets a float uniform
  29. void SetFloatUniform(const char* name, float value);
  30. // Sets an integer uniform
  31. void SetIntUniform(const char* name, int value);
  32. private:
  33. // Tries to compile the specified shader
  34. bool CompileShader(const std::string& fileName,
  35. GLenum shaderType,
  36. GLuint& outShader);
  37. // Tests whether shader compiled successfully
  38. bool IsCompiled(GLuint shader);
  39. // Tests whether vertex/fragment programs link
  40. bool IsValidProgram();
  41. private:
  42. // Store the shader object IDs
  43. GLuint mVertexShader;
  44. GLuint mFragShader;
  45. GLuint mShaderProgram;
  46. };