Create shadow framebuffer

This commit is contained in:
Camden Dixie O'Brien committed 2025-10-04 14:59:32 +01:00
1 parent da10aaab41
commit 8725f3082c
2 files changed
+15

No files matched your search

+14
View File
@@ -768,6 +768,19 @@ void gpu_init(gpu_ctx_t *ctx, GLFWwindow *window, const char *name)
assert(result == VK_SUCCESS); assert(result == VK_SUCCESS);
// Create framebuffers // Create framebuffers
const VkFramebufferCreateInfo shadow_framebuffer_config = {
.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
.renderPass = ctx->shadow_pass,
.attachmentCount = 1,
.pAttachments = &ctx->shadow_view,
.width = SHADOW_IMG_SIZE,
.height = SHADOW_IMG_SIZE,
.layers = 1,
};
result = vkCreateFramebuffer(
ctx->dev, &shadow_framebuffer_config, nullptr,
&ctx->shadow_framebuf);
assert(result == VK_SUCCESS);
for (unsigned i = 0; i < ctx->swapchain_img_count; ++i) { for (unsigned i = 0; i < ctx->swapchain_img_count; ++i) {
VkImageView attachments[] = { VkImageView attachments[] = {
ctx->swapchain_img_views[i], ctx->swapchain_img_views[i],
@@ -885,6 +898,7 @@ void gpu_cleanup(const gpu_ctx_t *ctx)
vkDestroyImage(ctx->dev, ctx->depth_img, nullptr); vkDestroyImage(ctx->dev, ctx->depth_img, nullptr);
vkFreeMemory(ctx->dev, ctx->depth_mem, nullptr); vkFreeMemory(ctx->dev, ctx->depth_mem, nullptr);
vkDestroyFramebuffer(ctx->dev, ctx->shadow_framebuf, nullptr);
for (unsigned i = 0; i < ctx->swapchain_img_count; ++i) { for (unsigned i = 0; i < ctx->swapchain_img_count; ++i) {
vkDestroyFramebuffer(ctx->dev, ctx->framebuffers[i], nullptr); vkDestroyFramebuffer(ctx->dev, ctx->framebuffers[i], nullptr);
vkDestroyImageView(ctx->dev, ctx->swapchain_img_views[i], nullptr); vkDestroyImageView(ctx->dev, ctx->swapchain_img_views[i], nullptr);
+1
View File
@@ -25,6 +25,7 @@ typedef struct {
VkImage depth_img; VkImage depth_img;
VkDeviceMemory depth_mem; VkDeviceMemory depth_mem;
VkImageView depth_view; VkImageView depth_view;
VkFramebuffer shadow_framebuf;
VkFramebuffer framebuffers[MAX_FRAMES_IN_FLIGHT]; VkFramebuffer framebuffers[MAX_FRAMES_IN_FLIGHT];
VkShaderModule floor_vert_shader; VkShaderModule floor_vert_shader;
VkShaderModule model_vert_shader; VkShaderModule model_vert_shader;