[vello_hybrid] Resources are now tied to Renderer instance change
C-hybrid
This change here: https://github.com/linebender/vello/pull/1794 makes it hard to do multi threaded font rendering.
I have not spent a lot of time investigating an alternate approach, but in `bevy_vello` for example we have:
```rust
thread_local! {
pub static LOCAL_FONT_CONTEXT: RefCell<Option<FontContext>> = const { RefCell::new(None) };
pub static LOCAL_LAYOUT_CONTEXT: RefCell<LayoutContext<Brush>> = RefCell::new(LayoutContext::new());
}
```
In my bespoke engine I _(and if bevy_vello wants to)_ use vello_hybrid instead, I had to do this and maybe still have to do:
```rust
thread_local! {
pub static LOCAL_FONT_CONTEXT: RefCell<Option<FontContext>> = const { RefCell::new(None) };
pub static LOCAL_LAYOUT_CONTEXT: RefCell<LayoutContext<Brush>> = RefCell::new(LayoutContext::new());
pub static LOCAL_RESOURCES: RefCell<Resources> = RefCell::new(Resources::default());
}
```
```rust
LOCAL_FONT_CONTEXT.with_borrow_mut(|font_context| {
if font_context.is_none() {
*font_context = Some(get_global_font_context().clone());
}
let font_context = font_context.as_mut().unwrap();
LOCAL_LAYOUT_CONTEXT.with_borrow_mut(|layout_context| {
self.build_layout(font_context, layout_context);
LOCAL_RESOURCES.with_borrow_mut(|resources| {
let mut builder = scene.glyph_run(resources, font_data);
});
});
```
0 条评论