Skip to main content

Renderer

Struct Renderer 

Source
pub struct Renderer { /* private fields */ }
Expand description

Rasterizador vectorial. Una instancia por surface (porque vello cachea resources contra un surface_format específico).

Implementations§

Source§

impl Renderer

Source

pub fn new(hal: &Hal) -> Result<Self, RasterError>

Inicializa el rasterizador. Vello acepta cualquier textura compatible (Rgba8Unorm / Bgra8Unorm) en render, así que no se fija un formato en construcción.

antialiasing_support: pedimos area solamente, no all(). area es el único método que render() usa (AaConfig::Area fijo). Pedir all() haría a vello compilar también pipelines para msaa8 y msaa16 que nunca se invocan — en Mali-G57 eso triplica el cold-start (medido: 3.7s vs ~1.2s). Si alguna app futura necesita MSAA, agregamos un constructor explícito.

num_init_threads: None: vello paraleliza la compilación de shaders en None → todos los CPU cores. Mali-G57 viene en SoCs octa-core ARM; con 1 thread tardamos 2.0s, con 8 esperamos ~400-600ms. La compilación de shaders es 100% CPU (Rust → SPIR-V), el GPU no participa, así que multi-thread escala casi linealmente hasta saturar el queue del Naga compiler.

Examples found in repository?
examples/render_node.rs (line 47)
33    fn resumed(&mut self, event_loop: &ActiveEventLoop) {
34        if self.state.is_some() {
35            return;
36        }
37        let window = event_loop
38            .create_window(
39                WindowAttributes::default()
40                    .with_title("llimphi · render_node")
41                    .with_inner_size(LogicalSize::new(960u32, 540u32)),
42            )
43            .expect("create window");
44        let window = Arc::new(window);
45        let hal = pollster::block_on(Hal::new(None)).expect("hal");
46        let surface = WinitSurface::new(&hal, window.clone()).expect("surface");
47        let renderer = Renderer::new(&hal).expect("renderer");
48        window.request_redraw();
49        self.state = Some(State {
50            window,
51            hal,
52            surface,
53            renderer,
54            scene: vello::Scene::new(),
55        });
56    }
Source

pub fn render( &mut self, hal: &Hal, scene: &Scene, frame: &Frame, base_color: Color, ) -> Result<(), RasterError>

Renderiza scene sobre frame limpiando con base_color. AA fija en area-sampling (precisión Δ < 10⁻⁹ rad del SDD).

Examples found in repository?
examples/render_node.rs (lines 86-91)
58    fn window_event(
59        &mut self,
60        event_loop: &ActiveEventLoop,
61        _id: WindowId,
62        event: WindowEvent,
63    ) {
64        let Some(state) = self.state.as_mut() else {
65            return;
66        };
67        match event {
68            WindowEvent::CloseRequested => event_loop.exit(),
69            WindowEvent::Resized(size) => {
70                state.surface.resize(size.width, size.height);
71                state.window.request_redraw();
72            }
73            WindowEvent::RedrawRequested => {
74                let frame = match state.surface.acquire() {
75                    Ok(f) => f,
76                    Err(_) => {
77                        let (w, h) = state.surface.size();
78                        state.surface.resize(w, h);
79                        state.window.request_redraw();
80                        return;
81                    }
82                };
83                let (w, h) = frame.size();
84                state.scene.reset();
85                build_node(&mut state.scene, w as f64, h as f64, self.started.elapsed().as_secs_f64());
86                if let Err(e) = state.renderer.render(
87                    &state.hal,
88                    &state.scene,
89                    &frame,
90                    palette::css::BLACK,
91                ) {
92                    eprintln!("render error: {e}");
93                }
94                state.surface.present(frame, &state.hal);
95                state.window.request_redraw();
96            }
97            _ => {}
98        }
99    }
Source

pub fn render_to_view( &mut self, hal: &Hal, scene: &Scene, view: &TextureView, width: u32, height: u32, base_color: Color, ) -> Result<(), RasterError>

Como render pero contra una vista de textura explícita (mismo formato/tamaño que la intermedia). Lo usa el compositor de overlay de llimphi-ui para rasterizar la capa de overlay sobre fondo transparente en su propia textura. Ojo: render_to_texture limpia el target con base_color y escribe todos los píxeles — no compone sobre contenido previo.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more