-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserModelPool.hpp
102 lines (92 loc) · 2.66 KB
/
UserModelPool.hpp
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
//
// Created by Carlo Ronconi on 27/06/23.
//
#include <utility>
#include "DataStructs.hpp"
#ifndef DRONE_DELIVERY_USERMODELPOOL_HPP
#define DRONE_DELIVERY_USERMODELPOOL_HPP
template <typename VertexType, typename UboType>
class UserModel {
private:
Model<VertexType> model;
DescriptorSet ds;
DescriptorSetLayout* DSL;
VertexDescriptor* vDescriptor;
Pipeline* pipeline;
Texture* texture;
BaseProject* bp;
ModelType MOD_TYPE;
std::string fileName;
int currImage;
public:
UboType ubo;
UserModel(VertexDescriptor *vDescriptor, Pipeline *pipeline,
DescriptorSetLayout *DSL, Texture *texture,
std::string fileName, ModelType MOD_TYPE, BaseProject *bp) :
vDescriptor(vDescriptor),
pipeline(pipeline),
DSL(DSL),
texture(texture),
fileName(std::move(fileName)),
MOD_TYPE(MOD_TYPE),
bp(bp){}
void initModel() {
model.init(bp, vDescriptor, fileName, MOD_TYPE);
}
void initDS() {
ds.init(bp, DSL, {
{0, UNIFORM, sizeof(UboType), nullptr},
{1, TEXTURE, 0, texture}});
}
void cleanupDS() {
ds.cleanup();
}
void cleanupModel() {
model.cleanup();
}
void bind(VkCommandBuffer commandBuffer, int currentImage) {
model.bind(commandBuffer);
ds.bind(commandBuffer, *pipeline, 1, currentImage);
vkCmdDrawIndexed(commandBuffer, static_cast<uint32_t>(model.indices.size()),
1, 0, 0, 0);
currImage = currentImage;
}
void map(glm::mat4 world, glm::mat4 view, glm::mat4 projection) {
ubo.amb = 1.0f; ubo.gamma = 180.0f; ubo.sColor = glm::vec3(1.0f);
ubo.mvpMat = projection * view * world;
ubo.mMat = world;
ubo.nMat = glm::inverse(glm::transpose(world));
ds.map(currImage, &ubo, sizeof(ubo), 0);
}
};
template <typename VertexType, typename UboType>
class UserModelPool {
public:
std::vector<UserModel<VertexType, UboType>> models;
void initAllModels() {
for (auto &m : models) {
m.initModel();
}
}
void initAllDSs() {
for (auto &m : models) {
m.initDS();
}
}
void cleanupAllDSs() {
for (auto &m : models) {
m.cleanupDS();
}
}
void cleanupAllModels() {
for (auto &m : models) {
m.cleanupModel();
}
}
void bindAll(VkCommandBuffer commandBuffer, int currentImage) {
for (auto &m : models) {
m.bind(commandBuffer, currentImage);
}
}
};
#endif //DRONE_DELIVERY_USERMODELPOOL_HPP