vulkan_test2

diff src/vku.c @ 6:1dd2c7398afc

swapchain images and other tales of woe
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 22 Sep 2017 18:13:03 +0300
parents cec4b0e7fce8
children e17abe477616
line diff
     1.1 --- a/src/vku.c	Fri Sep 22 17:48:18 2017 +0300
     1.2 +++ b/src/vku.c	Fri Sep 22 18:13:03 2017 +0300
     1.3 @@ -339,6 +339,49 @@
     1.4  	return sc;
     1.5  }
     1.6  
     1.7 +VkImage *vku_get_swapchain_images(VkSwapchainKHR sc, int *count)
     1.8 +{
     1.9 +	uint32_t nimg;
    1.10 +	VkImage *images;
    1.11 +
    1.12 +	if(vkGetSwapchainImagesKHR(vkdev, sc, &nimg, 0) != 0) {
    1.13 +		return 0;
    1.14 +	}
    1.15 +	if(!(images = malloc(nimg * sizeof *images))) {
    1.16 +		return 0;
    1.17 +	}
    1.18 +	vkGetSwapchainImagesKHR(vkdev, sc, &nimg, images);
    1.19 +
    1.20 +	if(count) *count = (int)nimg;
    1.21 +	return images;
    1.22 +}
    1.23 +
    1.24 +int vku_get_next_image(VkSwapchainKHR sc)
    1.25 +{
    1.26 +	uint32_t next;
    1.27 +
    1.28 +	if(vkAcquireNextImageKHR(vkdev, sc, UINT64_MAX, 0, 0, &next) != 0) {
    1.29 +		return -1;
    1.30 +	}
    1.31 +	return (int)next;
    1.32 +}
    1.33 +
    1.34 +void vku_present(VkSwapchainKHR sc, int img_idx)
    1.35 +{
    1.36 +	VkPresentInfoKHR inf;
    1.37 +	VkResult res;
    1.38 +	uint32_t index = img_idx;
    1.39 +
    1.40 +	memset(&inf, 0, sizeof inf);
    1.41 +	inf.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
    1.42 +	inf.swapchainCount = 1;
    1.43 +	inf.pSwapchains = &sc;
    1.44 +	inf.pImageIndices = &index;
    1.45 +	inf.pResults = &res;
    1.46 +
    1.47 +	vkQueuePresentKHR(vkq, &inf);
    1.48 +}
    1.49 +
    1.50  struct vku_buffer *vku_create_buffer(int sz, unsigned int usage)
    1.51  {
    1.52  	struct vku_buffer *buf;