Minor code cleanup
This commit is contained in:
parent
922eaecdc0
commit
93fb200fe6
1 changed files with 25 additions and 26 deletions
|
|
@ -220,8 +220,7 @@ public:
|
||||||
// what should be done a real-world application, where you should allocate large chunks of memory at once instead.
|
// what should be done a real-world application, where you should allocate large chunks of memory at once instead.
|
||||||
|
|
||||||
// Setup vertices
|
// Setup vertices
|
||||||
std::vector<Vertex> vertexBuffer =
|
std::vector<Vertex> vertexBuffer{
|
||||||
{
|
|
||||||
{ { 1.0f, 1.0f, 0.0f }, { 1.0f, 0.0f, 0.0f } },
|
{ { 1.0f, 1.0f, 0.0f }, { 1.0f, 0.0f, 0.0f } },
|
||||||
{ { -1.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f } },
|
{ { -1.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f } },
|
||||||
{ { 0.0f, -1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } }
|
{ { 0.0f, -1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } }
|
||||||
|
|
@ -229,11 +228,11 @@ public:
|
||||||
uint32_t vertexBufferSize = static_cast<uint32_t>(vertexBuffer.size()) * sizeof(Vertex);
|
uint32_t vertexBufferSize = static_cast<uint32_t>(vertexBuffer.size()) * sizeof(Vertex);
|
||||||
|
|
||||||
// Setup indices
|
// Setup indices
|
||||||
std::vector<uint32_t> indexBuffer = { 0, 1, 2 };
|
std::vector<uint32_t> indexBuffer{ 0, 1, 2 };
|
||||||
indices.count = static_cast<uint32_t>(indexBuffer.size());
|
indices.count = static_cast<uint32_t>(indexBuffer.size());
|
||||||
uint32_t indexBufferSize = indices.count * sizeof(uint32_t);
|
uint32_t indexBufferSize = indices.count * sizeof(uint32_t);
|
||||||
|
|
||||||
VkMemoryAllocateInfo memAlloc = {};
|
VkMemoryAllocateInfo memAlloc{};
|
||||||
memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||||
VkMemoryRequirements memReqs;
|
VkMemoryRequirements memReqs;
|
||||||
|
|
||||||
|
|
@ -320,7 +319,7 @@ public:
|
||||||
// Note: Some devices offer a dedicated transfer queue (with only the transfer bit set) that may be faster when doing lots of copies
|
// Note: Some devices offer a dedicated transfer queue (with only the transfer bit set) that may be faster when doing lots of copies
|
||||||
VkCommandBuffer copyCmd;
|
VkCommandBuffer copyCmd;
|
||||||
|
|
||||||
VkCommandBufferAllocateInfo cmdBufAllocateInfo = {};
|
VkCommandBufferAllocateInfo cmdBufAllocateInfo{};
|
||||||
cmdBufAllocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
cmdBufAllocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||||
cmdBufAllocateInfo.commandPool = commandPool;
|
cmdBufAllocateInfo.commandPool = commandPool;
|
||||||
cmdBufAllocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
cmdBufAllocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||||
|
|
@ -330,7 +329,7 @@ public:
|
||||||
VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo();
|
VkCommandBufferBeginInfo cmdBufInfo = vks::initializers::commandBufferBeginInfo();
|
||||||
VK_CHECK_RESULT(vkBeginCommandBuffer(copyCmd, &cmdBufInfo));
|
VK_CHECK_RESULT(vkBeginCommandBuffer(copyCmd, &cmdBufInfo));
|
||||||
// Put buffer region copies into command buffer
|
// Put buffer region copies into command buffer
|
||||||
VkBufferCopy copyRegion = {};
|
VkBufferCopy copyRegion{};
|
||||||
// Vertex buffer
|
// Vertex buffer
|
||||||
copyRegion.size = vertexBufferSize;
|
copyRegion.size = vertexBufferSize;
|
||||||
vkCmdCopyBuffer(copyCmd, stagingBuffers.vertices.buffer, vertices.buffer, 1, ©Region);
|
vkCmdCopyBuffer(copyCmd, stagingBuffers.vertices.buffer, vertices.buffer, 1, ©Region);
|
||||||
|
|
@ -340,7 +339,7 @@ public:
|
||||||
VK_CHECK_RESULT(vkEndCommandBuffer(copyCmd));
|
VK_CHECK_RESULT(vkEndCommandBuffer(copyCmd));
|
||||||
|
|
||||||
// Submit the command buffer to the queue to finish the copy
|
// Submit the command buffer to the queue to finish the copy
|
||||||
VkSubmitInfo submitInfo = {};
|
VkSubmitInfo submitInfo{};
|
||||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||||
submitInfo.commandBufferCount = 1;
|
submitInfo.commandBufferCount = 1;
|
||||||
submitInfo.pCommandBuffers = ©Cmd;
|
submitInfo.pCommandBuffers = ©Cmd;
|
||||||
|
|
@ -430,7 +429,7 @@ public:
|
||||||
{
|
{
|
||||||
// Allocate one descriptor set per frame from the global descriptor pool
|
// Allocate one descriptor set per frame from the global descriptor pool
|
||||||
for (uint32_t i = 0; i < MAX_CONCURRENT_FRAMES; i++) {
|
for (uint32_t i = 0; i < MAX_CONCURRENT_FRAMES; i++) {
|
||||||
VkDescriptorSetAllocateInfo allocInfo = {};
|
VkDescriptorSetAllocateInfo allocInfo{};
|
||||||
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
||||||
allocInfo.descriptorPool = descriptorPool;
|
allocInfo.descriptorPool = descriptorPool;
|
||||||
allocInfo.descriptorSetCount = 1;
|
allocInfo.descriptorSetCount = 1;
|
||||||
|
|
@ -440,7 +439,7 @@ public:
|
||||||
// Update the descriptor set determining the shader binding points
|
// Update the descriptor set determining the shader binding points
|
||||||
// For every binding point used in a shader there needs to be one
|
// For every binding point used in a shader there needs to be one
|
||||||
// descriptor set matching that binding point
|
// descriptor set matching that binding point
|
||||||
VkWriteDescriptorSet writeDescriptorSet = {};
|
VkWriteDescriptorSet writeDescriptorSet{};
|
||||||
|
|
||||||
// The buffer's information is passed using a descriptor info structure
|
// The buffer's information is passed using a descriptor info structure
|
||||||
VkDescriptorBufferInfo bufferInfo{};
|
VkDescriptorBufferInfo bufferInfo{};
|
||||||
|
|
@ -546,7 +545,7 @@ public:
|
||||||
// This example will use a single render pass with one subpass
|
// This example will use a single render pass with one subpass
|
||||||
|
|
||||||
// Descriptors for the attachments used by this renderpass
|
// Descriptors for the attachments used by this renderpass
|
||||||
std::array<VkAttachmentDescription, 2> attachments = {};
|
std::array<VkAttachmentDescription, 2> attachments{};
|
||||||
|
|
||||||
// Color attachment
|
// Color attachment
|
||||||
attachments[0].format = swapChain.colorFormat; // Use the color format selected by the swapchain
|
attachments[0].format = swapChain.colorFormat; // Use the color format selected by the swapchain
|
||||||
|
|
@ -569,16 +568,16 @@ public:
|
||||||
attachments[1].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; // Transition to depth/stencil attachment
|
attachments[1].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; // Transition to depth/stencil attachment
|
||||||
|
|
||||||
// Setup attachment references
|
// Setup attachment references
|
||||||
VkAttachmentReference colorReference = {};
|
VkAttachmentReference colorReference{};
|
||||||
colorReference.attachment = 0; // Attachment 0 is color
|
colorReference.attachment = 0; // Attachment 0 is color
|
||||||
colorReference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; // Attachment layout used as color during the subpass
|
colorReference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; // Attachment layout used as color during the subpass
|
||||||
|
|
||||||
VkAttachmentReference depthReference = {};
|
VkAttachmentReference depthReference{};
|
||||||
depthReference.attachment = 1; // Attachment 1 is color
|
depthReference.attachment = 1; // Attachment 1 is color
|
||||||
depthReference.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; // Attachment used as depth/stencil used during the subpass
|
depthReference.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; // Attachment used as depth/stencil used during the subpass
|
||||||
|
|
||||||
// Setup a single subpass reference
|
// Setup a single subpass reference
|
||||||
VkSubpassDescription subpassDescription = {};
|
VkSubpassDescription subpassDescription{};
|
||||||
subpassDescription.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
subpassDescription.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||||
subpassDescription.colorAttachmentCount = 1; // Subpass uses one color attachment
|
subpassDescription.colorAttachmentCount = 1; // Subpass uses one color attachment
|
||||||
subpassDescription.pColorAttachments = &colorReference; // Reference to the color attachment in slot 0
|
subpassDescription.pColorAttachments = &colorReference; // Reference to the color attachment in slot 0
|
||||||
|
|
@ -716,13 +715,13 @@ public:
|
||||||
|
|
||||||
// Color blend state describes how blend factors are calculated (if used)
|
// Color blend state describes how blend factors are calculated (if used)
|
||||||
// We need one blend attachment state per color attachment (even if blending is not used)
|
// We need one blend attachment state per color attachment (even if blending is not used)
|
||||||
VkPipelineColorBlendAttachmentState blendAttachmentState[1] = {};
|
VkPipelineColorBlendAttachmentState blendAttachmentState{};
|
||||||
blendAttachmentState[0].colorWriteMask = 0xf;
|
blendAttachmentState.colorWriteMask = 0xf;
|
||||||
blendAttachmentState[0].blendEnable = VK_FALSE;
|
blendAttachmentState.blendEnable = VK_FALSE;
|
||||||
VkPipelineColorBlendStateCreateInfo colorBlendStateCI{};
|
VkPipelineColorBlendStateCreateInfo colorBlendStateCI{};
|
||||||
colorBlendStateCI.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
|
colorBlendStateCI.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
|
||||||
colorBlendStateCI.attachmentCount = 1;
|
colorBlendStateCI.attachmentCount = 1;
|
||||||
colorBlendStateCI.pAttachments = blendAttachmentState;
|
colorBlendStateCI.pAttachments = &blendAttachmentState;
|
||||||
|
|
||||||
// Viewport state sets the number of viewports and scissor used in this pipeline
|
// Viewport state sets the number of viewports and scissor used in this pipeline
|
||||||
// Note: This is actually overridden by the dynamic states (see below)
|
// Note: This is actually overridden by the dynamic states (see below)
|
||||||
|
|
@ -852,8 +851,8 @@ public:
|
||||||
VkMemoryRequirements memReqs;
|
VkMemoryRequirements memReqs;
|
||||||
|
|
||||||
// Vertex shader uniform buffer block
|
// Vertex shader uniform buffer block
|
||||||
VkBufferCreateInfo bufferInfo = {};
|
VkBufferCreateInfo bufferInfo{};
|
||||||
VkMemoryAllocateInfo allocInfo = {};
|
VkMemoryAllocateInfo allocInfo{};
|
||||||
allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||||
allocInfo.pNext = nullptr;
|
allocInfo.pNext = nullptr;
|
||||||
allocInfo.allocationSize = 0;
|
allocInfo.allocationSize = 0;
|
||||||
|
|
@ -937,7 +936,7 @@ public:
|
||||||
|
|
||||||
vkResetCommandBuffer(commandBuffers[currentBuffer], 0);
|
vkResetCommandBuffer(commandBuffers[currentBuffer], 0);
|
||||||
|
|
||||||
VkCommandBufferBeginInfo cmdBufInfo = {};
|
VkCommandBufferBeginInfo cmdBufInfo{};
|
||||||
cmdBufInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
cmdBufInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||||
|
|
||||||
// Set clear values for all framebuffer attachments with loadOp set to clear
|
// Set clear values for all framebuffer attachments with loadOp set to clear
|
||||||
|
|
@ -946,7 +945,7 @@ public:
|
||||||
clearValues[0].color = { { 0.0f, 0.0f, 0.2f, 1.0f } };
|
clearValues[0].color = { { 0.0f, 0.0f, 0.2f, 1.0f } };
|
||||||
clearValues[1].depthStencil = { 1.0f, 0 };
|
clearValues[1].depthStencil = { 1.0f, 0 };
|
||||||
|
|
||||||
VkRenderPassBeginInfo renderPassBeginInfo = {};
|
VkRenderPassBeginInfo renderPassBeginInfo{};
|
||||||
renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
renderPassBeginInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
||||||
renderPassBeginInfo.pNext = nullptr;
|
renderPassBeginInfo.pNext = nullptr;
|
||||||
renderPassBeginInfo.renderPass = renderPass;
|
renderPassBeginInfo.renderPass = renderPass;
|
||||||
|
|
@ -963,14 +962,14 @@ public:
|
||||||
// This will clear the color and depth attachment
|
// This will clear the color and depth attachment
|
||||||
vkCmdBeginRenderPass(commandBuffers[currentBuffer], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
vkCmdBeginRenderPass(commandBuffers[currentBuffer], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||||
// Update dynamic viewport state
|
// Update dynamic viewport state
|
||||||
VkViewport viewport = {};
|
VkViewport viewport{};
|
||||||
viewport.height = (float)height;
|
viewport.height = (float)height;
|
||||||
viewport.width = (float)width;
|
viewport.width = (float)width;
|
||||||
viewport.minDepth = (float)0.0f;
|
viewport.minDepth = (float)0.0f;
|
||||||
viewport.maxDepth = (float)1.0f;
|
viewport.maxDepth = (float)1.0f;
|
||||||
vkCmdSetViewport(commandBuffers[currentBuffer], 0, 1, &viewport);
|
vkCmdSetViewport(commandBuffers[currentBuffer], 0, 1, &viewport);
|
||||||
// Update dynamic scissor state
|
// Update dynamic scissor state
|
||||||
VkRect2D scissor = {};
|
VkRect2D scissor{};
|
||||||
scissor.extent.width = width;
|
scissor.extent.width = width;
|
||||||
scissor.extent.height = height;
|
scissor.extent.height = height;
|
||||||
scissor.offset.x = 0;
|
scissor.offset.x = 0;
|
||||||
|
|
@ -982,7 +981,7 @@ public:
|
||||||
// The pipeline (state object) contains all states of the rendering pipeline, binding it will set all the states specified at pipeline creation time
|
// The pipeline (state object) contains all states of the rendering pipeline, binding it will set all the states specified at pipeline creation time
|
||||||
vkCmdBindPipeline(commandBuffers[currentBuffer], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
|
vkCmdBindPipeline(commandBuffers[currentBuffer], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
|
||||||
// Bind triangle vertex buffer (contains position and colors)
|
// Bind triangle vertex buffer (contains position and colors)
|
||||||
VkDeviceSize offsets[1] = { 0 };
|
VkDeviceSize offsets[1]{ 0 };
|
||||||
vkCmdBindVertexBuffers(commandBuffers[currentBuffer], 0, 1, &vertices.buffer, offsets);
|
vkCmdBindVertexBuffers(commandBuffers[currentBuffer], 0, 1, &vertices.buffer, offsets);
|
||||||
// Bind triangle index buffer
|
// Bind triangle index buffer
|
||||||
vkCmdBindIndexBuffer(commandBuffers[currentBuffer], indices.buffer, 0, VK_INDEX_TYPE_UINT32);
|
vkCmdBindIndexBuffer(commandBuffers[currentBuffer], indices.buffer, 0, VK_INDEX_TYPE_UINT32);
|
||||||
|
|
@ -998,7 +997,7 @@ public:
|
||||||
// Pipeline stage at which the queue submission will wait (via pWaitSemaphores)
|
// Pipeline stage at which the queue submission will wait (via pWaitSemaphores)
|
||||||
VkPipelineStageFlags waitStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
VkPipelineStageFlags waitStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||||
// The submit info structure specifies a command buffer queue submission batch
|
// The submit info structure specifies a command buffer queue submission batch
|
||||||
VkSubmitInfo submitInfo = {};
|
VkSubmitInfo submitInfo{};
|
||||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||||
submitInfo.pWaitDstStageMask = &waitStageMask; // Pointer to the list of pipeline stages that the semaphore waits will occur at
|
submitInfo.pWaitDstStageMask = &waitStageMask; // Pointer to the list of pipeline stages that the semaphore waits will occur at
|
||||||
submitInfo.waitSemaphoreCount = 1; // One wait semaphore
|
submitInfo.waitSemaphoreCount = 1; // One wait semaphore
|
||||||
|
|
@ -1037,7 +1036,7 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// OS specific macros for the example main entry points
|
// OS specific main entry points
|
||||||
// Most of the code base is shared for the different supported operating systems, but stuff like message handling differs
|
// Most of the code base is shared for the different supported operating systems, but stuff like message handling differs
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue