-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrameBufferBuilder.cpp
More file actions
94 lines (72 loc) · 2.45 KB
/
FrameBufferBuilder.cpp
File metadata and controls
94 lines (72 loc) · 2.45 KB
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
#include"FrameBufferBuilder.h"
FrameBufferBuilder::FrameBufferBuilder(VkDevice& d)
{
device = d;
}
std::shared_ptr<FrameBufferBuilder> FrameBufferBuilder::initProperty()
{
property.initProperty();
return shared_from_this();
}
FrameBufferProperty FrameBufferBuilder::Build()
{
return property;
}
void FrameBufferBuilder::Create(VkFramebuffer& frameBuffer, const FrameBufferProperty& property)
{
VkFramebufferCreateInfo info = property.info;
info.attachmentCount = static_cast<uint32_t>(property.texture.size());
std::vector<VkImageView> attachments(property.getAttachmentSize());
int index = 0;
for(int i = 0;i < property.texture.size(); i++)
{
for (int j = 0; j < property.targetLayerIndex[i].size(); j++)
{
attachments[index] = property.texture[i]->viewArray[property.targetLayerIndex[i][j]];
index++;
}
}
info.pAttachments = attachments.data();
if (vkCreateFramebuffer(device, &info, nullptr, &frameBuffer) != VK_SUCCESS)
{
throw std::runtime_error("FrameBufferBuilder : Create() : フレームバッファの作成に失敗");
}
}
//フレームバッファの幅と高さを設定する
std::shared_ptr<FrameBufferBuilder> FrameBufferBuilder::withWidthHeight(const uint32_t& width, const uint32_t& height)
{
property.info.width = width;
property.info.height = height;
return shared_from_this();
}
//レンダーパスを設定する
std::shared_ptr<FrameBufferBuilder> FrameBufferBuilder::withRenderPass(const std::shared_ptr<RenderPass> renderPass)
{
property.renderPass = renderPass;
property.info.renderPass = renderPass->renderPass;
return shared_from_this();
}
//VkImageViewを積み上げる、この時テクスチャのどのレイヤーのビューを対象にするかも設定する
std::shared_ptr<FrameBufferBuilder> FrameBufferBuilder::addViewAttachment(const std::shared_ptr<Texture> texture)
{
property.targetLayerIndex.push_back({ 0 });
property.texture.push_back(texture);
return shared_from_this();
}
std::shared_ptr<FrameBufferBuilder> FrameBufferBuilder::addViewAttachment(const std::shared_ptr<Texture> texture, const uint32_t baseViewIndex, const uint32_t viewCount)
{
std::vector<uint32_t> indexArray(viewCount);
for (int i = 0; i < viewCount; i++)
{
indexArray[i] = baseViewIndex + i;
}
property.targetLayerIndex.push_back(indexArray);
property.texture.push_back(texture);
return shared_from_this();
}
//レイヤー数を設定する
std::shared_ptr<FrameBufferBuilder> FrameBufferBuilder::withLayerCount(const uint32_t& layerCount)
{
property.info.layers = layerCount;
return shared_from_this();
}