hecrj / wgpu_glyph

A fast text renderer for wgpu (https://github.com/gfx-rs/wgpu)
https://docs.rs/wgpu_glyph
MIT License
443 stars 77 forks source link

GlyphBrush bundles upstream GlyphBrush and Pipeline #23

Closed dhardy closed 4 years ago

dhardy commented 4 years ago

I wish to calculate an optimal window size (using GlyphCruncher::glyph_bounds), then create that window. Resizing the window after creation has unwanted side-effects.

Using wgpu_glyph it does not appear that I am able to do this, at least without creating the GlyphBrush twice. Yet from examining the source, it appears that the only reason for this is that GlyphBrush encapsulates both the glyph_brush and the pipeline.

Probably the simplest solution (though awkward) is to allow a GlyphBrush to be created from an existing object of the upstream GlyphBrush type.

hecrj commented 4 years ago

Resizing the window after creation has unwanted side-effects.

Do you mean for your particular use case? wgpu_glyph should work well as long as you resize your swap chain correctly.

Using wgpu_glyph it does not appear that I am able to do this, at least without creating the GlyphBrush twice.

Could you elaborate a bit on this? You only need wgpu::Device to create a GlyphBrush, which can be obtained in wgpu without a window. You do not need a window for rendering either, as you can obtain a TextureView from any Texture. Maybe there is something particular to your use case that I am missing?


In any case, I agree that the GlyphBrush struct is doing way too much stuff. We should split it and define clear boundaries, maybe exposing the Cache as a first-class concept of the API.

I will most likely end up building a new text rendering crate at some point for iced with text shaping support. I'd like to wait until then before refactoring wgpu_glyph.

dhardy commented 4 years ago

I finally got around to solving my issue by resizing after creation: https://github.com/kas-gui/kas/pull/69

Regarding the other point about caches, I just opened this: https://github.com/alexheretic/glyph-brush/issues/97