You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.3 KiB

  1. #pragma once
  2. #include "ggl.h"
  3. struct UniformTexture {
  4. GLint mLocation;
  5. GLuint mTexture;
  6. UniformTexture() {
  7. mLocation = -1;
  8. mTexture = 0;
  9. }
  10. };
  11. struct UniformTextureCube {
  12. GLint mLocation;
  13. GLuint mTexture;
  14. UniformTextureCube() {
  15. mLocation = -1;
  16. mTexture = 0;
  17. }
  18. };
  19. struct UniformVector4f {
  20. GLint mLocation;
  21. float v[4];
  22. UniformVector4f() {
  23. mLocation = -1;
  24. memset(v, 0, sizeof(float) * 4);
  25. }
  26. };
  27. class Shader {
  28. public:
  29. static GLuint CompileShader(GLuint shaderType, const char* shaderCode);
  30. static GLuint CreateProgram(GLuint vsShader, GLuint fsShader);
  31. public:
  32. GLuint mProgram;
  33. GLint mModelMatrixLocation, mViewMatrixLocation, mProjectionMatrixLocation;
  34. GLint mPositionLocation, mColorLocation, mTexcoordLocation, mNormalLocation;
  35. std::map<std::string, UniformTexture*> mUniformTextures;
  36. std::map<std::string, UniformTextureCube*> mUniformTextureCubes;
  37. std::map<std::string, UniformVector4f*> mUniformVec4s;
  38. void Init(const char* vs, const char* fs);
  39. void Bind(float* M, float* V, float* P);
  40. void SetTexture(const char* name, const char* imagePath);
  41. GLuint SetTexture(const char* name, GLuint texture);
  42. GLuint SetTextureCube(const char * name, GLuint texture);
  43. void SetVec4(const char * name, float x, float y, float z, float w);
  44. };