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;

}

相关推荐
新中地GIS开发老师10 分钟前
25年GIS开发暑期实训营,15天Get三维可视化智慧城市开发项目
前端·人工智能·智慧城市·web·gis开发·webgis·地信
m0_3765340717 分钟前
flutter使用html_editor_enhanced: ^2.6.0后,编辑框无法获取焦点,无法操作
前端·flutter·html
行星00823 分钟前
docker常用命令
java·云原生·eureka
magic 2451 小时前
实时同步缓存,与阶段性同步缓存——补充理解《补充》
java·redis·mysql
牛马baby1 小时前
Java高频面试之并发编程-23
java·开发语言·面试
阿幸软件杂货间1 小时前
谷歌浏览器Google Chrome v137.0.7151.41 中文版本版+插件 v1.11.1
前端·chrome
難釋懷1 小时前
Vue 实例生命周期
前端·javascript·vue.js
hqxstudying1 小时前
Redis击穿,穿透和雪崩详解以及解决方案
java·数据库·redis·缓存
玹之又玹1 小时前
Kafka 客户端连接机制的一个典型陷阱
java·kafka
白初&1 小时前
CVE-2024-27348
java·安全