|
@@ -436,9 +436,9 @@ void Graphics::present(void *screenshotCallbackdata)
|
|
|
|
|
|
VkResult result = vkQueuePresentKHR(presentQueue, &presentInfo);
|
|
VkResult result = vkQueuePresentKHR(presentQueue, &presentInfo);
|
|
|
|
|
|
- if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || framebufferResized)
|
|
|
|
|
|
+ if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || swapChainRecreationRequested)
|
|
{
|
|
{
|
|
- framebufferResized = false;
|
|
|
|
|
|
+ swapChainRecreationRequested = false;
|
|
recreateSwapChain();
|
|
recreateSwapChain();
|
|
}
|
|
}
|
|
else if (result != VK_SUCCESS)
|
|
else if (result != VK_SUCCESS)
|
|
@@ -463,6 +463,9 @@ void Graphics::present(void *screenshotCallbackdata)
|
|
|
|
|
|
void Graphics::setViewportSize(int width, int height, int pixelwidth, int pixelheight)
|
|
void Graphics::setViewportSize(int width, int height, int pixelwidth, int pixelheight)
|
|
{
|
|
{
|
|
|
|
+ if (swapChain != VK_NULL_HANDLE && (pixelWidth != this->pixelWidth || pixelHeight != this->pixelHeight || width != this->width || height != this->height))
|
|
|
|
+ requestSwapchainRecreation();
|
|
|
|
+
|
|
this->width = width;
|
|
this->width = width;
|
|
this->height = height;
|
|
this->height = height;
|
|
this->pixelWidth = pixelwidth;
|
|
this->pixelWidth = pixelwidth;
|
|
@@ -1772,8 +1775,6 @@ VkSurfaceFormatKHR Graphics::chooseSwapSurfaceFormat(const std::vector<VkSurface
|
|
|
|
|
|
VkPresentModeKHR Graphics::chooseSwapPresentMode(const std::vector<VkPresentModeKHR> &availablePresentModes)
|
|
VkPresentModeKHR Graphics::chooseSwapPresentMode(const std::vector<VkPresentModeKHR> &availablePresentModes)
|
|
{
|
|
{
|
|
- int vsync = Vulkan::getVsync();
|
|
|
|
-
|
|
|
|
const auto begin = availablePresentModes.begin();
|
|
const auto begin = availablePresentModes.begin();
|
|
const auto end = availablePresentModes.end();
|
|
const auto end = availablePresentModes.end();
|
|
|
|
|
|
@@ -2295,30 +2296,10 @@ void Graphics::setDefaultRenderPass()
|
|
renderPassState.msaa = msaaSamples;
|
|
renderPassState.msaa = msaaSamples;
|
|
renderPassState.numColorAttachments = 1;
|
|
renderPassState.numColorAttachments = 1;
|
|
renderPassState.transitionImages.clear();
|
|
renderPassState.transitionImages.clear();
|
|
-
|
|
|
|
- VkViewport viewport{};
|
|
|
|
- viewport.x = 0.0f;
|
|
|
|
- viewport.y = 0.0f;
|
|
|
|
- viewport.width = renderPassState.width;
|
|
|
|
- viewport.height = renderPassState.height;
|
|
|
|
- viewport.minDepth = 0.0f;
|
|
|
|
- viewport.maxDepth = 1.0f;
|
|
|
|
-
|
|
|
|
- vkCmdSetViewport(commandBuffers.at(currentFrame), 0, 1, &viewport);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void Graphics::setRenderPass(const RenderTargets &rts, int pixelw, int pixelh, bool hasSRGBtexture)
|
|
void Graphics::setRenderPass(const RenderTargets &rts, int pixelw, int pixelh, bool hasSRGBtexture)
|
|
{
|
|
{
|
|
- VkViewport viewport{};
|
|
|
|
- viewport.x = 0.0f;
|
|
|
|
- viewport.y = 0.0f;
|
|
|
|
- viewport.width = static_cast<float>(pixelw);
|
|
|
|
- viewport.height = static_cast<float>(pixelh);
|
|
|
|
- viewport.minDepth = 0.0f;
|
|
|
|
- viewport.maxDepth = 1.0f;
|
|
|
|
-
|
|
|
|
- vkCmdSetViewport(commandBuffers.at(currentFrame), 0, 1, &viewport);
|
|
|
|
-
|
|
|
|
auto currentCommandBuffer = commandBuffers.at(currentFrame);
|
|
auto currentCommandBuffer = commandBuffers.at(currentFrame);
|
|
|
|
|
|
// fixme: hasSRGBtexture
|
|
// fixme: hasSRGBtexture
|
|
@@ -2373,6 +2354,16 @@ void Graphics::startRenderPass()
|
|
{
|
|
{
|
|
renderPassState.active = true;
|
|
renderPassState.active = true;
|
|
|
|
|
|
|
|
+ VkViewport viewport{};
|
|
|
|
+ viewport.x = 0.0f;
|
|
|
|
+ viewport.y = 0.0f;
|
|
|
|
+ viewport.width = renderPassState.width;
|
|
|
|
+ viewport.height = renderPassState.height;
|
|
|
|
+ viewport.minDepth = 0.0f;
|
|
|
|
+ viewport.maxDepth = 1.0f;
|
|
|
|
+
|
|
|
|
+ vkCmdSetViewport(commandBuffers.at(currentFrame), 0, 1, &viewport);
|
|
|
|
+
|
|
if (renderPassState.useConfigurations)
|
|
if (renderPassState.useConfigurations)
|
|
{
|
|
{
|
|
auto &renderPassConfiguration = renderPassState.renderPassConfiguration;
|
|
auto &renderPassConfiguration = renderPassState.renderPassConfiguration;
|
|
@@ -2485,6 +2476,14 @@ void Graphics::cleanupUnusedObjects()
|
|
eraseUnusedObjects(graphicsPipelines, pipelineUsages, vkDestroyPipeline, device);
|
|
eraseUnusedObjects(graphicsPipelines, pipelineUsages, vkDestroyPipeline, device);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void Graphics::requestSwapchainRecreation()
|
|
|
|
+{
|
|
|
|
+ if (swapChain != VK_NULL_HANDLE)
|
|
|
|
+ {
|
|
|
|
+ swapChainRecreationRequested = true;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
void Graphics::setComputeShader(Shader *shader)
|
|
void Graphics::setComputeShader(Shader *shader)
|
|
{
|
|
{
|
|
computeShader = shader;
|
|
computeShader = shader;
|
|
@@ -2707,6 +2706,21 @@ VkSampleCountFlagBits Graphics::getMsaaCount(int requestedMsaa) const
|
|
return VK_SAMPLE_COUNT_1_BIT;
|
|
return VK_SAMPLE_COUNT_1_BIT;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void Graphics::setVsync(int vsync)
|
|
|
|
+{
|
|
|
|
+ if (vsync != this->vsync)
|
|
|
|
+ {
|
|
|
|
+ this->vsync = vsync;
|
|
|
|
+
|
|
|
|
+ requestSwapchainRecreation();
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int Graphics::getVsync() const
|
|
|
|
+{
|
|
|
|
+ return vsync;
|
|
|
|
+}
|
|
|
|
+
|
|
void Graphics::createColorResources()
|
|
void Graphics::createColorResources()
|
|
{
|
|
{
|
|
if (msaaSamples & VK_SAMPLE_COUNT_1_BIT)
|
|
if (msaaSamples & VK_SAMPLE_COUNT_1_BIT)
|
|
@@ -2947,6 +2961,8 @@ void Graphics::cleanupSwapChain()
|
|
vkDestroyImageView(device, swapChainImageView, nullptr);
|
|
vkDestroyImageView(device, swapChainImageView, nullptr);
|
|
swapChainImageViews.clear();
|
|
swapChainImageViews.clear();
|
|
vkDestroySwapchainKHR(device, swapChain, nullptr);
|
|
vkDestroySwapchainKHR(device, swapChain, nullptr);
|
|
|
|
+
|
|
|
|
+ swapChain = VK_NULL_HANDLE;
|
|
}
|
|
}
|
|
|
|
|
|
void Graphics::recreateSwapChain()
|
|
void Graphics::recreateSwapChain()
|