You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: en/03_Drawing_a_triangle/04_Swap_chain_recreation.adoc
+22-20Lines changed: 22 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,15 +15,16 @@ Create a new `recreateSwapChain` function that calls `createSwapChain` and all t
15
15
16
16
[,c++]
17
17
----
18
-
void recreateSwapChain() {
18
+
void recreateSwapChain()
19
+
{
19
20
device.waitIdle();
20
21
21
22
createSwapChain();
22
23
createImageViews();
23
24
}
24
25
----
25
26
26
-
We first call `vkDeviceWaitIdle`, because just like in the last chapter, we shouldn't touch resources that may still be in use.
27
+
We first call `vk::raii::Device::waitIdle`, because just like in the last chapter, we shouldn't touch resources that may still be in use.
27
28
Obviously, we'll have to recreate the swap chain itself.
28
29
The image views need to be recreated because they are based directly on the swap chain images.
29
30
@@ -32,11 +33,12 @@ Let's call it `cleanupSwapChain`:
32
33
33
34
[,c++]
34
35
----
35
-
void cleanupSwapChain() {
36
-
36
+
void cleanupSwapChain()
37
+
{
37
38
}
38
39
39
-
void recreateSwapChain() {
40
+
void recreateSwapChain()
41
+
{
40
42
device.waitIdle();
41
43
42
44
cleanupSwapChain();
@@ -55,12 +57,14 @@ We'll move the cleanup code of all objects that are recreated as part of a swap
55
57
56
58
[,c++]
57
59
----
58
-
void cleanupSwapChain() {
60
+
void cleanupSwapChain()
61
+
{
59
62
swapChainImageViews.clear();
60
63
swapChain = nullptr;
61
64
}
62
65
63
-
void cleanup() {
66
+
void cleanup()
67
+
{
64
68
cleanupSwapChain();
65
69
66
70
glfwDestroyWindow(window);
@@ -73,7 +77,7 @@ Note that in `chooseSwapExtent` we already query the new window resolution to ma
73
77
That's all it takes to recreate the swap chain!
74
78
However, the disadvantage of this approach is that we need to stop all renderings before creating the new swap chain.
75
79
It is possible to create a new swap chain while drawing commands on an image from the old swap chain are still in-flight.
76
-
You need to pass the previous swap chain to the `oldSwapchain` field in the `VkSwapchainCreateInfoKHR` struct and destroy the old swap chain as soon as you've finished using it.
80
+
You need to pass the previous swap chain to the `oldSwapchain` field in the `vk::SwapchainCreateInfoKHR` struct and destroy the old swap chain as soon as you've finished using it.
77
81
78
82
== Suboptimal or out-of-date swap chain
79
83
@@ -120,8 +124,6 @@ else
120
124
// There are no other success codes than eSuccess; on any error code, presentKHR already threw an exception.
0 commit comments