imgui-wgpu-rs icon indicating copy to clipboard operation
imgui-wgpu-rs copied to clipboard

How to supply a custom sampler to a texture?

Open lwiklendt opened this issue 3 years ago • 2 comments

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.

lwiklendt avatar Jul 10 '21 12:07 lwiklendt

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

benmkw avatar Jul 15 '21 08:07 benmkw

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?

lwiklendt avatar Jul 15 '21 22:07 lwiklendt