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;

}

相关推荐
huohaiyu44 分钟前
Hashtable,HashMap,ConcurrentHashMap之间的区别
java·开发语言·多线程·哈希
街尾杂货店&1 小时前
css word-spacing属性
前端·css
千叶寻-1 小时前
正则表达式
前端·javascript·后端·架构·正则表达式·node.js
信奥卷王2 小时前
[GESP202503 五级] 原根判断
java·数据结构·算法
小咕聊编程2 小时前
【含文档+源码】基于SpringBoot的过滤协同算法之网上服装商城设计与实现
java·spring boot·后端
Zz_waiting.2 小时前
Spring 原理
java·spring·spring自动管理
瓯雅爱分享6 小时前
Java+Vue构建的采购招投标一体化管理系统,集成招标计划、投标审核、在线竞价、中标公示及合同跟踪功能,附完整源码,助力企业实现采购全流程自动化与规范化
java·mysql·vue·软件工程·源代码管理
光影少年6 小时前
angular生态及学习路线
前端·学习·angular.js
无尽夏_8 小时前
HTML5(前端基础)
前端·html·html5
Jagger_8 小时前
敏捷开发流程-精简版
前端·后端