Open Source Tomb Raider Engine
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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*!
  2. * \file include/system/Shader.h
  3. * \brief OpenGL Shader implementation
  4. *
  5. * \author xythobuz
  6. */
  7. #ifndef _SHADER_H_
  8. #define _SHADER_H_
  9. #include <vector>
  10. #include <glm/mat4x4.hpp>
  11. #include <glm/vec2.hpp>
  12. #include <glm/vec4.hpp>
  13. #include "TextureManager.h"
  14. class Shader {
  15. public:
  16. Shader() : programID(-1) { }
  17. ~Shader();
  18. int compile(const char* vertex, const char* fragment);
  19. void use();
  20. int addUniform(const char* name);
  21. unsigned int getUniform(int n);
  22. void addBuffer(int n = 1);
  23. unsigned int getBuffer(int n);
  24. template<typename T>
  25. void bufferData(int buff, std::vector<T> v) {
  26. glBindBuffer(GL_ARRAY_BUFFER, getBuffer(buff));
  27. glBufferData(GL_ARRAY_BUFFER, v.size() * sizeof(T), &v[0], GL_STATIC_DRAW);
  28. }
  29. void loadUniform(int uni, glm::vec2 vec);
  30. void loadUniform(int uni, glm::vec4 vec);
  31. void loadUniform(int uni, glm::mat4 mat);
  32. void loadUniform(int uni, int texture, TextureManager::TextureStorage store, int slot = 0);
  33. void bindBuffer(int buff);
  34. void bindBuffer(int buff, int location, int size);
  35. void disableAttribs();
  36. private:
  37. int programID;
  38. std::vector<unsigned int> uniforms;
  39. std::vector<unsigned int> buffers;
  40. std::vector<bool> attribs;
  41. };
  42. #endif