vulkan游戏引擎vulkan部分的frame_buffer实现

1.vulkan_framebuffer.h

#pragma once

#include "vulkan_types.inl"

void vulkan_framebuffer_create(

vulkan_context* context,

vulkan_renderpass* renderpass,

u32 width,

u32 height,

u32 attachment_count,

VkImageView* attachments,

vulkan_framebuffer* out_framebuffer

);

void vulkan_framebuffer_destroy(vulkan_context* context,vulkan_framebuffer* framebuffer);

2.vulkan_framebuffer.c

#include "vulkan_framebuffer.h"

#include "core/kmemory.h"

void vulkan_framebuffer_create(

vulkan_context* context,

vulkan_renderpass* renderpass,

u32 width,

u32 height,

u32 attachment_count,

VkImageView* attachments,

vulkan_framebuffer* out_framebuffer

)

{

//Take a copy of the attachments,renderpass and attachment count

out_framebuffer->attachments = kallocate(sizeof(VkImageView)* attachment_count,MEMORY_TAG_RENDERER);

for(u32 i = 0;i<attachment_count;++i)

{

out_framebuffer->attachments[i] = attachments[i];

}

out_framebuffer->renderpass = renderpass;

out_framebuffer->attachment_count = attachment_count;

//Creation info

VkFramebufferCreateInfo framebuffer_create_info = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO};

framebuffer_create_info.renderPass = renderpass->handle;

framebuffer_create_info.attachmentCount = attachment_count;

framebuffer_create_info.pAttachments = out_framebuffer->attachments;

framebuffer_create_info.width = width;

framebuffer_create_info.height = height;

framebuffer_create_info.layers = 1;

VK_CHECK(vkCreateFramebuffer(

context->device.logical_device,

&framebuffer_create_info,

context->allocator,

&out_framebuffer->handle));

}

void vulkan_framebuffer_destroy(vulkan_context* context,vulkan_framebuffer* framebuffer)

{

vkDestroyFramebuffer(context->device.logical_device,framebuffer->handle,context->allocator);

if(framebuffer->attachments)

{

kfree(framebuffer->attachments,sizeof(VkImageView) * framebuffer->attachment_count,MEMORY_TAG_RENDERER);

framebuffer->attachments = 0;

}

framebuffer->handle = 0;

framebuffer->attachment_count = 0;

framebuffer->renderpass= 0;

}

相关推荐
寻星探路2 小时前
【深度长文】万字攻克网络原理:从 HTTP 报文解构到 HTTPS 终极加密逻辑
java·开发语言·网络·python·http·ai·https
崔庆才丨静觅3 小时前
hCaptcha 验证码图像识别 API 对接教程
前端
曹牧4 小时前
Spring Boot:如何测试Java Controller中的POST请求?
java·开发语言
passerby60614 小时前
完成前端时间处理的另一块版图
前端·github·web components
掘了4 小时前
「2025 年终总结」在所有失去的人中,我最怀念我自己
前端·后端·年终总结
崔庆才丨静觅4 小时前
实用免费的 Short URL 短链接 API 对接说明
前端
崔庆才丨静觅5 小时前
5分钟快速搭建 AI 平台并用它赚钱!
前端
爬山算法5 小时前
Hibernate(90)如何在故障注入测试中使用Hibernate?
java·后端·hibernate
kfyty7255 小时前
集成 spring-ai 2.x 实践中遇到的一些问题及解决方案
java·人工智能·spring-ai
猫头虎5 小时前
如何排查并解决项目启动时报错Error encountered while processing: java.io.IOException: closed 的问题
java·开发语言·jvm·spring boot·python·开源·maven