-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuniformManager.cpp
67 lines (48 loc) · 2.25 KB
/
uniformManager.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
#include "uniformManager.h"
UniformManager::UniformManager() {
}
UniformManager::~UniformManager() {
}
void UniformManager::init(const Wrapper::Device::Ptr& device, const Wrapper::CommandPool::Ptr& commandPool, int frameCount) {
mDevice = device;
auto vpParam = Wrapper::UniformParameter::create();
vpParam->mBinding = 0;
vpParam->mCount = 1;
vpParam->mDescriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
vpParam->mSize = sizeof(VPMatrices);
vpParam->mStage = VK_SHADER_STAGE_VERTEX_BIT;
for (int i = 0; i < frameCount; ++i) {
auto buffer = Wrapper::Buffer::createUniformBuffer(device, vpParam->mSize, nullptr);
vpParam->mBuffers.push_back(buffer);
}
mUniformParams.push_back(vpParam);
auto objectParam = Wrapper::UniformParameter::create();
objectParam->mBinding = 1;
objectParam->mCount = 1;
objectParam->mDescriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
objectParam->mSize = sizeof(ObjectUniform);
objectParam->mStage = VK_SHADER_STAGE_VERTEX_BIT;
for (int i = 0; i < frameCount; ++i) {
auto buffer = Wrapper::Buffer::createUniformBuffer(device, objectParam->mSize, nullptr);
objectParam->mBuffers.push_back(buffer);
}
mUniformParams.push_back(objectParam);
auto textureParam = Wrapper::UniformParameter::create();
textureParam->mBinding = 2;
textureParam->mCount = 1;
textureParam->mDescriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
textureParam->mStage = VK_SHADER_STAGE_FRAGMENT_BIT;
textureParam->mTexture = Texture::create(mDevice, commandPool, kokoro_png);
mUniformParams.push_back(textureParam);
mDescriptorSetLayout = Wrapper::DescriptorSetLayout::create(device);
mDescriptorSetLayout->build(mUniformParams);
mDescriptorPool = Wrapper::DescriptorPool::create(device);
mDescriptorPool->build(mUniformParams, frameCount);
mDescriptorSet = Wrapper::DescriptorSet::create(device, mUniformParams, mDescriptorSetLayout, mDescriptorPool, frameCount);
}
void UniformManager::update(const VPMatrices& vpMatrices, const ObjectUniform& objectUniform, const int& frameCount) {
//update vp matrices
mUniformParams[0]->mBuffers[frameCount]->updateBufferByMap((void*)(&vpMatrices), sizeof(VPMatrices));
//update object uniform
mUniformParams[1]->mBuffers[frameCount]->updateBufferByMap((void*)(&objectUniform), sizeof(ObjectUniform));
}