pub struct WgpuRenderer { /* private fields */ }Expand description
The wgpu renderer.
Implementations§
Source§impl WgpuRenderer
impl WgpuRenderer
Sourcepub fn offscreen(ctx: &GpuContext) -> Self
pub fn offscreen(ctx: &GpuContext) -> Self
A renderer that draws into its own texture; read it back with
read_pixels. The texture is sized by each frame.
Sourcepub fn with_surface(
ctx: &GpuContext,
surface: Surface<'static>,
size: SizePx,
) -> Result<Self, RenderError>
pub fn with_surface( ctx: &GpuContext, surface: Surface<'static>, size: SizePx, ) -> Result<Self, RenderError>
A renderer that presents to surface (created from ctx.instance).
§Errors
RenderError::Backend if the surface is not supported by the adapter,
RenderError::InvalidSize for a zero or too large size.
Sourcepub fn take_gpu_error(&mut self) -> Option<String>
pub fn take_gpu_error(&mut self) -> Option<String>
The first GPU error (validation, out of memory) reported since the
last call, with wgpu’s message. A frame during which such an error
occurred makes Renderer::render return RenderError::Backend.
The renderer installs the device’s uncaptured-error handler; with several renderers on one device, the last one created receives them.
Sourcepub fn register_series(&mut self, series: Box<dyn GpuSeries>)
pub fn register_series(&mut self, series: Box<dyn GpuSeries>)
Registers the native implementation of a custom series kind,
replacing an earlier one of the same kind. The kind is then in
Renderer::native_kinds; pass those to Chart::set_native_kinds
(the host helpers do it before every frame). Do not register an
implementation that needs compute shaders on WebGL2.
Sourcepub fn measurer(&self) -> EngineMeasurer<'_>
pub fn measurer(&self) -> EngineMeasurer<'_>
The text measurer to pass to Chart::build_frame.
Sourcepub fn text_engine_mut(&mut self) -> &mut TextEngine
pub fn text_engine_mut(&mut self) -> &mut TextEngine
The text engine (to add fonts).
Sourcepub fn series_chunks(&self) -> usize
pub fn series_chunks(&self) -> usize
Bytes of GPU vertex buffers held for series data.
Sourcepub fn offscreen_texture(&self) -> Option<&Texture>
pub fn offscreen_texture(&self) -> Option<&Texture>
The texture an offscreen renderer drew the last frame into, for hosts
that compose the chart into their own rendering (a UI toolkit’s paint
callback, a game engine). None for a renderer created with
with_surface and before the first frame.
The format is Rgba8Unorm holding sRGB-encoded colors (the CPU
backend’s pixels): sample it as is and write the values to a
non-sRGB target, or convert them to linear before writing to an sRGB
one. The usages are RENDER_ATTACHMENT | COPY_SRC | TEXTURE_BINDING.
The texture is replaced when the frame size changes, so look it up
after each Renderer::render rather than keeping it.
use ferrochart_core::geom::SizeCss;
use ferrochart_core::render::Renderer;
use ferrochart_core::{Chart, ChartOptions};
use ferrochart_render_wgpu::{GpuContext, WgpuRenderer};
let ctx = GpuContext::headless()?;
let mut renderer = WgpuRenderer::offscreen(&ctx);
let mut chart = Chart::new(ChartOptions::default());
chart.resize(SizeCss { w: 800.0, h: 450.0 }, 2.0);
chart.build_frame(0.0, &renderer.measurer());
renderer.render(chart.frame(), &chart.data_view())?;
let texture = renderer.offscreen_texture().ok_or("no frame yet")?;
assert_eq!((texture.width(), texture.height()), (1600, 900));
// Bind `renderer.offscreen_view()` in the host's own pipeline.Sourcepub fn offscreen_view(&self) -> Option<&TextureView>
pub fn offscreen_view(&self) -> Option<&TextureView>
A view of the whole offscreen_texture
(same lifetime and conditions), ready to bind for sampling.
Sourcepub fn read_pixels(&self) -> Result<Vec<u8>, RenderError>
pub fn read_pixels(&self) -> Result<Vec<u8>, RenderError>
Reads the offscreen target back as tightly packed RGBA8 rows.
§Errors
RenderError::InvalidSize if this is not an offscreen renderer or
nothing was rendered, RenderError::Backend if mapping fails.
Trait Implementations§
Source§impl Debug for WgpuRenderer
impl Debug for WgpuRenderer
Source§impl Renderer for WgpuRenderer
impl Renderer for WgpuRenderer
Source§fn render(
&mut self,
frame: &Frame,
data: &ChartDataView<'_>,
) -> Result<(), RenderError>
fn render( &mut self, frame: &Frame, data: &ChartDataView<'_>, ) -> Result<(), RenderError>
data.changes_since), then draws frame. On error the synced generations
must not advance, so the next call catches up. Read moreSource§fn native_kinds(&self) -> &[&'static str]
fn native_kinds(&self) -> &[&'static str]
crate::Chart::set_native_kinds. None by default.