From: Eleni Maria Stea Date: Fri, 4 Jun 2021 20:08:17 +0000 (+0300) Subject: WIP create and destroy swapchain X-Git-Url: https://eleni.mutantstargoat.com/git/?a=commitdiff_plain;h=04881c8da046dfd0b56c42b1dfb81b8a06398c46;p=vkrt WIP create and destroy swapchain I might want to move them to vk.[hc] --- diff --git a/src/ui.c b/src/ui.c index 13f96fc..fd00364 100644 --- a/src/ui.c +++ b/src/ui.c @@ -1,19 +1,57 @@ +#include +#include #include #include "ui.h" bool vk_create_swapchain(struct vk_ctx *ctx, + int width, int height, + int num_qfam, struct vk_swapchain *swapchain) { VkSwapchainCreateInfoKHR s_info; + VkExtent2D extent; + + extent.width = width; + extent.height = height; memset(&s_info, 0, sizeof s_info); + s_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; - s_info.flags = VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR; + s_info.flags = 0; s_info.surface = swapchain->surface; s_info.minImageCount = 2; + s_info.imageFormat = VK_FORMAT_R32G32B32A32_SFLOAT; + s_info.imageColorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR; + s_info.imageExtent = extent; + s_info.imageArrayLayers = 1; + s_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | + VK_IMAGE_USAGE_SAMPLED_BIT | + VK_IMAGE_USAGE_TRANSFER_SRC_BIT | + VK_IMAGE_USAGE_TRANSFER_DST_BIT; + + s_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT; + s_info.queueFamilyIndexCount = num_qfam; /* how many queue families */ + + s_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; + s_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; + s_info.presentMode = VK_PRESENT_MODE_FIFO_KHR; + s_info.clipped = VK_TRUE; + s_info.oldSwapchain = VK_NULL_HANDLE; - // FIXME: to be continued + if (vkCreateSwapchainKHR(ctx->dev, &s_info, 0, + &swapchain->swapchain) != VK_SUCCESS) { + fprintf(stderr, "Failed to create a swapchain.\n"); + return false; + } return true; } + +void +vk_destroy_swapchain(struct vk_ctx *ctx, + struct vk_swapchain *swapchain) +{ + vkDestroySwapchainKHR(ctx->dev, swapchain->swapchain, 0); + vkDestroySurfaceKHR(ctx->inst, swapchain->surface, 0); +} diff --git a/src/ui.h b/src/ui.h index 6cc6713..d26f4f0 100644 --- a/src/ui.h +++ b/src/ui.h @@ -15,6 +15,8 @@ struct vk_swapchain /* swapchain */ bool vk_create_swapchain(struct vk_ctx *ctx, + int width, int height, + int num_qfam, struct vk_swapchain *swapchain); void vk_destroy_swapchain(struct vk_ctx *ctx,