vulkan_test2

diff src/vku.c @ 14:9fb6c24691ea

this shit never ends...
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 26 Jun 2018 07:20:03 +0300
parents d34f84bede17
children 196122a2b8c2
line diff
     1.1 --- a/src/vku.c	Mon Jun 25 08:00:57 2018 +0300
     1.2 +++ b/src/vku.c	Tue Jun 26 07:20:03 2018 +0300
     1.3 @@ -312,7 +312,7 @@
     1.4  }
     1.5  
     1.6  VkSwapchainKHR vku_create_swapchain(VkSurfaceKHR surf, int xsz, int ysz, int n,
     1.7 -		VkPresentModeKHR pmode, VkSwapchainKHR prev)
     1.8 +		VkFormat fmt, VkPresentModeKHR pmode, VkSwapchainKHR prev)
     1.9  {
    1.10  	VkSwapchainKHR sc;
    1.11  	VkSwapchainCreateInfoKHR inf;
    1.12 @@ -321,7 +321,7 @@
    1.13  	inf.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
    1.14  	inf.surface = surf;
    1.15  	inf.minImageCount = n;
    1.16 -	inf.imageFormat = VK_FORMAT_B8G8R8A8_UNORM;	/* TODO enumerate and choose */
    1.17 +	inf.imageFormat = fmt;
    1.18  	inf.imageColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR;
    1.19  	inf.imageExtent.width = xsz;
    1.20  	inf.imageExtent.height = ysz;
    1.21 @@ -366,6 +366,62 @@
    1.22  	return (int)next;
    1.23  }
    1.24  
    1.25 +VkImageView vku_create_view(VkImage img, VkFormat fmt)
    1.26 +{
    1.27 +	VkImageView view;
    1.28 +	VkImageViewCreateInfo iv;
    1.29 +
    1.30 +	memset(&iv, 0, sizeof iv);
    1.31 +	iv.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
    1.32 +	iv.image = img;
    1.33 +	iv.viewType = VK_IMAGE_VIEW_TYPE_2D;
    1.34 +	iv.format = fmt;
    1.35 +	iv.components.r = iv.components.g = iv.components.b = iv.components.a =
    1.36 +		VK_COMPONENT_SWIZZLE_IDENTITY;
    1.37 +	iv.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
    1.38 +	iv.subresourceRange.baseMipLevel = 0;
    1.39 +	iv.subresourceRange.levelCount = 1;
    1.40 +	iv.subresourceRange.baseArrayLayer = 0;
    1.41 +	iv.subresourceRange.layerCount = 1;
    1.42 +
    1.43 +	if(vkCreateImageView(vkdev, &iv, 0, &view) != 0) {
    1.44 +		fprintf(stderr, "vku_create_view failed\n");
    1.45 +		return 0;
    1.46 +	}
    1.47 +	return view;
    1.48 +}
    1.49 +
    1.50 +void vku_destroy_view(VkImageView view)
    1.51 +{
    1.52 +	vkDestroyImageView(vkdev, view, 0);
    1.53 +}
    1.54 +
    1.55 +VkFramebuffer vku_create_framebuffer(VkImageView view, int width, int height, VkRenderPass rpass)
    1.56 +{
    1.57 +	VkFramebuffer fb;
    1.58 +	VkFramebufferCreateInfo fbinf;
    1.59 +
    1.60 +	memset(&fbinf, 0, sizeof fbinf);
    1.61 +	fbinf.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
    1.62 +	fbinf.renderPass = rpass;
    1.63 +	fbinf.attachmentCount = 1;
    1.64 +	fbinf.pAttachments = &view;
    1.65 +	fbinf.width = width;
    1.66 +	fbinf.height = height;
    1.67 +	fbinf.layers = 1;
    1.68 +
    1.69 +	if(vkCreateFramebuffer(vkdev, &fbinf, 0, &fb) != 0) {
    1.70 +		fprintf(stderr, "vku_create_framebuffer failed\n");
    1.71 +		return 0;
    1.72 +	}
    1.73 +	return fb;
    1.74 +}
    1.75 +
    1.76 +void vku_destroy_framebuffer(VkFramebuffer fb)
    1.77 +{
    1.78 +	vkDestroyFramebuffer(vkdev, fb, 0);
    1.79 +}
    1.80 +
    1.81  void vku_present(VkSwapchainKHR sc, int img_idx)
    1.82  {
    1.83  	VkPresentInfoKHR inf;