[译]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 ...
随机推荐
- Web 前端学习大纲
什么是前端? 前端即网站前台部分,也叫前端开发,运行在PC端,移动端等浏览器上展现给用户浏览的网页.随着互联网的发展,HTML5,CSS3,前端框架的应用,跨平台响应式网页设计能够适应各种屏幕分辨率, ...
- 比SecureCRT更好用的工具MobaXterm下载安装使用教程
一.下载 1.官网下载:下载地址 下载左边的免费版本 2.百度网盘下载:下载地址 提取码:tbge java开发工具下载地址及安装教程大全,点这里. 更多深度技术文章,在这里. 二.安装 1.双击安 ...
- NIO-SocketChannel源码分析
目录 NIO-SocketChannel源码分析 目录 前言 ServerSocketChannelImpl 创建ServerSocketChannel 绑定和监听 接收 SocketChannelI ...
- Android(常用)主流UI开源库整理
这几天刚做完一个项目..有点空余时间,就想着吧这一两年做的项目中的UI界面用到的一些库整理一下.后来想了一下,既然要整理,就把网上常用的 AndroidUI界面的主流开源库 一起整理一下,方便查看. ...
- Java 复制Excel工作表
本文归纳了关于Java如何复制Excel工作表的方法,按不同复制需求,可分为: 1. 复制工作表 1.1 在同一个工作簿内复制工作表 1.2 在不同工作簿间复制工作表 2. 复制指定单元格数据 对于复 ...
- .Net,Java,Redis,Vue等技术视屏教程分享(不定期更新)
前言 作为一个资深的收藏家决定把我收集的那些精品资源不定时更新分享给大家 .所有资源全是收集余网络或为大佬分享,内容仅供观摩学习交流之用.如果犯了您的权益,请联系我. 2019.12.19更新 ASP ...
- 《Dotnet9》系列-开源C# WPF控件库1《MaterialDesignInXAML》强力推荐
时间如流水,只能流去不流回! 点赞再看,养成习惯,这是您给我创作的动力! 本文 Dotnet9 https://dotnet9.com 已收录,站长乐于分享dotnet相关技术,比如Winform.W ...
- LeetCode 11月第2周题目汇总
开源地址:点击该链接 前言 最近比较忙,这周几乎没有刷题,只刷了6道题~ 题目汇总 0387_first_unique_character_in_a_string类似的题目比较多了,字符串中找出特别的 ...
- SuperMap iDesktop .NET 10i制图技巧-----如何贴图
当我们在没有模型数据的情况下,我们只能通过造白膜来模拟三维建筑了,但是光秃秃的建筑物显然缺乏代入感,因此需要贴图来给场景润色,本文介绍如何给道路贴图和如何给白膜贴图 道路贴图: 1.打开二维道路数据 ...
- selenium的安装、报错和解决
selenium是的作用是模拟点击浏览器上的按钮,配合一个无头浏览器就可以快速解决一些前端需要加解密的功能. 第一步pip install selenium安装的第一步就是用pip把模块下载回来. ...