Image views

To use any VkImage, including those in the swap chain, in the render pipeline we have to create a VkImageViewobject. An image view is quite literally a view into an image. It describes how to access the image and which part of the image to access, for example if it should be treated as a 2D texture depth texture without any mipmapping levels.

要使用任何VkImage,包括在交换链中的那些,我们必须在渲染管道中创建一个VkImageView对象。一个image视图就是对image 的一个视图。它描述了,如何存取image,存取image 的哪一部分。例如,image应该被视为2D深度纹理,不含mipmap层。

In this chapter we'll write a createImageViews function that creates a basic image view for every image in the swap chain so that we can use them as color targets later on.

本章,我们将写一个createImageViews 函数,它为交换链中的每个image分别创建一个基础的image view,这样,我们就可以将它们当作颜色目标来用了。

First add a class member to store the image views in:

首先,添加成员以保存image view:

std::vector<VkImageView> swapChainImageViews;

Create the createImageViews function and call it right after swap chain creation.

创建createImageViews 函数,在创建交换链后调用它。

void initVulkan() {
createInstance();
setupDebugCallback();
createSurface();
pickPhysicalDevice();
createLogicalDevice();
createSwapChain();
createImageViews();
} void createImageViews() { }

The first thing we need to do is resize the list to fit all of the image views we'll be creating:

首先,调整list的大小,以适应我们要创建的image view的数量:

void createImageViews() {
swapChainImageViews.resize(swapChainImages.size()); }

Next, set up the loop that iterates over all of the swap chain images.

接下来,在循环中枚举所有的交换链image。

for (size_t i = ; i < swapChainImages.size(); i++) {

}

The parameters for image view creation are specified in a VkImageViewCreateInfo structure. The first few parameters are straightforward.

创建image view的参数由VkImageViewCreateInfo 结构体提供。前几个参数很直观。

VkImageViewCreateInfo createInfo = {};
createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
createInfo.image = swapChainImages[i];

The viewType and format fields specify how the image data should be interpreted. The viewType parameter allows you to treat images as 1D textures, 2D textures, 3D textures and cube maps.

字段viewType 和format 标明了image数据应当被如何解释。参数viewType 允许你将image当作1D纹理、2D纹理、3D纹理或cube纹理。

createInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
createInfo.format = swapChainImageFormat;

The components field allows you to swizzle the color channels around. For example, you can map all of the channels to the red channel for a monochrome texture. You can also map constant values of 0 and 1 to a channel. In our case we'll stick to the default mapping.

字段components 允许你搅和颜色通道。例如,你可以将所有通道都映射到红色通道,实现黑白纹理。你也可以映射01的常量到某个通道。在我们的案例中,我们使用默认的映射。

createInfo.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
createInfo.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
createInfo.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
createInfo.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;

The subresourceRange field describes what the image's purpose is and which part of the image should be accessed. Our images will be used as color targets without any mipmapping levels or multiple layers.

字段subresourceRange 描述了image的用途,还有要用image的哪一部分。我们的image要被用作颜色目标,不含mipmap层,不含多个layer。

createInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
createInfo.subresourceRange.baseMipLevel = ;
createInfo.subresourceRange.levelCount = ;
createInfo.subresourceRange.baseArrayLayer = ;
createInfo.subresourceRange.layerCount = ;

If you were working on a stereographic 3D application, then you would create a swap chain with multiple layers. You could then create multiple image views for each image representing the views for the left and right eyes by accessing different layers.

如果你在做一个立体3D应用程序,那么你得创建一个多layer的交换链。然后你就可以为每个image创建多个image view,不同的layer分别代表从左眼和右眼观察。

Creating the image view is now a matter of calling vkCreateImageView:

现在只需调用vkCreateImageView函数来创建image view:

if (vkCreateImageView(device, &createInfo, nullptr, &swapChainImageViews[i]) != VK_SUCCESS) {
throw std::runtime_error("failed to create image views!");
}

Unlike images, the image views were explicitly created by us, so we need to add a similar loop to destroy them again at the end of the program:

与image不同,image view是由我们显式地创建的,所以我们需要在程序结束时添加一个相似的循环来销毁它们:

void cleanup() {
for (auto imageView : swapChainImageViews) {
vkDestroyImageView(device, imageView, nullptr);
} ...
}

An image view is sufficient to start using an image as a texture, but it's not quite ready to be used as a render target just yet. That requires one more step of indirection, known as a framebuffer. But first we'll have to set up the graphics pipeline.

有了image view就可以将image用作纹理了,但是它还没有准备好被用作渲染目标。那需要下一步的操作,即帧缓存。但是,首先我们必须创建图形管道。

C++ code

[译]Vulkan教程(11)Image Views的更多相关文章

  1. [译]Vulkan教程(26)描述符池和set

    [译]Vulkan教程(26)描述符池和set Descriptor pool and sets 描述符池和set Introduction 入门 The descriptor layout from ...

  2. [译]Vulkan教程(28)Image视图和采样器

    [译]Vulkan教程(28)Image视图和采样器 Image view and sampler - Image视图和采样器 In this chapter we're going to creat ...

  3. [译]Vulkan教程(25)描述符布局和buffer

    [译]Vulkan教程(25)描述符布局和buffer Descriptor layout and buffer 描述符布局和buffer Introduction 入门 We're now able ...

  4. [译]Vulkan教程(20)重建交换链

    [译]Vulkan教程(20)重建交换链 Swap chain recreation 重建交换链 Introduction 入门 The application we have now success ...

  5. [译]Vulkan教程(17)帧缓存

    [译]Vulkan教程(17)帧缓存 Framebuffers 帧缓存 We've talked a lot about framebuffers in the past few chapters a ...

  6. [译]Vulkan教程(03)开发环境

    [译]Vulkan教程(03)开发环境 这是我翻译(https://vulkan-tutorial.com)上的Vulkan教程的第3篇. In this chapter we'll set up y ...

  7. [译]Vulkan教程(02)概况

    [译]Vulkan教程(02)概况 这是我翻译(https://vulkan-tutorial.com)上的Vulkan教程的第2篇. This chapter will start off with ...

  8. [译]Vulkan教程(01)入门

    [译]Vulkan教程(01)入门 接下来我将翻译(https://vulkan-tutorial.com)上的Vulkan教程.这可能是我学习Vulkan的最好方式,但不是最理想的方式. 我会用“d ...

  9. [译]Vulkan教程(33)多重采样

    [译]Vulkan教程(33)多重采样 Multisampling 多重采样 Introduction 入门 Our program can now load multiple levels of d ...

随机推荐

  1. electron中JS报错:require is not defined的问题解决方法

    Electron已经发布了6.0正式版,升级后发现原来能运行的代码报错提示require is not defined 解决办法: 修改创建BrowserWindow部分的相关代码,设置属性webPr ...

  2. JS基础-事件

    事件机制 事件触发三阶段 事件触发有三个阶段: window 往事件触发处传播,遇到注册的捕获事件会触发 传播到事件触发处时触发注册的事件 从事件触发处往 window 传播,遇到注册的冒泡事件会触发 ...

  3. Oracle 12C CDB、PDB常用管理命令

    Oracle 12C CDB.PDB常用管理命令 --查看PDB信息(在CDB模式下) show pdbs  --查看所有pdbselect name,open_mode from v$pdbs;  ...

  4. Elasticsearch系列---搜索分页和deep paging问题

    概要 本篇从介绍搜索分页为起点,简单阐述分页式数据搜索与原有集中式数据搜索思维方式的差异,就分页问题对deep paging问题的现象进行分析,最后介绍分页式系统top N的案例. 搜索分页语法 El ...

  5. Windows10 中的字母映射表

    有很多朋友为寻找特殊字符串而感到烦恼, windows10中的字符映射表有所有字体 包含的特殊符号 windows键 + R键 输入 charmap 点击确定 即可出现 字母映射表 可在字符的下拉按钮 ...

  6. 《Android项目实战--手机安全卫士》读后感

    上学期在学校图书馆看到此书,觉得比较贴近实践,于是寒假研究了一番,也算是体会了一把社会培训机构的模式. 由于时间关系,最后两章还没弄完,但感觉每章节的流程相似,加之马上要回学校了,所以打算在家的最后一 ...

  7. linux之寻找男人的帮助,man和info,

    1.在linux下寻求帮助是一个很好的习惯,幸运的是系统提供了帮助的命令man和info,由于linux指令很多,记忆起来简直麻烦,比如以a开头的指令有100条,linux命令算起来得几千条,记忆却是 ...

  8. Python连载58-http协议简介

    一.http协议实战 1.URL(Uniform Resource Located) (1)使用FFTP的URL,例如:ftp://rtfm.mit.edu (2)使用HTTP的URL,例如:http ...

  9. iOS核心动画高级技巧-4

    8. 显式动画 显式动画 如果想让事情变得顺利,只有靠自己 -- 夏尔·纪尧姆 上一章介绍了隐式动画的概念.隐式动画是在iOS平台创建动态用户界面的一种直接方式,也是UIKit动画机制的基础,不过它并 ...

  10. JS reduce()方法详解,使用reduce数组去重

     壹 ❀ 引 稍微有了解JavaScript数组API的同学,对于reduce方法至少有过一面之缘,也许是for与forEach太强大,或者filter,find很实用,在实际开发中我至始至终没使用过 ...