vulkan_test2
diff src/wsys_x11.c @ 17:f8bd29f124a8
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 27 Jun 2018 01:57:55 +0300 |
parents | 9fb6c24691ea |
children |
line diff
1.1 --- a/src/wsys_x11.c Tue Jun 26 08:42:12 2018 +0300 1.2 +++ b/src/wsys_x11.c Wed Jun 27 01:57:55 2018 +0300 1.3 @@ -20,6 +20,7 @@ 1.4 REDISPLAY = 4 1.5 }; 1.6 1.7 +static int reshape(int x, int y); 1.8 static void proc_event(XEvent *ev); 1.9 1.10 static Display *dpy; 1.11 @@ -102,7 +103,14 @@ 1.12 1.13 win_width = xsz; 1.14 win_height = ysz; 1.15 - pending = RESHAPE | REDISPLAY; 1.16 + 1.17 + if(reshape(xsz, ysz) == -1) { 1.18 + XDestroyWindow(dpy, win); 1.19 + XCloseDisplay(dpy); 1.20 + return -1; 1.21 + } 1.22 + 1.23 + pending = REDISPLAY; 1.24 1.25 return 0; 1.26 } 1.27 @@ -196,10 +204,10 @@ 1.28 } 1.29 } 1.30 1.31 -void wsys_swap_buffers(void) 1.32 +void wsys_swap_buffers(VkSemaphore sem_wait) 1.33 { 1.34 - vku_present(swapchain, next_swapchain_image); 1.35 - next_swapchain_image = vku_get_next_image(swapchain); 1.36 + vku_present(swapchain, next_swapchain_image, sem_wait); 1.37 + next_swapchain_image = vku_get_next_image(swapchain, swapchain_getimg_sem); 1.38 } 1.39 1.40 void wsys_redisplay(void) 1.41 @@ -212,67 +220,74 @@ 1.42 pending |= QUIT; 1.43 } 1.44 1.45 +static int reshape(int x, int y) 1.46 +{ 1.47 + int i; 1.48 + VkSwapchainKHR sc; 1.49 + VkFormat fmt = VK_FORMAT_B8G8R8A8_UNORM; /* TODO enumerate and choose */ 1.50 + 1.51 + printf("DBG reshape\n"); 1.52 + 1.53 + if(!vkrpass) { 1.54 + if(!(vkrpass = vku_create_renderpass(fmt, VK_FORMAT_UNDEFINED))) { 1.55 + abort(); 1.56 + } 1.57 + } 1.58 + 1.59 + if(!(sc = vku_create_swapchain(surf, x, y, 2, fmt, 1.60 + VK_PRESENT_MODE_FIFO_KHR, swapchain))) { 1.61 + fprintf(stderr, "Failed to create %dx%d double-buffered swapchain\n", x, y); 1.62 + return -1; 1.63 + } 1.64 + swapchain = sc; 1.65 + 1.66 + free(swapchain_images); 1.67 + swapchain_size = 2; 1.68 + swapchain_images = vku_get_swapchain_images(sc, 0); 1.69 + next_swapchain_image = vku_get_next_image(swapchain, swapchain_getimg_sem); 1.70 + 1.71 + if(!swapchain_views) { 1.72 + if(!(swapchain_views = calloc(swapchain_size, sizeof *swapchain_views))) { 1.73 + fprintf(stderr, "Failed to allocate image views\n"); 1.74 + return -1; 1.75 + } 1.76 + } 1.77 + 1.78 + for(i=0; i<swapchain_size; i++) { 1.79 + if(swapchain_views[i]) { 1.80 + vku_destroy_view(swapchain_views[i]); 1.81 + } 1.82 + swapchain_views[i] = vku_create_view(swapchain_images[i], fmt); 1.83 + } 1.84 + 1.85 + if(!swapchain_framebuf) { 1.86 + if(!(swapchain_framebuf = calloc(swapchain_size, sizeof *swapchain_framebuf))) { 1.87 + fprintf(stderr, "Failed to allocate framebuffers\n"); 1.88 + return -1; 1.89 + } 1.90 + } 1.91 + 1.92 + for(i=0; i<swapchain_size; i++) { 1.93 + if(swapchain_framebuf[i]) { 1.94 + vku_destroy_framebuffer(swapchain_framebuf[i]); 1.95 + } 1.96 + swapchain_framebuf[i] = vku_create_framebuffer(swapchain_views[i], x, y, vkrpass); 1.97 + } 1.98 + 1.99 + if(cb.reshape) { 1.100 + cb.reshape(x, y); 1.101 + } 1.102 + return 0; 1.103 +} 1.104 + 1.105 int wsys_process_events(int mode) 1.106 { 1.107 - int i; 1.108 XEvent xev; 1.109 1.110 if(pending & RESHAPE) { 1.111 - VkSwapchainKHR sc; 1.112 - VkFormat fmt = VK_FORMAT_B8G8R8A8_UNORM; /* TODO enumerate and choose */ 1.113 - 1.114 - printf("DBG reshape\n"); 1.115 - 1.116 - if(!vkrpass) { 1.117 - if(!(vkrpass = vku_create_renderpass(fmt, VK_FORMAT_UNDEFINED))) { 1.118 - abort(); 1.119 - } 1.120 - } 1.121 - 1.122 - if(!(sc = vku_create_swapchain(surf, win_width, win_height, 2, fmt, 1.123 - VK_PRESENT_MODE_FIFO_KHR, swapchain))) { 1.124 - fprintf(stderr, "Failed to create %dx%d double-buffered swapchain\n", win_width, win_height); 1.125 + if(reshape(win_width, win_height) == -1) { 1.126 return -1; 1.127 } 1.128 - swapchain = sc; 1.129 - 1.130 - free(swapchain_images); 1.131 - swapchain_size = 2; 1.132 - swapchain_images = vku_get_swapchain_images(sc, 0); 1.133 - next_swapchain_image = vku_get_next_image(swapchain); 1.134 - 1.135 - if(!swapchain_views) { 1.136 - if(!(swapchain_views = calloc(swapchain_size, sizeof *swapchain_views))) { 1.137 - fprintf(stderr, "Failed to allocate image views\n"); 1.138 - return -1; 1.139 - } 1.140 - } 1.141 - 1.142 - for(i=0; i<swapchain_size; i++) { 1.143 - if(swapchain_views[i]) { 1.144 - vku_destroy_view(swapchain_views[i]); 1.145 - } 1.146 - swapchain_views[i] = vku_create_view(swapchain_images[i], fmt); 1.147 - } 1.148 - 1.149 - if(!swapchain_framebuf) { 1.150 - if(!(swapchain_framebuf = calloc(swapchain_size, sizeof *swapchain_framebuf))) { 1.151 - fprintf(stderr, "Failed to allocate framebuffers\n"); 1.152 - return -1; 1.153 - } 1.154 - } 1.155 - 1.156 - for(i=0; i<swapchain_size; i++) { 1.157 - if(swapchain_framebuf[i]) { 1.158 - vku_destroy_framebuffer(swapchain_framebuf[i]); 1.159 - } 1.160 - swapchain_framebuf[i] = vku_create_framebuffer(swapchain_views[i], 1.161 - win_width, win_height, vkrpass); 1.162 - } 1.163 - 1.164 - if(cb.reshape) { 1.165 - cb.reshape(win_width, win_height); 1.166 - } 1.167 pending &= ~RESHAPE; 1.168 } 1.169