wgpu::Texture -> wgpu::TextureView?

I have an wgpu::Texture; I want a wgpu::TextureView

Now, I see this function pub fn create_view(&self, desc: &TextureViewDescriptor<'_>) -> TextureView but I do not have a TextureViewDescriptor

Now, wgpu::Texture itself has a TextureViewDescriptor but it is not public

pub struct Texture {
    context: Arc<C>,
    id: ObjectId,
    data: Box<Data>,
    owned: bool,
    descriptor: TextureDescriptor<'static>,
}

Is there anyway to do wgpu::Texture -> wgpu::TextureView without forking the wgpu package ? I feel like I am missing something very very obvious.

TextureViewDescriptor should be public: TextureViewDescriptor in wgpu - Rust

1 Like

The TextureViewDescriptor field of Texture is private:

pub struct Texture {
    context: Arc<C>,
    id: ObjectId,
    data: Box<Data>,
    owned: bool,
    descriptor: TextureDescriptor<'static>,
}

(Just browsing docs but) TextureViewDescriptor implements Default.

Incidentally if you search a type name, you can then click "In Return Types". That's how I found the implementation.

1 Like

That field is a TextureDescriptor, not a TextureViewDescriptor. A single texture can be interpreted in multiple ways. It could be interpreted as a regular 2D image, as a cube map, as a 3D image and so on. You could use varying mipmap levels.You could have a single layer or multiple. And in the future it may be possible to interpret a texture as an srgb image at one time and a linearrgb image at another time. The TextureViewDescriptor describes how you want to interpret the texture for this specific texture view.

1 Like

Ah, thank you. This stupid mistake on my part completely threw me off. Combined with @quinedot 's link to Default, everything makes sense now. Thanks!