Shader.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (C) 2018 Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
  3. * Author: Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #pragma once
  19. #include <string>
  20. #include <GL/glew.h>
  21. #include <GL/gl.h>
  22. #include <glm/glm.hpp>
  23. class Shader {
  24. public:
  25. Shader(const std::string &vShaderPath,
  26. const std::string &fShaderPath);
  27. inline void use() {
  28. glUseProgram(id);
  29. }
  30. inline void setBool(const std::string &name,
  31. bool value) const
  32. {
  33. glUniform1i(glGetUniformLocation(id, name.c_str()),
  34. static_cast<int>(value));
  35. }
  36. inline void setInt(const std::string &name,
  37. bool value) const
  38. {
  39. glUniform1i(glGetUniformLocation(id, name.c_str()),
  40. value);
  41. }
  42. inline void setFloat(const std::string &name,
  43. bool value) const
  44. {
  45. glUniform1f(glGetUniformLocation(id, name.c_str()),
  46. value);
  47. }
  48. inline void setVec3(const std::string &name,
  49. const glm::vec3 &v)
  50. {
  51. glUniform3f(glGetUniformLocation(id, name.c_str()),
  52. v.x, v.y, v.z);
  53. }
  54. inline void setMat4(const std::string &name,
  55. const glm::mat4 &m)
  56. {
  57. glUniformMatrix4fv(glGetUniformLocation(id, name.c_str()),
  58. 1, GL_FALSE, &m[0][0]);
  59. }
  60. inline unsigned int getId() const {
  61. return id;
  62. }
  63. private:
  64. unsigned int id;
  65. };