Compare commits
No commits in common. "master" and "v0.2" have entirely different histories.
|
@ -13,7 +13,6 @@ class Vulkan
|
||||||
public:
|
public:
|
||||||
void init(GLFWwindow* window); // инициализация
|
void init(GLFWwindow* window); // инициализация
|
||||||
void destroy(); // завершение работы
|
void destroy(); // завершение работы
|
||||||
void renderFrame(); // рендер кадра
|
|
||||||
private:
|
private:
|
||||||
VkInstance instance; // Экземпляр Vulkan
|
VkInstance instance; // Экземпляр Vulkan
|
||||||
PhysicalDevice physicalDevice; // Физическое устройство
|
PhysicalDevice physicalDevice; // Физическое устройство
|
||||||
|
@ -36,7 +35,6 @@ class Vulkan
|
||||||
std::vector<VkSemaphore> imageAvailableSemaphores; // семафор доступности изображения
|
std::vector<VkSemaphore> imageAvailableSemaphores; // семафор доступности изображения
|
||||||
std::vector<VkSemaphore> renderFinishedSemaphores; // семафор окончания рендера
|
std::vector<VkSemaphore> renderFinishedSemaphores; // семафор окончания рендера
|
||||||
std::vector<VkFence> inWorkFences; // барьер кадра в работе
|
std::vector<VkFence> inWorkFences; // барьер кадра в работе
|
||||||
uint32_t currentFrame = 0; // Текущий кадр рендера
|
|
||||||
|
|
||||||
// Структура для хранения флагов
|
// Структура для хранения флагов
|
||||||
struct
|
struct
|
||||||
|
|
|
@ -30,7 +30,6 @@ int main(int argc, char* argv[]) {
|
||||||
while(!glfwWindowShouldClose(window)) {
|
while(!glfwWindowShouldClose(window)) {
|
||||||
// Обработка событий
|
// Обработка событий
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
vulkan.renderFrame();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Уничтожение окна
|
// Уничтожение окна
|
||||||
|
|
88
src/vk.cpp
88
src/vk.cpp
|
@ -991,91 +991,3 @@ void Vulkan::createFramebuffers()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Рендер кадра
|
|
||||||
void Vulkan::renderFrame()
|
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Unable to acquire swap chain image");
|
|
||||||
}
|
|
||||||
|
|
||||||
vkResetCommandBuffer(commandBuffers[currentFrame], 0);
|
|
||||||
VkCommandBufferBeginInfo beginInfo{};
|
|
||||||
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
|
||||||
|
|
||||||
if (vkBeginCommandBuffer(commandBuffers[currentFrame], &beginInfo) != VK_SUCCESS)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Unable to begin recording command buffer");
|
|
||||||
}
|
|
||||||
|
|
||||||
VkClearValue clearColor = {0.0f, 0.0f, 0.0f, 1.0f};
|
|
||||||
|
|
||||||
VkRenderPassBeginInfo renderPassInfo{};
|
|
||||||
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
|
||||||
renderPassInfo.renderPass = renderPass;
|
|
||||||
renderPassInfo.framebuffer = swapChainFramebuffers[imageIndex];
|
|
||||||
renderPassInfo.renderArea.offset = {0, 0};
|
|
||||||
renderPassInfo.renderArea.extent = surface.selectedExtent;
|
|
||||||
renderPassInfo.clearValueCount = 1;
|
|
||||||
renderPassInfo.pClearValues = &clearColor;
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
vkCmdEndRenderPass(commandBuffers[currentFrame]);
|
|
||||||
|
|
||||||
if (vkEndCommandBuffer(commandBuffers[currentFrame]) != VK_SUCCESS)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Unable to record command buffer");
|
|
||||||
}
|
|
||||||
|
|
||||||
VkSemaphore waitSemaphores[] = {imageAvailableSemaphores[currentFrame]};
|
|
||||||
VkPipelineStageFlags waitStages[] = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT};
|
|
||||||
VkSemaphore signalSemaphores[] = {renderFinishedSemaphores[currentFrame]};
|
|
||||||
|
|
||||||
VkSubmitInfo submitInfo{};
|
|
||||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
|
||||||
submitInfo.waitSemaphoreCount = 1;
|
|
||||||
submitInfo.pWaitSemaphores = waitSemaphores;
|
|
||||||
submitInfo.pWaitDstStageMask = waitStages;
|
|
||||||
submitInfo.commandBufferCount = 1;
|
|
||||||
submitInfo.pCommandBuffers = &commandBuffers[currentFrame];
|
|
||||||
submitInfo.signalSemaphoreCount = 1;
|
|
||||||
submitInfo.pSignalSemaphores = signalSemaphores;
|
|
||||||
|
|
||||||
if (vkQueueSubmit(queue.descriptor, 1, &submitInfo, inWorkFences[currentFrame]) != VK_SUCCESS)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Unable to submit draw command buffer");
|
|
||||||
}
|
|
||||||
|
|
||||||
currentFrame = (currentFrame + 1) % surface.imageCount;
|
|
||||||
|
|
||||||
VkPresentInfoKHR presentInfo{};
|
|
||||||
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
|
||||||
presentInfo.waitSemaphoreCount = 1;
|
|
||||||
presentInfo.pWaitSemaphores = signalSemaphores;
|
|
||||||
presentInfo.swapchainCount = 1;
|
|
||||||
presentInfo.pSwapchains = &swapChain;
|
|
||||||
presentInfo.pImageIndices = &imageIndex;
|
|
||||||
|
|
||||||
if (vkQueuePresentKHR(queue.descriptor, &presentInfo) != VK_SUCCESS)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Unable to present swap chain image");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue