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
|
#ifndef MATERIAL_STRUCT
#define MATERIAL_STRUCT
#ifdef HAVE_GL
#include <glm/glm.hpp>
namespace camp {
inline bool operator < (const glm::vec4& m1, const glm::vec4& m2) {
return m1[0] < m2[0] ||
(m1[0] == m2[0] &&
(m1[1] < m2[1] ||
(m1[1] == m2[1] &&
(m1[2] < m2[2] ||
(m1[2] == m2[2] &&
(m1[3] < m2[3]))))));
}
struct Material {
public:
glm::vec4 diffuse, ambient, emissive, specular;
GLfloat shininess;
GLfloat padding[3];
Material() {}
Material(const glm::vec4& diffuse, const glm::vec4& ambient,
const glm::vec4& emissive, const glm::vec4& specular,
double shininess) :
diffuse(diffuse), ambient(ambient), emissive(emissive), specular(specular),
shininess(128*shininess) {}
Material(Material const& m):
diffuse(m.diffuse), ambient(m.ambient), emissive(m.emissive),
specular(m.specular), shininess(m.shininess) {}
~Material() {}
Material& operator=(Material const& m)
{
diffuse=m.diffuse;
ambient=m.ambient;
emissive=m.emissive;
specular=m.specular;
shininess=m.shininess;
return *this;
}
friend bool operator < (const Material& m1, const Material& m2) {
return m1.diffuse < m2.diffuse ||
(m1.diffuse == m2.diffuse &&
(m1.ambient < m2.ambient ||
(m1.ambient == m2.ambient &&
(m1.emissive < m2.emissive ||
(m1.emissive == m2.emissive &&
(m1.specular < m2.specular ||
(m1.specular == m2.specular &&
(m1.shininess < m2.shininess))))))));
}
};
extern size_t Nmaterials; // Number of materials compiled in shader
extern size_t nmaterials; // Current size of materials buffer
extern size_t Maxmaterials; // Maxinum size of materials buffer
void clearMaterialBuffer(bool draw=false);
}
#endif
#endif
|