-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRenderpass.cpp
101 lines (86 loc) · 3.24 KB
/
Renderpass.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
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
#include "Renderpass.h"
namespace MelonRenderer
{
Renderpass::Renderpass(Swapchain* swapchain)
{
m_swapchain = swapchain;
VkAttachmentDescription colorAttachment = {};
colorAttachment.format = VK_FORMAT_B8G8R8A8_UNORM; //TODO: parameter
colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD; //TODO: parameter for clear before rasterization
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
colorAttachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
colorAttachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
colorAttachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
colorAttachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
//default color attachment is always attachment 0
m_attachments.emplace_back(colorAttachment);
VkClearValue colorClearValue = {};
colorClearValue.color.float32[0] = 0.f;
colorClearValue.color.float32[1] = 0.4531f;
colorClearValue.color.float32[2] = 0.78125f;
colorClearValue.color.float32[3] = 0.f;
m_clearValues.emplace_back(colorClearValue);
}
bool Renderpass::CreateRenderpass()
{
VkRenderPassCreateInfo renderPassInfo = {};
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
renderPassInfo.attachmentCount = m_attachments.size();
renderPassInfo.pAttachments = m_attachments.data();
renderPassInfo.subpassCount = m_subpasses.size();
renderPassInfo.pSubpasses = m_subpasses.data();
renderPassInfo.dependencyCount = m_subpassDependencies.size();
renderPassInfo.pDependencies = m_subpassDependencies.data();
VkResult result = vkCreateRenderPass(Device::Get().m_device, &renderPassInfo, nullptr, &m_renderpass);
if (result != VK_SUCCESS)
{
Logger::Log("Could not create renderpass.");
return false;
}
return true;
}
bool Renderpass::BeginRenderpass(VkCommandBuffer& commandBuffer)
{
VkRenderPassBeginInfo renderPassBegin = {};
renderPassBegin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
renderPassBegin.pNext = nullptr;
renderPassBegin.renderPass = m_renderpass;
renderPassBegin.framebuffer = m_swapchain->GetFramebuffer();
renderPassBegin.renderArea.offset.x = 0;
renderPassBegin.renderArea.offset.y = 0;
renderPassBegin.renderArea.extent = m_swapchain->GetExtent();
renderPassBegin.clearValueCount = m_clearValues.size();
renderPassBegin.pClearValues = m_clearValues.data();
vkCmdBeginRenderPass(commandBuffer, &renderPassBegin, VK_SUBPASS_CONTENTS_INLINE);
return true;
}
bool Renderpass::EndRenderpass(VkCommandBuffer& commandBuffer)
{
vkCmdEndRenderPass(commandBuffer);
return true;
}
uint32_t Renderpass::AddAttachment(VkAttachmentDescription& attachment, VkClearValue& clearValue)
{
m_attachments.emplace_back(attachment);
m_clearValues.emplace_back(clearValue);
return m_attachments.size() - 1;
}
uint32_t Renderpass::AddSubpass(VkSubpassDescription& subpass)
{
m_subpasses.emplace_back(subpass);
return m_subpasses.size() - 1;
}
void Renderpass::AddSubpassDependency(VkSubpassDependency& subpassDependency)
{
m_subpassDependencies.emplace_back(subpassDependency);
}
VkRenderPass* Renderpass::GetVkRenderpass()
{
return &m_renderpass;
}
VkAttachmentDescription* Renderpass::GetColorAttachmentPointer()
{
return &m_attachments[0];
}
}