pub struct Renderer {
pub clear_color: Color,
/* private fields */
}Expand description
One window’s renderer: its surface, the pipelines and a GPU copy of the core’s glyph atlas.
Open one per window with Renderer::new (first window, on a device
of its own) or Renderer::new_in (another window on a shared
Gpu). Each frame, hand Renderer::render the display list and
atlas from Core::output; call Renderer::resize when the window
changes size. The crate root has the whole sequence.
Fields§
§clear_color: ColorThe color a frame is cleared to before anything is drawn.
A runner usually sets it to the theme’s background each frame. It is written straight through: the renderer asks for a non-sRGB surface, so each component is the byte it lands as, the same way a quad’s color is.
Implementations§
Source§impl Renderer
impl Renderer
Sourcepub async fn new(
target: impl Into<SurfaceTarget<'static>>,
width: u32,
height: u32,
) -> Result<Renderer, Box<dyn Error>>
pub async fn new( target: impl Into<SurfaceTarget<'static>>, width: u32, height: u32, ) -> Result<Renderer, Box<dyn Error>>
A renderer for one window, on a device of its own.
width and height are the window’s size in physical pixels.
Fails when no adapter can present to target or the surface cannot
be configured. Use Renderer::new_in for every window after the
first, so they share the device.
Sourcepub fn new_in(
gpu: &Gpu,
target: impl Into<SurfaceTarget<'static>>,
width: u32,
height: u32,
) -> Result<Renderer, Box<dyn Error>>
pub fn new_in( gpu: &Gpu, target: impl Into<SurfaceTarget<'static>>, width: u32, height: u32, ) -> Result<Renderer, Box<dyn Error>>
A renderer for another window on an existing device, the one every
window of the app shares. Get gpu from the first renderer’s
Renderer::gpu.
Sourcepub fn set_frame_latency(&mut self, frames: u32)
pub fn set_frame_latency(&mut self, frames: u32)
Sets how many frames may be queued ahead of the one on screen (at
least one; see DEFAULT_FRAME_LATENCY). Reconfigures the surface
when the value changes.
Sourcepub fn frame_latency(&self) -> u32
pub fn frame_latency(&self) -> u32
The frame latency the surface is configured with.
Sourcepub fn subpixel_text(&self) -> bool
pub fn subpixel_text(&self) -> bool
Whether this device can draw LCD subpixel glyphs
(QuadKind::GlyphSubpixel) as intended.
Pass it to Core::set_subpixel_text once after opening the
renderer; when it is false the core keeps rasterizing grayscale
masks, which every device blends correctly.
Sourcepub fn resize(&mut self, width: u32, height: u32)
pub fn resize(&mut self, width: u32, height: u32)
Reconfigures the swapchain for a new window size, in physical pixels.
The size is clamped to at least 1 (a minimized window reports zero, and a zero-sized surface is a validation error) and to the device’s largest texture (Windows hands out nonsense sizes mid-resize, and configuring past the limit panics inside wgpu). A clamped frame is one wrong picture; the next real size fixes it.
Sourcepub fn render(
&mut self,
dl: &DisplayList,
atlas: &mut GlyphAtlas,
) -> Result<RenderReport, RenderError>
pub fn render( &mut self, dl: &DisplayList, atlas: &mut GlyphAtlas, ) -> Result<RenderReport, RenderError>
Draws one frame and presents it.
Uploads the atlas when it changed since the last frame (and clears
its dirty flag), writes the list’s quads to the instance buffer,
draws them over Renderer::clear_color in one render pass, and
presents. Acquiring the swapchain image blocks while vsync holds
the frame back; that time comes back as
RenderReport::vsync_wait_ms so a runner can tell pacing from
work.
Fails without presenting when the surface or the device cannot
take the frame; each RenderError says what to do next.
Auto Trait Implementations§
impl !Freeze for Renderer
impl !RefUnwindSafe for Renderer
impl !UnwindSafe for Renderer
impl Send for Renderer
impl Sync for Renderer
impl Unpin for Renderer
impl UnsafeUnpin for Renderer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.