Advertisement
Guest User

Untitled

a guest
Aug 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include "Shader.h"
  2.  
  3. #include <GL/glew.h>
  4. #include <GLFW/glfw3.h>
  5.  
  6. void Shader::bind() const {
  7.     glUseProgram(handle);
  8. }
  9.  
  10. void Shader::release() const {
  11.     glUseProgram(0);
  12. }
  13.  
  14. int Shader::uniform(const std::string &name) {
  15.     // Is it already in the map?
  16.     auto it = locationMap.find(name);
  17.     if (it != locationMap.end()) {
  18.         return it->second;
  19.     }
  20.  
  21.     // It isn't, get the uniform location and store it
  22.     GLint location = glGetUniformLocation(handle, name.c_str());
  23.     locationMap.insert(std::make_pair<std::string, int>(name, location));
  24.  
  25.     return location;
  26. }
  27.  
  28. int Shader::attribute(const std::string &name) {
  29.     // Is it already in the map?
  30.     auto it = locationMap.find(name);
  31.     if (it != locationMap.end()) {
  32.         return it->second;
  33.     }
  34.  
  35.     // It isn't, get the attribute location and store it
  36.     GLint location = glGetAttribLocation(handle, name.c_str());
  37.     locationMap.insert(std::make_pair<std::string, int>(name, location));
  38.  
  39.     return location;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement