MCPcopy Create free account
hub / github.com/defold/defold / SwapChainChanged

Function SwapChainChanged

engine/graphics/src/vulkan/graphics_vulkan.cpp:945–1011  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

943 }
944
945 void SwapChainChanged(VulkanContext* context, uint32_t* width, uint32_t* height, VkResult (*cb)(void* ctx), void* cb_ctx)
946 {
947 VkDevice vk_device = context->m_LogicalDevice.m_Device;
948
949 if (vk_device == VK_NULL_HANDLE)
950 {
951 return;
952 }
953
954 // Flush all current commands
955 SynchronizeDevice(vk_device);
956
957 DestroyMainFrameBuffers(context);
958
959 // Destroy main Depth/Stencil buffer
960 VulkanTexture* depth_stencil_texture = &context->m_MainTextureDepthStencil;
961 DestroyDeviceBuffer(vk_device, &depth_stencil_texture->m_DeviceBuffer.m_Handle);
962 DestroyTexture(vk_device, &depth_stencil_texture->m_Handle);
963 DestroySwapChain(vk_device, context->m_SwapChain);
964
965 // Reset the image layout
966 memset(depth_stencil_texture->m_ImageLayout, 0, sizeof(depth_stencil_texture->m_ImageLayout));
967
968 // At this point, we've destroyed the framebuffers, depth/stencil textures, and the swapchain
969 // and the platform may do extra setup
970 if (cb)
971 {
972 VkResult res = cb(cb_ctx);
973 CHECK_VK_ERROR(res);
974 }
975
976 // Update swap chain capabilities
977 SwapChainCapabilities swap_chain_capabilities;
978 GetSwapChainCapabilities(context->m_PhysicalDevice.m_Device, context->m_WindowSurface, swap_chain_capabilities);
979 context->m_SwapChainCapabilities.Swap(swap_chain_capabilities);
980
981 const bool want_vsync = context->m_SwapInterval != 0;
982
983 // Create the swap chain
984 VkResult res = UpdateSwapChain(&context->m_PhysicalDevice, &context->m_LogicalDevice, width, height, want_vsync, context->m_SwapChainCapabilities, context->m_SwapChain);
985 CHECK_VK_ERROR(res);
986
987 // Create the main Depth/Stencil buffer
988 VkFormat vk_depth_format;
989 VkImageTiling vk_depth_tiling;
990 GetDepthFormatAndTiling(context->m_PhysicalDevice.m_Device, 0, 0, &vk_depth_format, &vk_depth_tiling);
991 res = CreateDepthStencilTexture(context,
992 vk_depth_format, vk_depth_tiling,
993 context->m_SwapChain->m_ImageExtent.width,
994 context->m_SwapChain->m_ImageExtent.height,
995 context->m_SwapChain->m_SampleCountFlag,
996 GetDefaultDepthAndStencilAspectFlags(vk_depth_format),
997 depth_stencil_texture);
998 CHECK_VK_ERROR(res);
999
1000 context->m_WindowWidth = context->m_SwapChain->m_ImageExtent.width;
1001 context->m_WindowHeight = context->m_SwapChain->m_ImageExtent.height;
1002

Callers 4

NativeBeginFrameFunction · 0.85
VulkanSetWindowSizeFunction · 0.85
VulkanBeginFrameFunction · 0.85

Calls 14

SynchronizeDeviceFunction · 0.85
DestroyMainFrameBuffersFunction · 0.85
DestroyDeviceBufferFunction · 0.85
DestroySwapChainFunction · 0.85
cbFunction · 0.85
GetSwapChainCapabilitiesFunction · 0.85
UpdateSwapChainFunction · 0.85
GetDepthFormatAndTilingFunction · 0.85
CreateMainFrameBuffersFunction · 0.85
DestroyTextureFunction · 0.70

Tested by

no test coverage detected