1#![cfg_attr(docsrs, feature(doc_auto_cfg))]
22
23pub mod draw;
24mod draw_shaded;
25pub mod options;
26mod shaded_theme;
27mod surface;
28
29use crate::draw::{CustomPipeBuilder, DrawPipe};
30use kas::runner::{self, Result};
31use wgpu::rwh;
32
33pub use draw_shaded::{DrawShaded, DrawShadedImpl};
34pub use options::Options;
35pub use shaded_theme::ShadedTheme;
36pub extern crate wgpu;
37
38pub struct Instance<CB: CustomPipeBuilder> {
40 options: Options,
41 instance: wgpu::Instance,
42 custom: CB,
43}
44
45impl<CB: CustomPipeBuilder> Instance<CB> {
46 pub fn new(options: Options, custom: CB) -> Self {
51 let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
52 backends: options.backend(),
53 ..Default::default()
54 });
55
56 Instance {
57 options,
58 instance,
59 custom,
60 }
61 }
62}
63
64impl<CB: CustomPipeBuilder> runner::GraphicsInstance for Instance<CB> {
65 type Shared = DrawPipe<CB::Pipe>;
66
67 type Surface<'a> = surface::Surface<'a, CB::Pipe>;
68
69 fn new_shared(&mut self, surface: Option<&Self::Surface<'_>>) -> Result<Self::Shared> {
70 DrawPipe::new(
71 &self.instance,
72 &mut self.custom,
73 &self.options,
74 surface.map(|s| &s.surface),
75 )
76 }
77
78 fn new_surface<'window, W>(
79 &mut self,
80 window: W,
81 transparent: bool,
82 ) -> Result<Self::Surface<'window>>
83 where
84 W: rwh::HasWindowHandle + rwh::HasDisplayHandle + Send + Sync + 'window,
85 Self: Sized,
86 {
87 surface::Surface::new(&self.instance, window, transparent)
88 }
89}