Advertisement
Masterchoc

Untitled

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