Yatekii / imgui-wgpu-rs

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

Better texture support #20

Closed N3xed closed 3 years ago

N3xed commented 4 years ago

A texture is now represented by the Texture struct. Its texture data can now be uploaded and updated with Texture::write(). Made the Renderer::textures field publicly accessible (it's used to manage existing textures). Changed Renderer::reload_font_texture() to take into account possible preuploaded font atlas textures. Added some documentation to the Texture struct and its methods.

I've also incorporated the commit Aeledfyr@af054c9a21524fed4c8746f06473d852af7790e1 (@Aeledfyr I hope it's OK), which enables to pass a depth format and MSAA sample count when creating a new renderer.

N3xed commented 3 years ago

I added a TextureConfig and RendererConfig struct as you've requested. These structs use the builder pattern. The RendererConfig is now also used to specify the fragment and vertex shaders, because of that the functions Renderer::new_glsl(), Renderer::new() and Renderer::new_static() became pretty pointless. There is now a single constructor function Renderer::new() that takes the RendererConfig struct as an argument.

As described in the commit message, I've also added the possibility to use custom shaders for the renderer with the RendererConfig::with_shaders() function. This function is also used by the new() and new_glsl() functions, that use either the precompiled or newly compiled default shaders.

In my previous commits I made Renderer::textures public, because of that the new texture management methods Renderer::insert_texture(), Renderer::replace_texture() and Renderer::texture_view() aren't needed anymore, so I've removed them. As for texture_view(), I've added the Texture::view() and Texture::texture() accessors that allow the same functionality. Because the two configuration structs use the builder pattern, I've also added the convenience method build() to each of them, which allows to directly create a Texture or Renderer from the configuration.

As per #23, I've added the possibility to create a Texture from its raw parts (wgpu::Texture, wgpu::TextureView, wgpu::BindGroup and wgpu::Extent3d). As far as I know, the texture is automatically deleted from the GPU when it is dropped and you can manage the textures now with the Renderer::textures field.

Hopefully, these changes are satisfactory. Also, it seems that the macOS-latest test somehow, didn't execute correctly? Not sure why that is.