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
The `vkQueuePresentKHR` function returns the same values with the same meaning.
184
184
In this case we will also recreate the swap chain if it is suboptimal, because
185
-
we want the best possible result. Try to run it and resize the window to see if
186
-
the framebuffer is indeed resized properly with the window.
185
+
we want the best possible result.
186
+
187
+
## Handling resizes explicitly
188
+
189
+
Although many drivers and platforms trigger `VK_ERROR_OUT_OF_DATE_KHR` automatically after a window resize, it is not guaranteed to happen. That's why we'll add some extra code to also handle resizes explicitly. First add a new member variable that flags that a resize has happened:
190
+
191
+
```c++
192
+
std::vector<VkFence> inFlightFences;
193
+
size_t currentFrame = 0;
194
+
195
+
bool framebufferResized = false;
196
+
```
197
+
198
+
The `drawFrame` function should then be modified to also check for this flag:
199
+
200
+
```c++
201
+
if (result == VK_ERROR_OUT_OF_DATE_KHR || result == VK_SUBOPTIMAL_KHR || framebufferResized) {
202
+
framebufferResized = false;
203
+
recreateSwapChain();
204
+
} elseif (result != VK_SUCCESS) {
205
+
...
206
+
}
207
+
```
208
+
209
+
Now to actually detect resizes we can use the `glfwSetFramebufferSizeCallback` function in the GLFW framework to set up a callback:
staticvoidframebufferResizeCallback(GLFWwindow* window, int width, int height) {
222
+
223
+
}
224
+
```
225
+
226
+
The reason that we're creating a `static` function as a callback is because GLFW does not know how to properly call a member function with the right `this` pointer to our `HelloTriangleApplication` instance.
227
+
228
+
However, we do get a reference to the `GLFWwindow` in the callback and there is another GLFW function that allows you to store an arbitrary pointer inside of it: `glfwSetWindowUserPointer`:
0 commit comments