-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModel.cpp
100 lines (81 loc) · 2.22 KB
/
Model.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "Model.h"
#include "FileHelper.h"
#include "Shader.h"
const ShaderProgram * Model::getDefaultShaderProgram() {
static ShaderProgram defaultShaderProgram(ShaderProgram::Recipe()
.addShader(Shader::compile(Shader::VertexShader, FileHelper::loadTextFile("shaders/Transform.glsl")))
.addShader(Shader::compile(Shader::VertexShader, FileHelper::loadTextFile("shaders/Null.vert")))
.addShader(Shader::compile(Shader::FragmentShader, FileHelper::loadTextFile("shaders/FillColor.frag")))
);
return &defaultShaderProgram;
}
Model::Model() {
this->color = { 1, 1, 1, 1 };
}
const Mesh * Model::getMesh() const {
return this->mesh;
}
Model & Model::bindMesh(const Mesh * mesh) {
this->mesh = mesh;
return *this;
}
const Vector4f& Model::getColor() const {
return this->color;
}
Model & Model::setColor(const Vector4f & color) {
this->color = color;
return *this;
}
const Texture * Model::getDiffuseTexture() const{
return this->diffuseTexture;
}
Model & Model::bindDiffuseTexture(const Texture * texture) {
this->diffuseTexture = texture;
return *this;
}
const ShaderProgram * Model::getShaderProgram() const {
return this->shaderProgram;
}
Model & Model::bindShaderProgram(const ShaderProgram * shaderProgram) {
this->shaderProgram = nullptr == shaderProgram ? Model::getDefaultShaderProgram() : shaderProgram;
return *this;
}
void Model::draw(const ShaderProgram & shaderProgram) const {
if (nullptr == this->mesh) {
return;
}
GLint objectId;
if (0 <= (objectId = glGetUniformLocation(shaderProgram.getProgramId(), "in_color"))) {
glUniform4fv(objectId, 1, this->color.data());
}
shaderProgram.onPreDraw(*this);
this->mesh->draw(shaderProgram);
shaderProgram.onPostDraw(*this);
}
const Texture * Model::getSpecularTexture() const
{
return specularTexture;
}
Model& Model::bindSpecularTexture(const Texture * texture)
{
specularTexture = texture;
return *this;
}
const Texture * Model::getNormalTexture() const
{
return normalTexture;
}
Model& Model::bindNormalTexture(const Texture * texture)
{
normalTexture = texture;
return *this;
}
Model& Model::bindHeightTexture(const Texture * texture)
{
heightTexture = texture;
return *this;
}
const Texture * Model::getHeightTexture() const
{
return heightTexture;
}