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;

}

相关推荐
该用户已不存在8 分钟前
macOS是开发的终极进化版吗?
前端·后端
小豆包api24 分钟前
小豆包AI API × Nano Banana:3D手办 + AI视频生成,「动起来」的神级玩法!
前端·api
ytadpole30 分钟前
揭秘设计模式:工厂模式的五级进化之路
java·设计模式
计算机毕业设计木哥30 分钟前
计算机毕设选题:基于Python+Django的B站数据分析系统的设计与实现【源码+文档+调试】
java·开发语言·后端·python·spark·django·课程设计
失散1331 分钟前
分布式专题——1.2 Redis7核心数据结构
java·数据结构·redis·分布式·架构
布列瑟农的星空1 小时前
大话设计模式——观察者模式和发布/订阅模式的区别
前端·后端·架构
龙在天1 小时前
Vue3 实现 B站 视差 动画
前端
KenXu1 小时前
F2C Prompt to Design、AI 驱动的设计革命
前端
小鱼儿亮亮1 小时前
canvas中画线条,线条效果比预期宽1像素且模糊问题分析及解决方案
前端·react.js
@大迁世界1 小时前
用 popover=“hint“ 打造友好的 HTML 提示:一招让界面更“懂人”
开发语言·前端·javascript·css·html