-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUniformBuffer.hpp
78 lines (56 loc) · 1.8 KB
/
UniformBuffer.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
#pragma once
#include "RendererCommon.h"
#include "Model.hpp"
#include "Camera.hpp"
#include <chrono>
struct StaticUbo {
glm::mat4 view;
glm::mat4 proj;
};
struct DynamicUbo {
glm::mat4* model{nullptr};
};
struct UniformBuffers {
std::vector<VkBuffer> staticBuffers;
std::vector<VkBuffer> dynamicBuffers;
std::vector<VkDeviceMemory> staticBuffersMemory;
std::vector<VkDeviceMemory> dynamicBuffersMemory;
std::vector<void*> staticBuffersMapped;
std::vector<void*> dynamicBuffersMapped;
};
class UniformBuffer {
public:
UniformBuffer() = default;
~UniformBuffer();
UniformBuffer(const VkDevice& device, const VkPhysicalDevice& physicalDevice,
const int MAX_FRAMES_IN_FLIGHT, const VkExtent2D& swapchainExtent, VkPhysicalDeviceProperties properties,
const std::vector<Model>& models, const Camera& camera);
void createDescriptorSets(Model& model, const int MAX_FRAMES_IN_FLIGHT);
void recreateDynamicBuffer();
void calculateDynamicBuffer();
void updateStatic(uint32_t currentFrame);
void updateDynamic(uint32_t currentFrame);
void cleanup();
VkDescriptorSetLayout& getLayout();
uint32_t getDynamicAlignment();
VkDescriptorPool& getDescriptorPool();
private:
void create(const int MAX_FRAMES_IN_FLIGHT, const VkPhysicalDevice& physicalDevice);
void createDescriptorSetLayout();
void createDescriptorPool(const int MAX_FRAMES_IN_FLIGHT);
const std::vector<Model>& models;
const Camera& camera;
uint32_t dynamicAlignment;
size_t bufferSize;
const uint32_t MAX_MODEL_COUNT;
StaticUbo staticUbo;
DynamicUbo dynamicUbo;
VkDescriptorSetLayout descriptorSetLayout;
VkDescriptorSetLayout dynamicDescriptorSetLayout;
VkDescriptorPool descriptorPool;
UniformBuffers uniformBuffers;
VkDevice device;
VkPhysicalDevice physicalDevice;
VkExtent2D swapchainExtent;
const int MAX_FRAMES_IN_FLIGHT;
};