@@ -22,17 +22,25 @@ use webxr_api::Views;
22
22
use euclid:: Size2D ;
23
23
use euclid:: TypedRigidTransform3D ;
24
24
25
+ use gleam:: gl;
25
26
use gleam:: gl:: GLsync ;
26
27
use gleam:: gl:: GLuint ;
28
+ use gleam:: gl:: Gl ;
27
29
28
- pub struct HeadlessMockDiscovery ;
30
+ use std:: rc:: Rc ;
31
+
32
+ pub struct HeadlessMockDiscovery {
33
+ gl : Rc < dyn Gl > ,
34
+ }
29
35
30
36
struct HeadlessDiscovery {
37
+ gl : Rc < dyn Gl > ,
31
38
init : MockDeviceInit ,
32
39
receiver : Option < Receiver < MockDeviceMsg > > ,
33
40
}
34
41
35
42
struct HeadlessDevice {
43
+ gl : Rc < dyn Gl > ,
36
44
floor_transform : TypedRigidTransform3D < f32 , Native , Floor > ,
37
45
viewer_origin : TypedRigidTransform3D < f32 , Viewer , Native > ,
38
46
views : Views ,
@@ -46,6 +54,7 @@ impl MockDiscovery for HeadlessMockDiscovery {
46
54
receiver : Receiver < MockDeviceMsg > ,
47
55
) -> Result < Box < dyn Discovery > , Error > {
48
56
Ok ( Box :: new ( HeadlessDiscovery {
57
+ gl : self . gl . clone ( ) ,
49
58
init,
50
59
receiver : Some ( receiver) ,
51
60
} ) )
@@ -57,12 +66,14 @@ impl Discovery for HeadlessDiscovery {
57
66
if !self . supports_session ( mode) {
58
67
return Err ( Error :: NoMatchingDevice ) ;
59
68
}
69
+ let gl = self . gl . clone ( ) ;
60
70
let receiver = self . receiver . take ( ) . ok_or ( Error :: NoMatchingDevice ) ?;
61
71
let viewer_origin = self . init . viewer_origin . clone ( ) ;
62
72
let floor_transform = self . init . floor_origin . inverse ( ) ;
63
73
let views = self . init . views . clone ( ) ;
64
- xr. spawn ( move || {
74
+ xr. run_on_main_thread ( move || {
65
75
Ok ( HeadlessDevice {
76
+ gl,
66
77
floor_transform,
67
78
viewer_origin,
68
79
views,
@@ -96,13 +107,21 @@ impl Device for HeadlessDevice {
96
107
}
97
108
}
98
109
99
- fn render_animation_frame ( & mut self , _: GLuint , _: Size2D < i32 > , _: GLsync ) { }
110
+ fn render_animation_frame ( & mut self , _: GLuint , _: Size2D < i32 > , sync : GLsync ) {
111
+ self . gl . wait_sync ( sync, 0 , gl:: TIMEOUT_IGNORED ) ;
112
+ }
100
113
101
114
fn initial_inputs ( & self ) -> Vec < InputSource > {
102
115
vec ! [ ]
103
116
}
104
117
}
105
118
119
+ impl HeadlessMockDiscovery {
120
+ pub fn new ( gl : Rc < dyn Gl > ) -> HeadlessMockDiscovery {
121
+ HeadlessMockDiscovery { gl }
122
+ }
123
+ }
124
+
106
125
impl HeadlessDevice {
107
126
fn handle_msg ( & mut self , msg : MockDeviceMsg ) {
108
127
match msg {
0 commit comments