[译]Vulkan教程(17)帧缓存
[译]Vulkan教程(17)帧缓存
Framebuffers 帧缓存
We've talked a lot about framebuffers in the past few chapters and we've set up the render pass to expect a single framebuffer with the same format as the swap chain images, but we haven't actually created any yet.
我们在过去的章节谈论过很多次帧缓存了,我们已经设置了render pass,希望有一个帧缓存with与交换链image相同的格式,但是我们还没有创建帧缓存。
The attachments specified during render pass creation are bound by wrapping them into a VkFramebuffer object. A framebuffer object references all of the VkImageView objects that represent the attachments. In our case that will be only a single one: the color attachment. However, the image that we have to use for the attachment depends on which image the swap chain returns when we retrieve one for presentation. That means that we have to create a framebuffer for all of the images in the swap chain and use the one that corresponds to the retrieved image at drawing time.
在创建render pass时指定的附件,通过一个VkFramebuffer 对象关联起来。帧缓存对象引用所有的VkImageView 对象that代表附件。在我们的案例中只有1个,即颜色附件。但是,用作附件的image依赖于交换链返回哪个image when我们检索一个for呈现。这意味着,我们必须创建一个帧缓存for交换链的每个image,在绘制时使用与检索到的image对应的那个帧缓存。
To that end, create another std::vector class member to hold the framebuffers:
为此,创建另一个类成员std::vector to记录这些帧缓存。
std::vector<VkFramebuffer> swapChainFramebuffers;
We'll create the objects for this array in a new function createFramebuffers that is called from initVulkan right after creating the graphics pipeline:
我们将为此数组创建对象在新函数createFramebuffers that被initVulkan 调用after创建图形管道:
void initVulkan() {
createInstance();
setupDebugCallback();
createSurface();
pickPhysicalDevice();
createLogicalDevice();
createSwapChain();
createImageViews();
createRenderPass();
createGraphicsPipeline();
createFramebuffers();
}
...
void createFramebuffers() {
}
Start by resizing the container to hold all of the framebuffers:
开始,调整容器大小to记录所有的帧缓存:
void createFramebuffers() {
swapChainFramebuffers.resize(swapChainImageViews.size());
}
We'll then iterate through the image views and create framebuffers from them:
然后我们遍历image视图,为它们创建帧缓存:
for (size_t i = ; i < swapChainImageViews.size(); i++) {
VkImageView attachments[] = {
swapChainImageViews[i]
};
VkFramebufferCreateInfo framebufferInfo = {};
framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
framebufferInfo.renderPass = renderPass;
framebufferInfo.attachmentCount = ;
framebufferInfo.pAttachments = attachments;
framebufferInfo.width = swapChainExtent.width;
framebufferInfo.height = swapChainExtent.height;
framebufferInfo.layers = ;
if (vkCreateFramebuffer(device, &framebufferInfo, nullptr, &swapChainFramebuffers[i]) != VK_SUCCESS) {
throw std::runtime_error("failed to create framebuffer!");
}
}
As you can see, creation of framebuffers is quite straightforward. We first need to specify with which renderPassthe framebuffer needs to be compatible. You can only use a framebuffer with the render passes that it is compatible with, which roughly means that they use the same number and type of attachments.
如你所见,帧缓存的创建过程是十分直观的。我们首先要指定帧缓存需要与哪个renderPass兼容。你只能用与render pass兼容的帧缓存,基本上意思是它们的附件的数量和类型相同。
The attachmentCount and pAttachments parameters specify the VkImageView objects that should be bound to the respective attachment descriptions in the render pass pAttachment array.
attachmentCount 和pAttachments 参数指定VkImageView 对象that应当被绑定到相应的附件描述信息in render pass pAttachment 数组。
The width and height parameters are self-explanatory and layers refers to the number of layers in image arrays. Our swap chain images are single images, so the number of layers is 1.
width 和height 参数是不言自明的,layers 指image数组中的layer的数量。我们的交换链image是单image,所以layer数量为1。
We should delete the framebuffers before the image views and render pass that they are based on, but only after we've finished rendering:
我们应当在删除image视图和render pass之前删除帧缓存,但是要在完成渲染之后:
void cleanup() {
for (auto framebuffer : swapChainFramebuffers) {
vkDestroyFramebuffer(device, framebuffer, nullptr);
}
...
}
We've now reached the milestone where we have all of the objects that are required for rendering. In the next chapter we're going to write the first actual drawing commands.
我们现在到达了一个里程碑where我们有了所有的对象that被要求用于渲染。下一章我们要写第一个实际的绘制命令。
C++ code / Vertex shader / Fragment shader
[译]Vulkan教程(17)帧缓存的更多相关文章
- [译]Vulkan教程(33)多重采样
[译]Vulkan教程(33)多重采样 Multisampling 多重采样 Introduction 入门 Our program can now load multiple levels of d ...
- [译]Vulkan教程(30)深度缓存
[译]Vulkan教程(30)深度缓存 Depth buffering 深度缓存 Introduction 入门 The geometry we've worked with so far is pr ...
- [译]Vulkan教程(29)组合的Image采样器
[译]Vulkan教程(29)组合的Image采样器 Combined image sampler 组合的image采样器 Introduction 入门 We looked at descripto ...
- [译]Vulkan教程(28)Image视图和采样器
[译]Vulkan教程(28)Image视图和采样器 Image view and sampler - Image视图和采样器 In this chapter we're going to creat ...
- [译]Vulkan教程(25)描述符布局和buffer
[译]Vulkan教程(25)描述符布局和buffer Descriptor layout and buffer 描述符布局和buffer Introduction 入门 We're now able ...
- [译]Vulkan教程(20)重建交换链
[译]Vulkan教程(20)重建交换链 Swap chain recreation 重建交换链 Introduction 入门 The application we have now success ...
- [译]Vulkan教程(19)渲染和呈现
[译]Vulkan教程(19)渲染和呈现 Rendering and presentation 渲染和呈现 Setup 设置 This is the chapter where everything ...
- [译]Vulkan教程(18)命令buffers
[译]Vulkan教程(18)命令buffers Command buffers 命令buffer Commands in Vulkan, like drawing operations and me ...
- [译]Vulkan教程(16)图形管道基础之总结
[译]Vulkan教程(16)图形管道基础之总结 Conclusion 总结 We can now combine all of the structures and objects from the ...
随机推荐
- Day 10 面向对象基础
目录 面对过程编程 面向对象编程 类 定义类 对象 定义对象 定制对象独有特征 面对过程编程 分析解决问题所需要的步骤, 用函数将这些步骤一步一步实现, 使用的时候一个个调用就可以了 优点: 复杂的问 ...
- 【集合系列】- 深入浅出分析 ArrayDeque
一.摘要 在 jdk1.5 中,新增了 Queue 接口,代表一种队列集合的实现,咱们继续来聊聊 java 集合体系中的 Queue 接口. Queue 接口是由大名鼎鼎的 Doug Lea 创建,中 ...
- Oracle 12C CDB、PDB常用管理命令
Oracle 12C CDB.PDB常用管理命令 --查看PDB信息(在CDB模式下) show pdbs --查看所有pdbselect name,open_mode from v$pdbs; ...
- Spring Cloud第十篇 | 分布式配置中心Config
本文是Spring Cloud专栏的第十篇文章,了解前九篇文章内容有助于更好的理解本文: Spring Cloud第一篇 | Spring Cloud前言及其常用组件介绍概览 Spring Clo ...
- Node Js模块讲解
Node JS模块 所谓的Node JS模块其实就是指Node JS package,即nodejs包. 一 什么是NodeJS模块? 在说这个问题之前,我们有必要提出一个概念,即模块规范. 现阶段J ...
- ajax数据交互
目录 一.ORM查询优化 1-1. only与defer 1-2. select_related与prefatch_related 二.MTV与MVC模型 三.choices参数 四.AJAX 4-1 ...
- 《CSAPP》实验二:二进制炸弹
二进制炸弹是第三章<程序的机器级表示>的配套实验,这章主要介绍了x64汇编,包括:操作数的表示方式,数据传送指令,算术和逻辑指令,控制流跳转指令,过程(procedure)的实现与运行时栈 ...
- 什么是Java优先级队列?
PriorityQueue是基于无界优先级队列和优先级堆构建的重要Java API之一.本文通过适当的代码示例深入了解了有关此API及其用法的一些复杂信息.另在上篇文章中我们简单地谈了下Java编译器 ...
- Linux-3.14.12内存管理笔记【伙伴管理算法(4)】
此处承接前面未深入分析的页面释放部分,主要详细分析伙伴管理算法中页面释放的实现.页面释放的函数入口是__free_page(),其实则是一个宏定义. 具体实现: [file:/include/linu ...
- render加载vue文件 vue-loader配置
默认webpack无法打包.vue文件,需要安装相关Loader安装 npm install vue-loader vue-template-compiler -D webpack.config.js ...