Yatekii / imgui-wgpu-rs

Dear imgui renderer for wgpu-rs.
MIT License
256 stars 84 forks source link

How to supply a custom sampler to a texture? #60

Open lwiklendt opened 3 years ago

lwiklendt commented 3 years ago

At the moment the only way of creating a Texture with your own sampler (e.g. for nearest mag filtering) is to call Texture::from_raw_parts. However, to create a binding group we need to supply a shared reference to the texture layout which is currently a private field in the Renderer struct. The way I'm getting around it at the moment is to copy-paste the texture layout code from Renderer::new, but a better approach would be either for Renderer to have a function that returns the texture layout as a shared reference, or for Texture to have a new method that takes a SamplerDescriptor.

benmkw commented 3 years ago

or for Texture to have a new method that takes a SamplerDescriptor

At first glance it seems that you could move the SamplerDescriptor creation which is currently in Texture::new into the default impl for TextureConfig and expose it that way. (If you don't just need the SamplerDescriptor, but also the Sampler then this won't work because of the dependency on the device...)

Using ..Default() for TextureConfig means that this does not impact other users.

see https://github.com/Yatekii/imgui-wgpu-rs/pull/35/files for reference

lwiklendt commented 3 years ago

At first glance it seems that you could move the SamplerDescriptor creation which is currently in Texture::new into the default impl for TextureConfig and expose it that way. ... Using ..Default() for TextureConfig means that this does not impact other users.

This would work fine. It is backwards incompatible since it will break for users not using ..Default() which should only be done for a major semver change, but being a 0.x semver I guess it's ok?