@@ -42,20 +42,43 @@ fn app_mut<T>(cb: impl FnOnce(&mut App) -> error::Result<T>) -> error::Result<T>
4242 Ok ( res)
4343}
4444
45- /// Create a WebGPU surface from a native window handle.
46- ///
47- /// Currently, this just creates a bevy window with the given parameters and
48- /// stores the raw window handle for later use by the renderer, which will
49- /// actually create the surface.
50- pub fn surface_create (
45+ /// Create a WebGPU surface from a macOS NSWindow handle.
46+ #[ cfg( target_os = "macos" ) ]
47+ pub fn surface_create_macos (
48+ window_handle : u64 ,
49+ width : u32 ,
50+ height : u32 ,
51+ scale_factor : f32 ,
52+ ) -> error:: Result < Entity > {
53+ app_mut ( |app| {
54+ surface:: create_surface_macos ( app. world_mut ( ) , window_handle, width, height, scale_factor)
55+ } )
56+ }
57+
58+ /// Create a WebGPU surface from a Windows HWND handle.
59+ #[ cfg( target_os = "windows" ) ]
60+ pub fn surface_create_windows (
61+ window_handle : u64 ,
62+ width : u32 ,
63+ height : u32 ,
64+ scale_factor : f32 ,
65+ ) -> error:: Result < Entity > {
66+ app_mut ( |app| {
67+ surface:: create_surface_windows ( app. world_mut ( ) , window_handle, width, height, scale_factor)
68+ } )
69+ }
70+
71+ /// Create a WebGPU surface from a Wayland window and display handle.
72+ #[ cfg( all( target_os = "linux" , feature = "wayland" ) ) ]
73+ pub fn surface_create_wayland (
5174 window_handle : u64 ,
5275 display_handle : u64 ,
5376 width : u32 ,
5477 height : u32 ,
5578 scale_factor : f32 ,
5679) -> error:: Result < Entity > {
5780 app_mut ( |app| {
58- surface:: create (
81+ surface:: create_surface_wayland (
5982 app. world_mut ( ) ,
6083 window_handle,
6184 display_handle,
@@ -66,6 +89,40 @@ pub fn surface_create(
6689 } )
6790}
6891
92+ /// Create a WebGPU surface from an X11 window and display handle.
93+ #[ cfg( all( target_os = "linux" , feature = "x11" ) ) ]
94+ pub fn surface_create_x11 (
95+ window_handle : u64 ,
96+ display_handle : u64 ,
97+ width : u32 ,
98+ height : u32 ,
99+ scale_factor : f32 ,
100+ ) -> error:: Result < Entity > {
101+ app_mut ( |app| {
102+ surface:: create_surface_x11 (
103+ app. world_mut ( ) ,
104+ window_handle,
105+ display_handle,
106+ width,
107+ height,
108+ scale_factor,
109+ )
110+ } )
111+ }
112+
113+ /// Create a WebGPU surface from a web canvas element pointer.
114+ #[ cfg( target_arch = "wasm32" ) ]
115+ pub fn surface_create_web (
116+ window_handle : u64 ,
117+ width : u32 ,
118+ height : u32 ,
119+ scale_factor : f32 ,
120+ ) -> error:: Result < Entity > {
121+ app_mut ( |app| {
122+ surface:: create_surface_web ( app. world_mut ( ) , window_handle, width, height, scale_factor)
123+ } )
124+ }
125+
69126pub fn surface_create_offscreen (
70127 width : u32 ,
71128 height : u32 ,
@@ -106,7 +163,7 @@ pub fn surface_create_from_canvas(
106163 // TODO: not sure if this is right to force here
107164 let scale_factor = 1.0 ;
108165
109- surface_create ( canvas_ptr, 0 , width, height, scale_factor)
166+ surface_create_web ( canvas_ptr, width, height, scale_factor)
110167}
111168
112169pub fn surface_destroy ( graphics_entity : Entity ) -> error:: Result < ( ) > {
@@ -124,9 +181,8 @@ fn create_app() -> App {
124181 #[ cfg( not( target_arch = "wasm32" ) ) ]
125182 let plugins = DefaultPlugins
126183 . build ( )
127- . disable :: < bevy:: log:: LogPlugin > ( )
128184 . disable :: < bevy:: winit:: WinitPlugin > ( )
129- . disable :: < bevy:: render :: pipelined_rendering :: PipelinedRenderingPlugin > ( )
185+ . disable :: < bevy:: log :: LogPlugin > ( )
130186 . set ( WindowPlugin {
131187 primary_window : None ,
132188 exit_condition : bevy:: window:: ExitCondition :: DontExit ,
@@ -136,9 +192,8 @@ fn create_app() -> App {
136192 #[ cfg( target_arch = "wasm32" ) ]
137193 let plugins = DefaultPlugins
138194 . build ( )
139- . disable :: < bevy:: log:: LogPlugin > ( )
140195 . disable :: < bevy:: winit:: WinitPlugin > ( )
141- . disable :: < bevy:: audio :: AudioPlugin > ( )
196+ . disable :: < bevy:: log :: LogPlugin > ( )
142197 . set ( WindowPlugin {
143198 primary_window : None ,
144199 exit_condition : bevy:: window:: ExitCondition :: DontExit ,
0 commit comments