Разделение метода renderFrame
This commit is contained in:
33
src/vk.cpp
33
src/vk.cpp
@@ -985,11 +985,26 @@ void Vulkan::createFramebuffers()
|
||||
|
||||
// Рендер кадра
|
||||
void Vulkan::renderFrame()
|
||||
{
|
||||
renderBegin();
|
||||
|
||||
VkBuffer vertexBuffers[] = {vertexBuffer};
|
||||
VkDeviceSize offsets[] = {0};
|
||||
vkCmdBindVertexBuffers(commandBuffers[currentFrame], 0, 1, vertexBuffers, offsets);
|
||||
|
||||
vkCmdBindIndexBuffer(commandBuffers[currentFrame], indexBuffer, 0, VK_INDEX_TYPE_UINT16);
|
||||
|
||||
vkCmdDrawIndexed(commandBuffers[currentFrame], 6, 1, 0, 0, 0);
|
||||
|
||||
renderEnd();
|
||||
}
|
||||
|
||||
// Начало рендера кадра
|
||||
void Vulkan::renderBegin()
|
||||
{
|
||||
vkWaitForFences(logicalDevice, 1, &inWorkFences[currentFrame], VK_TRUE, UINT64_MAX);
|
||||
vkResetFences(logicalDevice, 1, &inWorkFences[currentFrame]);
|
||||
|
||||
uint32_t imageIndex;
|
||||
VkResult result = vkAcquireNextImageKHR(logicalDevice, swapChain, UINT64_MAX, imageAvailableSemaphores[currentFrame], VK_NULL_HANDLE, &imageIndex);
|
||||
|
||||
if (result != VK_SUCCESS)
|
||||
@@ -1019,16 +1034,12 @@ void Vulkan::renderFrame()
|
||||
|
||||
vkCmdBeginRenderPass(commandBuffers[currentFrame], &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||
|
||||
vkCmdBindPipeline(commandBuffers[currentFrame], VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline);
|
||||
|
||||
VkBuffer vertexBuffers[] = {vertexBuffer};
|
||||
VkDeviceSize offsets[] = {0};
|
||||
vkCmdBindVertexBuffers(commandBuffers[currentFrame], 0, 1, vertexBuffers, offsets);
|
||||
|
||||
vkCmdBindIndexBuffer(commandBuffers[currentFrame], indexBuffer, 0, VK_INDEX_TYPE_UINT16);
|
||||
|
||||
vkCmdDrawIndexed(commandBuffers[currentFrame], 6, 1, 0, 0, 0);
|
||||
vkCmdBindPipeline(commandBuffers[currentFrame], VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline);
|
||||
}
|
||||
|
||||
// Окончание рендера кадра
|
||||
void Vulkan::renderEnd()
|
||||
{
|
||||
vkCmdEndRenderPass(commandBuffers[currentFrame]);
|
||||
|
||||
if (vkEndCommandBuffer(commandBuffers[currentFrame]) != VK_SUCCESS)
|
||||
@@ -1069,4 +1080,4 @@ void Vulkan::renderFrame()
|
||||
{
|
||||
throw std::runtime_error("Unable to present swap chain image");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user