forked from tharvik/COG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaterial.cpp
74 lines (59 loc) · 1.72 KB
/
Material.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
#include "Material.h"
#include <fstream>
#include "Logger.h"
using namespace std;
map<string, shared_ptr<Texture>> Material::textures;
Material::Material(const std::string& mbfPath, const std::string& vsPath,
const std::string& fsPath) :
shader(vsPath, fsPath), texturesToDraw(), parameters()
{
readMaterialFile(mbfPath);
// set uniform values to the shader
this->shader.setUniformValue(this->parameters);
}
Material::Material(const Material&& material) : shader(move(material.shader)),
texturesToDraw(move(material.texturesToDraw)),
parameters(move(material.parameters))
{}
void Material::use() const
{
this->shader.use();
//!! still need to use textures
}
void Material::print() const
{
cout << "\tKa = ("
<< this->parameters[Shader::Ka+0]
<< this->parameters[Shader::Ka+1]
<< this->parameters[Shader::Ka+2]
<< ")" << endl
<< "\tKd = ("
<< this->parameters[Shader::Kd+0]
<< this->parameters[Shader::Kd+1]
<< this->parameters[Shader::Kd+2]
<< ")" << endl
<< "\tKs = ("
<< this->parameters[Shader::Ks+0]
<< this->parameters[Shader::Ks+1]
<< this->parameters[Shader::Ks+2]
<< ")" << endl
<< "\tNs = " << this->parameters[Shader::Ns+0] << endl
<< "\td = " << this->parameters[Shader::d+0] << endl;
}
void Material::readMaterialFile(const string &filePath)
{
// open file
ifstream file;
file.open(filePath, std::ifstream::binary);
if (!file.good())
{
logger_warn("Unable to open material binary file ." + filePath
+ "The file may be empty or doesn't exist.");
return;
}
// read
file.read(reinterpret_cast<char*>(parameters.data()),
long(parameters.max_size() * sizeof(float)));
// end
file.close();
}