11use egui:: { TexturesDelta , UserData , ViewportCommand } ;
22
3- use crate :: { App , epi} ;
3+ use crate :: { App , epi, web :: web_painter :: WebPainter } ;
44
5- use super :: { NeedRepaint , now_sec, text_agent:: TextAgent , web_painter :: WebPainter as _ } ;
5+ use super :: { NeedRepaint , now_sec, text_agent:: TextAgent } ;
66
77pub struct AppRunner {
88 #[ allow( dead_code, clippy:: allow_attributes) ]
99 pub ( crate ) web_options : crate :: WebOptions ,
1010 pub ( crate ) frame : epi:: Frame ,
1111 egui_ctx : egui:: Context ,
12- painter : super :: ActiveWebPainter ,
12+ painter : Box < dyn WebPainter > ,
1313 pub ( crate ) input : super :: WebInput ,
1414 app : Box < dyn epi:: App > ,
1515 pub ( crate ) needs_repaint : std:: sync:: Arc < NeedRepaint > ,
@@ -34,14 +34,52 @@ impl Drop for AppRunner {
3434impl AppRunner {
3535 /// # Errors
3636 /// Failure to initialize WebGL renderer, or failure to create app.
37+ #[ cfg_attr(
38+ not( feature = "wgpu_no_default_features" ) ,
39+ expect( clippy:: unused_async)
40+ ) ]
3741 pub async fn new (
3842 canvas : web_sys:: HtmlCanvasElement ,
3943 web_options : crate :: WebOptions ,
4044 app_creator : epi:: AppCreator < ' static > ,
4145 text_agent : TextAgent ,
4246 ) -> Result < Self , String > {
4347 let egui_ctx = egui:: Context :: default ( ) ;
44- let painter = super :: ActiveWebPainter :: new ( egui_ctx. clone ( ) , canvas, & web_options) . await ?;
48+
49+ #[ allow( clippy:: allow_attributes, unused_assignments) ]
50+ #[ cfg( feature = "glow" ) ]
51+ let mut gl = None ;
52+
53+ #[ allow( clippy:: allow_attributes, unused_assignments) ]
54+ #[ cfg( feature = "wgpu_no_default_features" ) ]
55+ let mut wgpu_render_state = None ;
56+
57+ let painter = match web_options. renderer {
58+ #[ cfg( feature = "glow" ) ]
59+ epi:: Renderer :: Glow => {
60+ log:: debug!( "Using the glow renderer" ) ;
61+ let painter = super :: web_painter_glow:: WebPainterGlow :: new (
62+ egui_ctx. clone ( ) ,
63+ canvas,
64+ & web_options,
65+ ) ?;
66+ gl = Some ( painter. gl ( ) . clone ( ) ) ;
67+ Box :: new ( painter) as Box < dyn WebPainter >
68+ }
69+
70+ #[ cfg( feature = "wgpu_no_default_features" ) ]
71+ epi:: Renderer :: Wgpu => {
72+ log:: debug!( "Using the wgpu renderer" ) ;
73+ let painter = super :: web_painter_wgpu:: WebPainterWgpu :: new (
74+ egui_ctx. clone ( ) ,
75+ canvas,
76+ & web_options,
77+ )
78+ . await ?;
79+ wgpu_render_state = painter. render_state ( ) ;
80+ Box :: new ( painter) as Box < dyn WebPainter >
81+ }
82+ } ;
4583
4684 let info = epi:: IntegrationInfo {
4785 web_info : epi:: WebInfo {
@@ -79,15 +117,13 @@ impl AppRunner {
79117 storage : Some ( & storage) ,
80118
81119 #[ cfg( feature = "glow" ) ]
82- gl : Some ( painter . gl ( ) . clone ( ) ) ,
120+ gl : gl . clone ( ) ,
83121
84122 #[ cfg( feature = "glow" ) ]
85123 get_proc_address : None ,
86124
87- #[ cfg( all( feature = "wgpu_no_default_features" , not( feature = "glow" ) ) ) ]
88- wgpu_render_state : painter. render_state ( ) ,
89- #[ cfg( all( feature = "wgpu_no_default_features" , feature = "glow" ) ) ]
90- wgpu_render_state : None ,
125+ #[ cfg( feature = "wgpu_no_default_features" ) ]
126+ wgpu_render_state : wgpu_render_state. clone ( ) ,
91127 } ;
92128 let app = app_creator ( & cc) . map_err ( |err| err. to_string ( ) ) ?;
93129
@@ -96,12 +132,10 @@ impl AppRunner {
96132 storage : Some ( Box :: new ( storage) ) ,
97133
98134 #[ cfg( feature = "glow" ) ]
99- gl : Some ( painter . gl ( ) . clone ( ) ) ,
135+ gl,
100136
101- #[ cfg( all( feature = "wgpu_no_default_features" , not( feature = "glow" ) ) ) ]
102- wgpu_render_state : painter. render_state ( ) ,
103- #[ cfg( all( feature = "wgpu_no_default_features" , feature = "glow" ) ) ]
104- wgpu_render_state : None ,
137+ #[ cfg( feature = "wgpu_no_default_features" ) ]
138+ wgpu_render_state,
105139 } ;
106140
107141 let needs_repaint: std:: sync:: Arc < NeedRepaint > =
0 commit comments