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;

}

相关推荐
IAUTOMOBILE27 分钟前
Python 流程控制与函数定义:从调试现场到工程实践
java·前端·python
hutengyi28 分钟前
PostgreSQL版本选择
java
皮皮林55134 分钟前
重磅!JetBrains 正式发布全新的 AI 开发工具,定名 AI IDE AIR
java·intellij idea
好大哥呀1 小时前
C++ Web 编程
开发语言·前端·c++
MX_93591 小时前
SpringMVC请求参数
java·后端·spring·servlet·apache
ID_180079054731 小时前
小红书笔记评论 API,Python 调用示例与完整 JSON 返回参考
java·开发语言
lifewange1 小时前
java连接Mysql数据库
java·数据库·mysql
爱学习的小仙女!1 小时前
面试题 前端(一)DOCTYPE作用 标准模式与混杂模式区分
前端·前端面试题
云原生指北2 小时前
命令行四件套:fd-rg-fzf-bat
java·大数据·elasticsearch
人间打气筒(Ada)2 小时前
go实战案例:如何通过 Service Meh 实现熔断和限流
java·开发语言·golang·web·istio·service mesh·熔断限流