Wgpu-rs: Question about `encoder.copy_texture_to_texture` with SwapChainTexture as the destination

Created on 29 Aug 2020  路  1Comment  路  Source: gfx-rs/wgpu-rs

I'm trying to draw a 2d texture directly onto the screen without vertices and shaders. Based on this Stackoverflow question it seems like all I have to do is copying the texture to the swap chain texture.

CommandEncoder::copy_texture_to_texture accepts a TextureCopyView as the destination

fn copy_texture_to_texture(
        &mut self,
        source: TextureCopyView,
        destination: TextureCopyView,
        copy_size: Extent3d,
    )
pub struct TextureCopyView<T> {
    pub texture: T,
    pub mip_level: u32,
    pub origin: Origin3d,
}

where T has type &'a Texture.

However, by calling SwapChain::get_current_frame() I get this:

pub struct SwapChainTexture {
    pub view: TextureView,
    detail: <C as Context>::SwapChainOutputDetail,
}

which only has a TextureView available to me.

I saw that for wgpu 0.3.0 there used to be a texture field in SwapChainOutput, which presumably can be used to construct my TextureCopyView. This was deleted in 0.4.0. So what would be the correct way to copy a texture to a SwapChainTexture?

Thank you for answering my question!

question

Most helpful comment

Unfortunately due to compatibility, the only way to write data to the swapchain image is by rendering to it. In your case you should render a fullscreen triangle and copy from your framebuffer. This may end up being faster as there are a couple of optimizations drivers can do but only when they render.

>All comments

Unfortunately due to compatibility, the only way to write data to the swapchain image is by rendering to it. In your case you should render a fullscreen triangle and copy from your framebuffer. This may end up being faster as there are a couple of optimizations drivers can do but only when they render.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

imjasonmiller picture imjasonmiller  路  3Comments

rukai picture rukai  路  5Comments

RazrFalcon picture RazrFalcon  路  3Comments

kvark picture kvark  路  3Comments

dmilford picture dmilford  路  3Comments