handle surface resize
This commit is contained in:
parent
d4c463c507
commit
ef3a1ad4af
|
@ -191,6 +191,17 @@ static VkPipeline createPipeline( void )
|
|||
.depthCompareOp = VK_COMPARE_OP_LESS,
|
||||
};
|
||||
|
||||
VkDynamicState dynamic_states[] = {
|
||||
VK_DYNAMIC_STATE_VIEWPORT,
|
||||
VK_DYNAMIC_STATE_SCISSOR,
|
||||
};
|
||||
|
||||
VkPipelineDynamicStateCreateInfo dynamic_state_create_info = {
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
|
||||
.dynamicStateCount = ARRAYSIZE(dynamic_states),
|
||||
.pDynamicStates = dynamic_states,
|
||||
};
|
||||
|
||||
VkGraphicsPipelineCreateInfo gpci = {
|
||||
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
||||
.stageCount = ARRAYSIZE(shader_stages),
|
||||
|
@ -204,6 +215,7 @@ static VkPipeline createPipeline( void )
|
|||
.pDepthStencilState = &depth,
|
||||
//.layout = material->pipeline_layout,
|
||||
.renderPass = vk_frame.render_pass,
|
||||
.pDynamicState = &dynamic_state_create_info,
|
||||
.subpass = 0,
|
||||
};
|
||||
|
||||
|
@ -252,10 +264,20 @@ void vk2dBegin( void )
|
|||
void vk2dEnd( void )
|
||||
{
|
||||
const VkDeviceSize offset = 0;
|
||||
const VkViewport viewport[] = {
|
||||
{0.f, 0.f, (float)vk_frame.surface_caps.currentExtent.width, (float)vk_frame.surface_caps.currentExtent.height, 0.f, 1.f},
|
||||
};
|
||||
const VkRect2D scissor[] = {{
|
||||
{0, 0},
|
||||
vk_frame.surface_caps.currentExtent,
|
||||
}};
|
||||
|
||||
if (!g2d.num_pics)
|
||||
return;
|
||||
|
||||
vkCmdBindPipeline(vk_core.cb, VK_PIPELINE_BIND_POINT_GRAPHICS, g2d.pipeline);
|
||||
vkCmdSetViewport(vk_core.cb, 0, ARRAYSIZE(viewport), viewport);
|
||||
vkCmdSetScissor(vk_core.cb, 0, ARRAYSIZE(scissor), scissor);
|
||||
vkCmdBindVertexBuffers(vk_core.cb, 0, 1, &g2d.pics_buffer.buffer, &offset);
|
||||
|
||||
for (int i = 0; i <= g2d.current_batch; ++i)
|
||||
|
|
|
@ -176,6 +176,8 @@ const char *resultName(VkResult result);
|
|||
X(vkAllocateDescriptorSets) \
|
||||
X(vkUpdateDescriptorSets) \
|
||||
X(vkDestroyDescriptorSetLayout) \
|
||||
X(vkCmdSetViewport) \
|
||||
X(vkCmdSetScissor) \
|
||||
|
||||
#define X(f) extern PFN_##f f;
|
||||
DEVICE_FUNCS(X)
|
||||
|
|
|
@ -71,6 +71,17 @@ static qboolean createRenderPass( void ) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static void destroySwapchain( VkSwapchainKHR swapchain )
|
||||
{
|
||||
for (uint32_t i = 0; i < vk_frame.num_images; ++i)
|
||||
{
|
||||
vkDestroyImageView(vk_core.device, vk_frame.image_views[i], NULL);
|
||||
vkDestroyFramebuffer(vk_core.device, vk_frame.framebuffers[i], NULL);
|
||||
}
|
||||
|
||||
vkDestroySwapchainKHR(vk_core.device, swapchain, NULL);
|
||||
}
|
||||
|
||||
static qboolean createSwapchain( void )
|
||||
{
|
||||
VkSwapchainCreateInfoKHR *create_info = &vk_frame.create_info;
|
||||
|
@ -100,6 +111,10 @@ static qboolean createSwapchain( void )
|
|||
create_info->minImageCount = vk_frame.surface_caps.maxImageCount;
|
||||
|
||||
XVK_CHECK(vkCreateSwapchainKHR(vk_core.device, create_info, NULL, &vk_frame.swapchain));
|
||||
if (create_info->oldSwapchain)
|
||||
{
|
||||
destroySwapchain( create_info->oldSwapchain );
|
||||
}
|
||||
|
||||
vk_frame.num_images = 0;
|
||||
XVK_CHECK(vkGetSwapchainImagesKHR(vk_core.device, vk_frame.swapchain, &vk_frame.num_images, NULL));
|
||||
|
@ -155,7 +170,21 @@ static qboolean createSwapchain( void )
|
|||
|
||||
void R_BeginFrame( qboolean clearScene )
|
||||
{
|
||||
gEngine.Con_Printf(S_WARN "VK FIXME: %s(%d)\n", __FUNCTION__, clearScene);
|
||||
//gEngine.Con_Printf(S_WARN "VK FIXME: %s(%d)\n", __FUNCTION__, clearScene);
|
||||
|
||||
// Check that swapchain has the same size
|
||||
{
|
||||
VkSurfaceCapabilitiesKHR surface_caps;
|
||||
XVK_CHECK(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(vk_core.physical_device.device, vk_core.surface.surface, &surface_caps));
|
||||
|
||||
if (surface_caps.currentExtent.width != vk_frame.surface_caps.currentExtent.width
|
||||
|| surface_caps.currentExtent.height != vk_frame.surface_caps.currentExtent.height)
|
||||
{
|
||||
createSwapchain();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
vk2dBegin();
|
||||
}
|
||||
|
||||
|
@ -251,12 +280,7 @@ void VK_FrameCtlShutdown( void )
|
|||
destroySemaphore(g_frame.done);
|
||||
destroySemaphore(g_frame.image_available);
|
||||
|
||||
for (uint32_t i = 0; i < vk_frame.num_images; ++i)
|
||||
{
|
||||
vkDestroyImageView(vk_core.device, vk_frame.image_views[i], NULL);
|
||||
vkDestroyFramebuffer(vk_core.device, vk_frame.framebuffers[i], NULL);
|
||||
}
|
||||
destroySwapchain( vk_frame.swapchain );
|
||||
|
||||
vkDestroySwapchainKHR(vk_core.device, vk_frame.swapchain, NULL);
|
||||
vkDestroyRenderPass(vk_core.device, vk_frame.render_pass, NULL);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue