nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: nuclear@0: void keyb(GLFWwindow *win, int key, int sc, int act, int mods); nuclear@0: int init(void); nuclear@0: void destroy(void); nuclear@0: void draw(void); nuclear@0: nuclear@0: GLFWwindow *win; nuclear@0: int win_width = 800; nuclear@0: int win_height = 600; nuclear@0: int redraw_pending; nuclear@0: nuclear@0: int main(void) nuclear@0: { nuclear@0: if(!glfwInit()) { nuclear@0: fprintf(stderr, "glfw init failed\n"); nuclear@0: return 1; nuclear@0: } nuclear@0: nuclear@0: glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); nuclear@0: win = glfwCreateWindow(win_width, win_height, "test", 0, 0); nuclear@0: glfwSetKeyCallback(win, keyb); nuclear@0: nuclear@0: if(init() == -1) { nuclear@0: glfwDestroyWindow(win); nuclear@0: glfwTerminate(); nuclear@0: return 1; nuclear@0: } nuclear@0: nuclear@0: redraw_pending = 1; nuclear@0: nuclear@0: while(!glfwWindowShouldClose(win)) { nuclear@0: glfwWaitEvents(); nuclear@0: nuclear@0: if(redraw_pending) { nuclear@0: redraw_pending = 0; nuclear@0: draw(); nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: destroy(); nuclear@0: glfwDestroyWindow(win); nuclear@0: glfwTerminate(); nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: void keyb(GLFWwindow *win, int key, int sc, int act, int mods) nuclear@0: { nuclear@0: if(act == GLFW_PRESS) { nuclear@0: switch(key) { nuclear@0: case GLFW_KEY_ESCAPE: nuclear@0: glfwSetWindowShouldClose(win, 1); nuclear@0: break; nuclear@0: } nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: /* -------------------------------------------------------------- */ nuclear@0: int create_instance(void); nuclear@0: int create_surface(void); nuclear@0: int choose_phys_dev(void); nuclear@0: int create_device(void); nuclear@0: int create_swapchain(void); nuclear@0: int create_imgviews(void); nuclear@0: int create_rendpass(void); nuclear@0: int create_pipeline(void); nuclear@0: int create_framebuf(void); nuclear@0: int create_cmdpool(void); nuclear@0: int create_cmdbuf(void); nuclear@0: int create_semaphores(void); nuclear@0: VkShaderModule load_shader(const char *fname); nuclear@0: nuclear@0: VkInstance vk; nuclear@0: VkPhysicalDevice vkpdev; nuclear@0: int vkqfam_idx = -1; nuclear@0: VkDevice vkdev; nuclear@0: VkQueue vkq; nuclear@0: VkSurfaceKHR vksurf; nuclear@0: VkSurfaceCapabilitiesKHR vksurf_caps; nuclear@0: int vksurf_numfmt, vksurf_selfmt; nuclear@0: VkSurfaceFormatKHR *vksurf_fmt; nuclear@0: VkSwapchainKHR vksc; nuclear@0: int vksc_numimg; nuclear@0: VkImage *vksc_img; nuclear@0: VkExtent2D vksc_extent; nuclear@0: VkImageView *vksc_view; nuclear@0: VkRenderPass vkrpass; nuclear@0: VkPipelineLayout vkpipe_layout; nuclear@0: VkPipeline vkpipe; nuclear@0: VkFramebuffer *vksc_fb; nuclear@0: VkCommandPool vkcmdpool; nuclear@0: VkCommandBuffer *vksc_cmdbuf; nuclear@0: VkSemaphore sem_gotimg, sem_drawdone; nuclear@0: nuclear@0: int init(void) nuclear@0: { nuclear@0: if(create_instance() == -1) return -1; nuclear@0: if(create_surface() == -1) return -1; nuclear@0: if(choose_phys_dev() == -1) return -1; nuclear@0: if(create_device() == -1) return -1; nuclear@0: if(create_swapchain() == -1) return -1; nuclear@0: if(create_imgviews() == -1) return -1; nuclear@0: if(create_rendpass() == -1) return -1; nuclear@0: if(create_pipeline() == -1) return -1; nuclear@0: if(create_framebuf() == -1) return -1; nuclear@0: if(create_cmdpool() == -1) return -1; nuclear@0: if(create_cmdbuf() == -1) return -1; nuclear@0: if(create_semaphores() == -1) return -1; nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: void destroy(void) nuclear@0: { nuclear@0: int i; nuclear@0: nuclear@0: if(sem_gotimg) vkDestroySemaphore(vkdev, sem_gotimg, 0); nuclear@0: if(sem_drawdone) vkDestroySemaphore(vkdev, sem_drawdone, 0); nuclear@0: if(vkcmdpool) vkDestroyCommandPool(vkdev, vkcmdpool, 0); nuclear@0: if(vksc_fb) { nuclear@0: for(i=0; i