helion_core/
renderer.rs

1use wgpu;
2
3/// Render options - shared across all renderer types
4#[derive(Debug, Clone)]
5pub struct RenderOptions {
6    pub clear_color: wgpu::Color,
7    pub point_size: f32, // TODO: Not currently used, will be implemented in future versions
8}
9
10impl Default for RenderOptions {
11    fn default() -> Self {
12        Self {
13            clear_color: wgpu::Color {
14                r: 1.0,
15                g: 1.0,
16                b: 1.0,
17                a: 1.0,
18            },
19            point_size: 2.0,
20        }
21    }
22}
23
24/// Base Renderer trait - common interface for all renderer implementations
25pub trait Renderer {
26    /// Render to the provided render pass
27    fn render_to_pass<'rpass>(&'rpass mut self, render_pass: &mut wgpu::RenderPass<'rpass>);
28}
29
30// ============================================================================
31// Specialized Renderer Traits - Added for multi-context support
32// ============================================================================
33
34/// WindowRenderer trait - specialized for native window contexts (e.g., Python bindings)
35/// 
36/// Use this when:
37/// - Creating desktop applications with native windows
38/// - You have direct access to device/queue/surface
39/// - You want simple, self-contained rendering
40pub trait WindowRenderer: Renderer {
41    /// Create a new renderer for window context
42    fn new(
43        device: &wgpu::Device,
44        config: &wgpu::SurfaceConfiguration,
45        chart_data: crate::data::ChartData,
46    ) -> Self
47    where
48        Self: Sized;
49
50    /// Update the chart data
51    fn update_data(&mut self, device: &wgpu::Device, chart_data: &crate::data::ChartData);
52}
53
54/// WebRenderer trait - specialized for web/WASM contexts
55/// 
56/// Use this when:
57/// - Building web applications (WASM targets)
58/// - You need GPUBackend for resource management
59/// - You want full control over the render loop
60pub trait WebRenderer: Renderer {
61    /// Create a new renderer with GPUBackend
62    fn new(backend: &crate::backend::GPUBackend) -> Result<Self, String>
63    where
64        Self: Sized;
65
66    /// Render with full backend context
67    fn render_with_backend(
68        &mut self,
69        backend: &crate::backend::GPUBackend,
70        data: &crate::data::ChartData,
71        options: &RenderOptions,
72    ) -> Result<(), String>;
73
74    /// Update data using backend
75    fn update_data(&mut self, backend: &crate::backend::GPUBackend, data: &crate::data::ChartData) -> Result<(), String>;
76}