1 #define GLFW_INCLUDE_VULKAN
2 #include <GLFW/glfw3.h>
13 /* global variables */
14 extern GLFWwindow *win;
18 /* static functions */
19 static void error_callback(int error, const char *descr);
20 static void reshape(int width, int height);
25 fprintf(stderr, "Failed to initialize GLFW.\n");
29 if(!glfwVulkanSupported()) {
30 fprintf(stderr, "No Vulkan support on the device.\n");
34 glfwSetErrorCallback(error_callback);
36 if(!vku_create_device()) {
37 fprintf(stderr, "Failed to initialize vulkan.\n");
41 if(!glfwGetPhysicalDevicePresentationSupport(vkinst, vkpdev, vkqfamily)) {
42 fprintf(stderr, "Presentation support not found.\n");
46 glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
47 if(!(win = glfwCreateWindow(win_w, win_h, "vkcow", 0, 0))) {
48 fprintf(stderr, "Failed to create window.\n");
52 if(VkResult err = glfwCreateWindowSurface(vkinst, win, 0, &vksurface)) {
53 fprintf(stderr, "Failed to create KHR surface: %s\n", vku_get_vulkan_error_str(err));
57 gfx_reshape = reshape;
64 //TODOs according to the book:
65 // 1- make sure all threads have been terminated (when I add threads)
67 // 2- destroy objects in *reverse* order
68 vkDestroySurfaceKHR(vkinst, vksurface, 0);
73 static void error_callback(int error, const char *description)
75 fprintf(stderr, "GLFW error %d: %s.\n", error, description);
78 static void reshape(int width, int height)
81 if(!(sc = vku_create_swapchain(vksurface, width, height, 2, VK_PRESENT_MODE_FIFO_KHR,
83 fprintf(stderr, "Failed to create %dx%d double-buffered swapchain\n", width, height);
88 free(vkswapchain_images);
89 vkswapchain_images = vku_get_swapchain_images(sc, 0);
90 vknext_swapchain_image = vku_get_next_image(vkswapchain);