New Framebuffers and Command Buffers
Most part of RenderImpl
is similar to EmptyScene::RenderImpl
except for an extra _depthView
added to the framebuffer attachments.
In BuildCommandBuffer
, we add { 1.0f, 0 } of type VkClearDepthStencilValue
when we begin a render pass instance.
And inside the render pass instance, we bind the _pipeline
since it affects all the subsequent graphics and compute commands until a different pipeline is bound.
Next, we bind one vertex buffer on binding number 0 with no offsets in the buffer. The binding number 0 is identical to VkVertexInputBindingDescription::binding
as we mentioned in the previous post. Having a vertex buffer means we should bind an index buffer for vertex traversal. VK_INDEX_TYPE_UINT32
argument of vkCmdBindIndexBuffer
should match the data type of index data we upload to GPU in ModelResource::UploadToGPU
.
Then, vkCmdBindDescriptorSets
causes the sets numbered 0 to use the first binding stored in pDescriptorSets
for subsequent rendering commands (either compute or graphics, according to the pipelineBindPoint
).
We know vkCmdBindDescriptorSets
is able to bind multiple descriptor sets when inspecting the function signature, and in this case, we can specify the set number at layout qualifier in shader code.
layout(set = 0, binding = 0) uniform Foo {…}
layout(set = 1, binding = 0) uniform sampler2D fooSampler;
But in our case, we have only one descriptor set so we can just ignore it.
Finally, vkCmdDrawIndexed
draw the primitives one time with no vertex offsets.
Update Uniform Buffer
EarthSceneRenderer::UpdateMVP
is called every updating frame and sets values of a MVP
variable and copy the data to the address _buffers[0].mapped
points to. Note we multiply -1 to the entry of mvp.projection[1][1]
which inverts the y coordinate of the multiplicand vector because of Vulkan having a top-left coordinate system.
Clean Up and Orientation Change
The clean-up is simple: what we create/allocate in the constructor should be destroyed/freed in the destructor. And when screen orientation changes, swapchain and all its dependencies should be recreated.