-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphongmaterial.cpp
78 lines (64 loc) · 1.45 KB
/
phongmaterial.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <GL/glew.h>
#include "phongmaterial.h"
#include "shader.h"
#include "shadercache.h"
#include "drawcontext.h"
#include "texture.h"
PhongMaterial::PhongMaterial()
{
shader_ = ShaderCache::getInstance()->acquire("phong");
}
PhongMaterial::~PhongMaterial()
{
}
void PhongMaterial::apply(DrawContext &context)
{
Material::apply(context);
shader_->setUniformValue("ambient", ambient_);
shader_->setUniformValue("diffuse", diffuse_);
shader_->setUniformValue("specular", specular_);
shader_->setUniformValue("shiness", shiness_);
if (diffuseMap_) {
shader_->setUniformValue("useDiffuseMap", true);
diffuseMap_->apply(context, "diffuseMap", 0);
}
else {
shader_->setUniformValue("useDiffuseMap", false);
}
}
const Color& PhongMaterial::ambient() const
{
return ambient_;
}
void PhongMaterial::setAmbient(const Color &ambient)
{
ambient_ = ambient;
}
const Color &PhongMaterial::diffuse() const
{
return diffuse_;
}
void PhongMaterial::setDiffuse(const Color &diffuse)
{
diffuse_ = diffuse;
}
const Color &PhongMaterial::specular() const
{
return specular_;
}
void PhongMaterial::setSpecular(const Color &specular)
{
specular_ = specular;
}
float PhongMaterial::shiness() const
{
return shiness_;
}
void PhongMaterial::setShiness(float shiness)
{
shiness_ = shiness;
}
void PhongMaterial::setDiffuseMap(Texture *diffuseMap)
{
diffuseMap_ = diffuseMap;
}