pub struct QuadRenderer { /* private fields */ }Expand description
Fast batched quad renderer using GPU instancing.
Optimized for bar charts with large datasets. Key features:
- Quads stored in data coordinates
- GPU transforms data → screen (pan/zoom is cheap)
- Only rebuild instance buffer when data actually changes
Implementations§
Source§impl QuadRenderer
impl QuadRenderer
Sourcepub fn new(context: Arc<GraphicsContext>, target_format: TextureFormat) -> Self
pub fn new(context: Arc<GraphicsContext>, target_format: TextureFormat) -> Self
Create a new quad renderer with the given target texture format.
The target_format must match the render target this renderer will draw into.
For window surfaces, use the format from WindowContext::format().
Sourcepub fn add_bar(
&mut self,
x_center: f32,
width: f32,
y_bottom: f32,
y_top: f32,
color: Color,
)
pub fn add_bar( &mut self, x_center: f32, width: f32, y_bottom: f32, y_top: f32, color: Color, )
Add a bar from center x, width, y range.
Sourcepub fn quad_count(&self) -> usize
pub fn quad_count(&self) -> usize
Get the number of quads.
Sourcepub fn render(&self, pass: &mut RenderPass<'_>, viewport: Viewport)
pub fn render(&self, pass: &mut RenderPass<'_>, viewport: Viewport)
Render quads with identity transform (data coords = screen coords).
Sourcepub fn render_transformed(
&self,
pass: &mut RenderPass<'_>,
transform: &DataTransform,
)
pub fn render_transformed( &self, pass: &mut RenderPass<'_>, transform: &DataTransform, )
Render quads with a DataTransform.
This is the preferred method for rendering with data-to-screen mapping. The transform is cheap to update (32 bytes), so pan/zoom only updates the transform, not the quad data.
§Example
let transform = DataTransform::from_data_range(viewport, DataRangeParams {
plot_x: 80.0, plot_y: 20.0,
plot_width: 600.0, plot_height: 400.0,
data_x_min: 0.0, data_x_max: 100.0,
data_y_min: 0.0, data_y_max: 50.0,
});
quad_renderer.render_transformed(pass, &transform);Sourcepub fn render_with_data_transform(
&self,
pass: &mut RenderPass<'_>,
viewport: Viewport,
plot_x: f32,
plot_y: f32,
plot_width: f32,
plot_height: f32,
data_x_min: f64,
data_x_max: f64,
data_y_min: f64,
data_y_max: f64,
)
pub fn render_with_data_transform( &self, pass: &mut RenderPass<'_>, viewport: Viewport, plot_x: f32, plot_y: f32, plot_width: f32, plot_height: f32, data_x_min: f64, data_x_max: f64, data_y_min: f64, data_y_max: f64, )
Render quads with a data-to-screen transformation.
Deprecated: Use render_transformed with a
DataTransform instead for a cleaner API.
This is the fast path for charts: data doesn’t change on pan/zoom, only the transform does.
Trait Implementations§
Source§impl RenderCapability for QuadRenderer
impl RenderCapability for QuadRenderer
Source§fn requirements() -> GpuRequirements
fn requirements() -> GpuRequirements
Auto Trait Implementations§
impl Freeze for QuadRenderer
impl !RefUnwindSafe for QuadRenderer
impl Send for QuadRenderer
impl Sync for QuadRenderer
impl Unpin for QuadRenderer
impl !UnwindSafe for QuadRenderer
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
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.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more