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

Skip to content

Commit 387e4e5

Browse files
committed
Replace glfwGetWindowSize with glfwGetFramebufferSize and add back missing chooseSwapExtent text
1 parent 8620fe6 commit 387e4e5

14 files changed

Lines changed: 33 additions & 13 deletions

03_Drawing_a_triangle/04_Swap_chain_recreation.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,26 @@ Instead I've opted to clean up the existing command buffers with the
110110
`vkFreeCommandBuffers` function. This way we can reuse the existing pool to
111111
allocate the new command buffers.
112112

113+
To handle window resizes properly, we also need to query the current size of the framebuffer to make sure that the swap chain images have the (new) right size. To do that change the `chooseSwapExtent` function to take the actual size into account:
114+
115+
```
116+
VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities) {
117+
if (capabilities.currentExtent.width != std::numeric_limits<uint32_t>::max()) {
118+
return capabilities.currentExtent;
119+
} else {
120+
int width, height;
121+
glfwGetFramebufferSize(window, &width, &height);
122+
123+
VkExtent2D actualExtent = {
124+
static_cast<uint32_t>(width),
125+
static_cast<uint32_t>(height)
126+
};
127+
128+
...
129+
}
130+
}
131+
```
132+
113133
That's all it takes to recreate the swap chain! However, the disadvantage of
114134
this approach is that we need to stop all rendering before creating the new swap
115135
chain. It is possible to create a new swap chain while drawing commands on an

code/16_swap_chain_recreation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ class HelloTriangleApplication {
750750
return capabilities.currentExtent;
751751
} else {
752752
int width, height;
753-
glfwGetWindowSize(window, &width, &height);
753+
glfwGetFramebufferSize(window, &width, &height);
754754

755755
VkExtent2D actualExtent = {
756756
static_cast<uint32_t>(width),

code/17_vertex_input.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ class HelloTriangleApplication {
795795
return capabilities.currentExtent;
796796
} else {
797797
int width, height;
798-
glfwGetWindowSize(window, &width, &height);
798+
glfwGetFramebufferSize(window, &width, &height);
799799

800800
VkExtent2D actualExtent = {
801801
static_cast<uint32_t>(width),

code/18_vertex_buffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ class HelloTriangleApplication {
851851
return capabilities.currentExtent;
852852
} else {
853853
int width, height;
854-
glfwGetWindowSize(window, &width, &height);
854+
glfwGetFramebufferSize(window, &width, &height);
855855

856856
VkExtent2D actualExtent = {
857857
static_cast<uint32_t>(width),

code/19_staging_buffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ class HelloTriangleApplication {
899899
return capabilities.currentExtent;
900900
} else {
901901
int width, height;
902-
glfwGetWindowSize(window, &width, &height);
902+
glfwGetFramebufferSize(window, &width, &height);
903903

904904
VkExtent2D actualExtent = {
905905
static_cast<uint32_t>(width),

code/20_index_buffer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ class HelloTriangleApplication {
932932
return capabilities.currentExtent;
933933
} else {
934934
int width, height;
935-
glfwGetWindowSize(window, &width, &height);
935+
glfwGetFramebufferSize(window, &width, &height);
936936

937937
VkExtent2D actualExtent = {
938938
static_cast<uint32_t>(width),

code/21_descriptor_layout.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ class HelloTriangleApplication {
994994
return capabilities.currentExtent;
995995
} else {
996996
int width, height;
997-
glfwGetWindowSize(window, &width, &height);
997+
glfwGetFramebufferSize(window, &width, &height);
998998

999999
VkExtent2D actualExtent = {
10001000
static_cast<uint32_t>(width),

code/22_descriptor_set.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ class HelloTriangleApplication {
10481048
return capabilities.currentExtent;
10491049
} else {
10501050
int width, height;
1051-
glfwGetWindowSize(window, &width, &height);
1051+
glfwGetFramebufferSize(window, &width, &height);
10521052

10531053
VkExtent2D actualExtent = {
10541054
static_cast<uint32_t>(width),

code/23_texture_image.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ class HelloTriangleApplication {
12031203
return capabilities.currentExtent;
12041204
} else {
12051205
int width, height;
1206-
glfwGetWindowSize(window, &width, &height);
1206+
glfwGetFramebufferSize(window, &width, &height);
12071207

12081208
VkExtent2D actualExtent = {
12091209
static_cast<uint32_t>(width),

code/24_sampler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ class HelloTriangleApplication {
12391239
return capabilities.currentExtent;
12401240
} else {
12411241
int width, height;
1242-
glfwGetWindowSize(window, &width, &height);
1242+
glfwGetFramebufferSize(window, &width, &height);
12431243

12441244
VkExtent2D actualExtent = {
12451245
static_cast<uint32_t>(width),

0 commit comments

Comments
 (0)