Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 072c0bb

Browse files
committed
Elaborate on the reason for renderpass recreation during swapchain recreation
1 parent c5c9044 commit 072c0bb

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

03_Drawing_a_triangle/04_Swap_chain_recreation.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ shouldn't touch resources that may still be in use. Obviously, the first thing
3030
we'll have to do is recreate the swap chain itself. The image views need to be
3131
recreated because they are based directly on the swap chain images. The render
3232
pass needs to be recreated because it depends on the format of the swap chain
33-
images. Viewport and scissor rectangle size is specified during graphics
34-
pipeline creation, so the pipeline also needs to be rebuilt. It is possible to
35-
avoid this by using dynamic state for the viewports and scissor rectangles.
36-
Finally, the framebuffers and command buffers also directly depend on the swap
37-
chain images.
33+
images. It is rare for the swap chain image format to change during an operation
34+
like a window resize, but it should still be handled. Viewport and scissor
35+
rectangle size is specified during graphics pipeline creation, so the pipeline
36+
also needs to be rebuilt. It is possible to avoid this by using dynamic state
37+
for the viewports and scissor rectangles. Finally, the framebuffers and command
38+
buffers also directly depend on the swap chain images.
3839

3940
To make sure that the old versions of these objects are cleaned up before
4041
recreating them, we should move some of the cleanup code to a separate function
@@ -43,12 +44,12 @@ that we can call from the `recreateSwapChain` function. Let's call it
4344

4445
```c++
4546
void cleanupSwapChain() {
46-
47+
4748
}
4849

4950
void recreateSwapChain() {
5051
vkDeviceWaitIdle(device);
51-
52+
5253
cleanupSwapChain();
5354

5455
createSwapChain();
@@ -104,7 +105,7 @@ void cleanup() {
104105
We could recreate the command pool from scratch, but that is rather wasteful.
105106
Instead I've opted to clean up the existing command buffers with the
106107
`vkFreeCommandBuffers` function. This way we can reuse the existing pool to
107-
allocate the new command buffers.
108+
allocate the new command buffers.
108109

109110
That's all it takes to recreate the swap chain! However, the disadvantage of
110111
this approach is that we need to stop all rendering before creating the new swap
@@ -219,4 +220,4 @@ the vertex shader and actually use a vertex buffer.
219220
220221
[C++ code](/code/swap_chain_recreation.cpp) /
221222
[Vertex shader](/code/shader_base.vert) /
222-
[Fragment shader](/code/shader_base.frag)
223+
[Fragment shader](/code/shader_base.frag)

0 commit comments

Comments
 (0)