improve the resize callback

also gets rid of 1 global var
This commit is contained in:
jacekpoz 2024-09-25 17:58:18 +02:00
parent 6c20ddcbd9
commit ccf0e1481b
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
3 changed files with 11 additions and 10 deletions

View file

@ -24,11 +24,6 @@
// TODO: clean up globals here
static void framebuffer_resize_callback(GLFWwindow *window, int width, int height) {
(void)window; (void)width; (void)height;
g_framebuffer_resized = true;
}
static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods) {
(void)window; (void)scancode; (void)action; (void)mods;
if (key == GLFW_KEY_SPACE) {
@ -119,7 +114,7 @@ bool ptk_init(const size_t width, const size_t height, const char *title, const
return false;
}
glfwSetFramebufferSizeCallback(g_window, framebuffer_resize_callback);
glfwSetFramebufferSizeCallback(g_window, vk_framebuffer_resized);
glfwSetKeyCallback(g_window, key_callback);
glfwSetMouseButtonCallback(g_window, mouse_button_callback);

View file

@ -13,9 +13,14 @@
// TODO: clean up globals here
bool g_framebuffer_resized = false;
bool m_framebuffer_resized = false;
uint32_t g_current_frame = 0;
void vk_framebuffer_resized(GLFWwindow *window, int width, int height) {
(void)window; (void)width; (void)height;
m_framebuffer_resized = true;
}
bool vk_draw_frame(void) {
vkWaitForFences(g_dev, 1, &g_in_flight_fences.data[g_current_frame], VK_TRUE, UINT64_MAX);
@ -84,9 +89,9 @@ bool vk_draw_frame(void) {
if (
queue_present_result == VK_ERROR_OUT_OF_DATE_KHR ||
queue_present_result == VK_SUBOPTIMAL_KHR ||
g_framebuffer_resized
m_framebuffer_resized
) {
g_framebuffer_resized = false;
m_framebuffer_resized = false;
if (!vk_recreate_swapchain(g_window, g_physical_dev, g_surface, g_render_pass)) {
return false;
}

View file

@ -11,9 +11,10 @@
#endif
#include <GLFW/glfw3.h>
extern bool g_framebuffer_resized;
extern uint32_t g_current_frame;
void vk_framebuffer_resized(GLFWwindow *window, int width, int height);
bool vk_draw_frame(void);
#endif // PTK_PTK_VK_DRAW_H_