Skip to content

Latest commit

 

History

History
46 lines (43 loc) · 1.33 KB

1.7创建图片视图和帧缓冲.md

File metadata and controls

46 lines (43 loc) · 1.33 KB

图片视图和帧缓冲

什么是图像视图? 就是一个对象在内存中连续的装了一个或一堆的图像结束. 什么是帧缓冲? 跟上面一样,也是装了一堆帧的一块内存.

// 创建图像视图
let image_views: Vec<_> = backbuffer
    .into_iter()
    .map(|image| unsafe {
        device
            .create_image_view(
                &image,
                ViewKind::D2,
                format,
                Swizzle::NO,
                SubresourceRange {
                    aspects: Aspects::COLOR,
                    levels: 0..1,
                    layers: 0..1,
                },
            )
            .map_err(|_| "为图像创建图像视图失败")
    })
    .collect::<Result<Vec<_>, &str>>()?;

// 创建帧缓冲
let framebuffers: Vec<<back::Backend as Backend>::Framebuffer> = {
    image_views
        .iter()
        .map(|image_view| unsafe {
            device
                .create_framebuffer(
                    &render_pass,
                    vec![image_view],
                    Extent {
                        width: extent.width as u32,
                        height: extent.height as u32,
                        depth: 1,
                    },
                )
                .map_err(|_| "创建帧缓冲失败")
        })
        .collect::<Result<Vec<_>, &str>>()?
};