-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.h
107 lines (73 loc) · 2.21 KB
/
utils.h
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
101
102
#pragma once
#include <ostream>
#include <iostream>
#include <embree3/rtcore.h>
#include <vector>
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/glm.hpp>
#include <glm/gtx/norm.hpp>
#define GLM_GTX_transform
#include <glm/gtx/transform.hpp>
#define GLM_GTC_constants
#include <glm/gtc/constants.hpp>
inline std::ostream& operator<<(std::ostream& os, const glm::vec3& v) {
os << '[' << v.x << ',' << v.y << ',' << v.z << ']';
return os;
}
struct Data {
glm::vec4* face_colors;
glm::vec4* vertex_colors;
Data(std::size_t vertex_n, std::size_t face_n) {
vertex_colors = static_cast<glm::vec4*>(aligned_alloc(16, vertex_n*sizeof(glm::vec4)));
face_colors = static_cast<glm::vec4*>(aligned_alloc(16, face_n*sizeof(glm::vec4)));
}
~Data() {
if (vertex_colors) free(vertex_colors);
if (face_colors) free(face_colors);
}
Data(Data&& data) {
face_colors = data.face_colors;
vertex_colors = data.vertex_colors;
data.face_colors = nullptr;
data.vertex_colors = nullptr;
}
Data& operator=(const Data&) = delete;
Data(Data& data) = delete;
};
struct DataVertex {
glm::vec4* vertex;
DataVertex(std::size_t vertex_n) {
vertex = static_cast<glm::vec4*>(aligned_alloc(16, vertex_n*sizeof(glm::vec4)));
}
~DataVertex() {
if (vertex) free(vertex);
}
DataVertex(DataVertex&& data) {
vertex = data.vertex;
data.vertex = nullptr;
}
DataVertex& operator=(DataVertex&& data) {
vertex = data.vertex;
data.vertex = nullptr;
return *this;
}
DataVertex& operator=(const DataVertex&) = delete;
DataVertex(DataVertex& data) = delete;
};
//==================================================
// Materials structs
// TODO: It should be defined somewhere else!
//==================================================
enum struct MaterialType {
Lambertian, Metal, Dielectric, DiffuseLight
};
struct Material {
MaterialType type {};
glm::vec3 emmited{}; // DiffuseLight
glm::vec3 albedo{}; // all
float fuzz{}; // Metal
float ref_idx{}; // Dielectric
Material(MaterialType type): type{type} {}
Material() {}
};
using VectorMaterial = std::vector<Material>;