1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
mod settings;
#[doc(inline)]
pub use settings::*;
mod winit_window;
#[doc(inline)]
pub use winit_window::*;
#[cfg(not(target_arch = "wasm32"))]
mod headless;
#[doc(inline)]
#[cfg(not(target_arch = "wasm32"))]
pub use headless::*;
use thiserror::Error;
#[cfg(not(target_arch = "wasm32"))]
#[derive(Error, Debug)]
#[allow(missing_docs)]
pub enum WindowError {
#[error("failed creating a new window")]
WindowCreation(#[from] glutin::CreationError),
#[error("failed creating a new context")]
ContextCreation(#[from] glutin::ContextError),
#[error("error in three-d")]
ThreeDError(#[from] CoreError),
#[error("the number of MSAA samples must be a power of two")]
InvalidNumberOfMSAASamples,
}
#[cfg(target_arch = "wasm32")]
#[derive(Error, Debug)]
#[allow(missing_docs)]
pub enum WindowError {
#[error("failed to create a new winit window")]
WinitError(#[from] winit::error::OsError),
#[error("failed creating a new window")]
WindowCreation,
#[error("unable to get document from canvas")]
DocumentMissing,
#[error("unable to convert canvas to html canvas: {0}")]
CanvasConvertFailed(String),
#[error("unable to get webgl2 context for the given canvas, maybe the browser doesn't support WebGL2{0}")]
WebGL2NotSupported(String),
#[error("unable to get EXT_color_buffer_float extension for the given canvas, maybe the browser doesn't support EXT_color_buffer_float: {0}")]
ColorBufferFloatNotSupported(String),
#[error("unable to get OES_texture_float extension for the given canvas, maybe the browser doesn't support OES_texture_float: {0}")]
OESTextureFloatNotSupported(String),
#[error("error in three-d")]
ThreeDError(#[from] CoreError),
}
use crate::control::*;
use crate::core::*;
#[derive(Clone, Debug)]
pub struct FrameInput {
pub events: Vec<Event>,
pub elapsed_time: f64,
pub accumulated_time: f64,
pub viewport: Viewport,
pub window_width: u32,
pub window_height: u32,
pub device_pixel_ratio: f64,
pub first_frame: bool,
pub context: Context,
}
impl FrameInput {
pub fn screen(&self) -> RenderTarget {
RenderTarget::screen(&self.context, self.viewport.width, self.viewport.height)
}
}
#[derive(Clone, Debug)]
pub struct FrameOutput {
pub exit: bool,
pub swap_buffers: bool,
pub wait_next_event: bool,
}
impl Default for FrameOutput {
fn default() -> Self {
Self {
exit: false,
swap_buffers: true,
wait_next_event: false,
}
}
}