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.

Shader.cpp 845B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "Shader.h"
  2. void Shader::bind() const {
  3. glUseProgram(handle);
  4. }
  5. void Shader::release() const {
  6. glUseProgram(0);
  7. }
  8. int Shader::uniform(const std::string &name) {
  9. // Is it already in the map?
  10. auto it = locationMap.find(name);
  11. if (it != locationMap.end()) {
  12. return it->second;
  13. }
  14. // It isn't, get the uniform location and store it
  15. GLint location = glGetUniformLocation(handle, name.c_str());
  16. locationMap.insert(std::make_pair(name, location));
  17. return location;
  18. }
  19. int Shader::attribute(const std::string &name) {
  20. // Is it already in the map?
  21. auto it = locationMap.find(name);
  22. if (it != locationMap.end()) {
  23. return it->second;
  24. }
  25. // It isn't, get the attribute location and store it
  26. GLint location = glGetAttribLocation(handle, name.c_str());
  27. locationMap.insert(std::make_pair(name, location));
  28. return location;
  29. }