Masterchoc

Untitled

Jan 4th, 2018
138
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "material.h"
  2.  
  3. Material::Material(const std::string& name, Shader* shader)
  4. {
  5.     m_name = name;
  6.     m_shader = shader;
  7.  
  8.     this->getShader()->addUniform("mTransform");
  9.     this->getShader()->addUniform("mView");
  10.     this->getShader()->addUniform("mProj");
  11.     this->getShader()->addUniform("lightPosition");
  12.     this->getShader()->addUniform("lightColor");
  13. }
  14.  
  15. void Material::bindAttributes()
  16. {
  17.     this->getShader()->bindAttribute(0, "position");
  18.     this->getShader()->bindAttribute(1, "uvs");
  19.     this->getShader()->bindAttribute(2, "normal");
  20.     this->getShader()->bindAttribute(3, "tangent");
  21. }
  22.  
  23. void Material::preUpdate(Transform* transform, Camera* camera, std::vector<Light*> lights)
  24. {
  25.     this->getShader()->bind();
  26.     this->bindAttributes();
  27.     this->getShader()->setUniformMat4fv("mTransform", transform->getModel());
  28.     this->getShader()->setUniformMat4fv("mView", camera->getViewMatrix());
  29.     this->getShader()->setUniformMat4fv("mProj", camera->getProjectionMatrix());
  30.     this->getShader()->setUniform3fv("lightPosition", lights[0]->getPosition());
  31.     this->getShader()->setUniform3fv("lightColor", lights[0]->getColor());
  32.     this->getDiffuseTexture()->bind(0);
  33. }
  34.  
  35. void Material::postUpdate()
  36. {
  37.     this->getShader()->unbind();
  38.     this->getDiffuseTexture()->unbind();
  39. }
  40.  
  41. Material::~Material()
  42. {
  43.  
  44. }
RAW Paste Data