1pub mod draw;
22mod draw_shaded;
23pub mod options;
24mod shaded_theme;
25mod surface;
26
27use crate::draw::{CustomPipeBuilder, DrawPipe};
28use kas::runner::{self, HasDisplayAndWindowHandle, RunError};
29
30pub use draw_shaded::{DrawShaded, DrawShadedImpl};
31pub use options::Options;
32pub use shaded_theme::ShadedTheme;
33pub extern crate wgpu;
34
35pub struct Instance<CB: CustomPipeBuilder> {
37 options: Options,
38 instance: wgpu::Instance,
39 custom: CB,
40}
41
42impl<CB: CustomPipeBuilder> Instance<CB> {
43 pub fn new(options: Options, custom: CB) -> Self {
48 let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
49 backends: options.backend(),
50 ..Default::default()
51 });
52
53 Instance {
54 options,
55 instance,
56 custom,
57 }
58 }
59}
60
61impl<CB: CustomPipeBuilder> runner::GraphicsInstance for Instance<CB> {
62 type Shared = DrawPipe<CB::Pipe>;
63
64 type Surface = surface::Surface<CB::Pipe>;
65
66 fn new_shared(
67 &mut self,
68 surface: Option<&Self::Surface>,
69 features: runner::GraphicsFeatures,
70 ) -> Result<Self::Shared, RunError> {
71 DrawPipe::new(
72 &self.instance,
73 &mut self.custom,
74 &self.options,
75 surface.map(|s| &s.surface),
76 features,
77 )
78 }
79
80 fn new_surface(
81 &mut self,
82 window: std::sync::Arc<dyn HasDisplayAndWindowHandle + Send + Sync>,
83 transparent: bool,
84 ) -> std::result::Result<Self::Surface, RunError>
85 where
86 Self: Sized,
87 {
88 surface::Surface::new(&self.instance, window, transparent)
89 }
90}