|
|
@ -106,38 +106,38 @@ void Application::recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t im |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Application::drawFrame() { |
|
|
|
void Application::drawFrame() { |
|
|
|
vkWaitForFences(Instance::instance->device, 1, &inFlightFences[currentFrame], VK_TRUE, UINT64_MAX); |
|
|
|
vkWaitForFences(Instance::instance->device, 1, &inFlightFence, VK_TRUE, UINT64_MAX); |
|
|
|
|
|
|
|
|
|
|
|
uint32_t imageIndex; |
|
|
|
uint32_t imageIndex; |
|
|
|
VkResult result = vkAcquireNextImageKHR(Instance::instance->device, swapchain->handle, UINT64_MAX, imageAvailableSemaphores[currentFrame], VK_NULL_HANDLE, &imageIndex); |
|
|
|
VkResult result = vkAcquireNextImageKHR(Instance::instance->device, swapchain->handle, UINT64_MAX, imageAvailableSemaphore, VK_NULL_HANDLE, &imageIndex); |
|
|
|
if (result == VK_ERROR_OUT_OF_DATE_KHR){ |
|
|
|
if (result == VK_ERROR_OUT_OF_DATE_KHR){ |
|
|
|
swapchain->recreateSwapchain(); |
|
|
|
swapchain->recreateSwapchain(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
vkResetFences(Instance::instance->device, 1, &inFlightFences[currentFrame]); |
|
|
|
vkResetFences(Instance::instance->device, 1, &inFlightFence); |
|
|
|
|
|
|
|
|
|
|
|
vkResetCommandBuffer(commandPool->buffers[currentFrame], 0); |
|
|
|
vkResetCommandBuffer(commandPool->buffer, 0); |
|
|
|
recordCommandBuffer(commandPool->buffers[currentFrame], imageIndex); |
|
|
|
recordCommandBuffer(commandPool->buffer, imageIndex); |
|
|
|
|
|
|
|
|
|
|
|
updateUniformBuffer(); |
|
|
|
updateUniformBuffer(); |
|
|
|
|
|
|
|
|
|
|
|
VkSubmitInfo submitInfo {}; |
|
|
|
VkSubmitInfo submitInfo {}; |
|
|
|
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
|
|
|
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
|
|
|
|
|
|
|
|
|
|
|
VkSemaphore waitSemaphores[] = {imageAvailableSemaphores[currentFrame]}; |
|
|
|
VkSemaphore waitSemaphores[] = {imageAvailableSemaphore}; |
|
|
|
VkPipelineStageFlags waitStages[] = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT}; |
|
|
|
VkPipelineStageFlags waitStages[] = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT}; |
|
|
|
submitInfo.waitSemaphoreCount = 1; |
|
|
|
submitInfo.waitSemaphoreCount = 1; |
|
|
|
submitInfo.pWaitSemaphores = waitSemaphores; |
|
|
|
submitInfo.pWaitSemaphores = waitSemaphores; |
|
|
|
submitInfo.pWaitDstStageMask = waitStages; |
|
|
|
submitInfo.pWaitDstStageMask = waitStages; |
|
|
|
submitInfo.commandBufferCount = 1; |
|
|
|
submitInfo.commandBufferCount = 1; |
|
|
|
submitInfo.pCommandBuffers = &commandPool->buffers[currentFrame]; |
|
|
|
submitInfo.pCommandBuffers = &commandPool->buffer; |
|
|
|
|
|
|
|
|
|
|
|
VkSemaphore signalSemaphores[] = {renderFinishedSemaphores[currentFrame]}; |
|
|
|
VkSemaphore signalSemaphores[] = {renderFinishedSemaphore}; |
|
|
|
submitInfo.signalSemaphoreCount = 1; |
|
|
|
submitInfo.signalSemaphoreCount = 1; |
|
|
|
submitInfo.pSignalSemaphores = signalSemaphores; |
|
|
|
submitInfo.pSignalSemaphores = signalSemaphores; |
|
|
|
|
|
|
|
|
|
|
|
vkQueueSubmit(Instance::instance->graphicsQueue, 1, &submitInfo, inFlightFences[currentFrame]); |
|
|
|
vkQueueSubmit(Instance::instance->graphicsQueue, 1, &submitInfo, inFlightFence); |
|
|
|
|
|
|
|
|
|
|
|
VkPresentInfoKHR presentInfo {}; |
|
|
|
VkPresentInfoKHR presentInfo {}; |
|
|
|
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; |
|
|
|
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; |
|
|
@ -154,15 +154,9 @@ void Application::drawFrame() { |
|
|
|
swapchain->recreateSwapchain(); |
|
|
|
swapchain->recreateSwapchain(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Application::createSyncObjects() { |
|
|
|
void Application::createSyncObjects() { |
|
|
|
imageAvailableSemaphores.resize(MAX_FRAMES_IN_FLIGHT); |
|
|
|
|
|
|
|
renderFinishedSemaphores.resize(MAX_FRAMES_IN_FLIGHT); |
|
|
|
|
|
|
|
inFlightFences.resize(MAX_FRAMES_IN_FLIGHT); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VkSemaphoreCreateInfo semaphoreInfo {}; |
|
|
|
VkSemaphoreCreateInfo semaphoreInfo {}; |
|
|
|
semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
|
|
|
semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
|
|
|
|
|
|
|
|
|
|
@ -170,11 +164,9 @@ void Application::createSyncObjects() { |
|
|
|
fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
|
|
|
fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; |
|
|
|
fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; |
|
|
|
fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; |
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++){ |
|
|
|
vkCreateSemaphore(Instance::instance->device, &semaphoreInfo, nullptr, &imageAvailableSemaphore); |
|
|
|
vkCreateSemaphore(Instance::instance->device, &semaphoreInfo, nullptr, &imageAvailableSemaphores[i]); |
|
|
|
vkCreateSemaphore(Instance::instance->device, &semaphoreInfo, nullptr, &renderFinishedSemaphore); |
|
|
|
vkCreateSemaphore(Instance::instance->device, &semaphoreInfo, nullptr, &renderFinishedSemaphores[i]); |
|
|
|
vkCreateFence(Instance::instance->device, &fenceInfo, nullptr, &inFlightFence); |
|
|
|
vkCreateFence(Instance::instance->device, &fenceInfo, nullptr, &inFlightFences[i]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Application::mainLoop() { |
|
|
|
void Application::mainLoop() { |
|
|
@ -187,11 +179,9 @@ void Application::mainLoop() { |
|
|
|
|
|
|
|
|
|
|
|
Application::~Application() { |
|
|
|
Application::~Application() { |
|
|
|
delete swapchain; |
|
|
|
delete swapchain; |
|
|
|
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++){ |
|
|
|
vkDestroySemaphore(Instance::instance->device, imageAvailableSemaphore, nullptr); |
|
|
|
vkDestroySemaphore(Instance::instance->device, imageAvailableSemaphores[i], nullptr); |
|
|
|
vkDestroySemaphore(Instance::instance->device, renderFinishedSemaphore, nullptr); |
|
|
|
vkDestroySemaphore(Instance::instance->device, renderFinishedSemaphores[i], nullptr); |
|
|
|
vkDestroyFence(Instance::instance->device, inFlightFence, nullptr); |
|
|
|
vkDestroyFence(Instance::instance->device, inFlightFences[i], nullptr); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
delete commandPool; |
|
|
|
delete commandPool; |
|
|
|
delete vertexBuffer; |
|
|
|
delete vertexBuffer; |
|
|
|
delete indexBuffer; |
|
|
|
delete indexBuffer; |
|
|
|