Take a reference to a window in GraphicsContext::new, like glutin and wgpu
This commit is contained in:
parent
85b4f189bd
commit
99d63063b6
13 changed files with 40 additions and 78 deletions
|
|
@ -25,7 +25,7 @@ fn main() {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
let mut graphics_context = unsafe { GraphicsContext::new(window) }.unwrap();
|
||||
let mut graphics_context = unsafe { GraphicsContext::new(&window) }.unwrap();
|
||||
|
||||
let mut old_size = (0, 0);
|
||||
let mut frames = pre_render_frames(0, 0);
|
||||
|
|
@ -35,10 +35,10 @@ fn main() {
|
|||
*control_flow = ControlFlow::Poll;
|
||||
|
||||
match event {
|
||||
Event::RedrawRequested(window_id) if window_id == graphics_context.window().id() => {
|
||||
Event::RedrawRequested(window_id) if window_id == window.id() => {
|
||||
let elapsed = start.elapsed().as_secs_f64() % 1.0;
|
||||
let (width, height) = {
|
||||
let size = graphics_context.window().inner_size();
|
||||
let size = window.inner_size();
|
||||
(size.width, size.height)
|
||||
};
|
||||
|
||||
|
|
@ -51,12 +51,12 @@ fn main() {
|
|||
graphics_context.set_buffer(buffer.as_slice(), width as u16, height as u16);
|
||||
}
|
||||
Event::MainEventsCleared => {
|
||||
graphics_context.window().request_redraw();
|
||||
window.request_redraw();
|
||||
}
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::CloseRequested,
|
||||
window_id,
|
||||
} if window_id == graphics_context.window().id() => {
|
||||
} if window_id == window.id() => {
|
||||
*control_flow = ControlFlow::Exit;
|
||||
}
|
||||
_ => {}
|
||||
|
|
@ -89,4 +89,4 @@ fn pre_render_frames(width: usize, height: usize) -> Vec<Vec<u32>>{
|
|||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
(0..60).into_par_iter().map(render).collect()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,19 +32,19 @@ fn main() {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
let mut graphics_context = unsafe { GraphicsContext::new(window) }.unwrap();
|
||||
let mut graphics_context = unsafe { GraphicsContext::new(&window) }.unwrap();
|
||||
|
||||
event_loop.run(move |event, _, control_flow| {
|
||||
*control_flow = ControlFlow::Wait;
|
||||
|
||||
match event {
|
||||
Event::RedrawRequested(window_id) if window_id == graphics_context.window().id() => {
|
||||
Event::RedrawRequested(window_id) if window_id == window.id() => {
|
||||
graphics_context.set_buffer(&buffer, fruit.width() as u16, fruit.height() as u16);
|
||||
}
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::CloseRequested,
|
||||
window_id,
|
||||
} if window_id == graphics_context.window().id() => {
|
||||
} if window_id == window.id() => {
|
||||
*control_flow = ControlFlow::Exit;
|
||||
}
|
||||
_ => {}
|
||||
|
|
|
|||
|
|
@ -21,15 +21,15 @@ fn main() {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
let mut graphics_context = unsafe { GraphicsContext::new(window) }.unwrap();
|
||||
let mut graphics_context = unsafe { GraphicsContext::new(&window) }.unwrap();
|
||||
|
||||
event_loop.run(move |event, _, control_flow| {
|
||||
*control_flow = ControlFlow::Wait;
|
||||
|
||||
match event {
|
||||
Event::RedrawRequested(window_id) if window_id == graphics_context.window().id() => {
|
||||
Event::RedrawRequested(window_id) if window_id == window.id() => {
|
||||
let (width, height) = {
|
||||
let size = graphics_context.window().inner_size();
|
||||
let size = window.inner_size();
|
||||
(size.width, size.height)
|
||||
};
|
||||
let buffer = (0..((width * height) as usize))
|
||||
|
|
@ -51,7 +51,7 @@ fn main() {
|
|||
Event::WindowEvent {
|
||||
event: WindowEvent::CloseRequested,
|
||||
window_id,
|
||||
} if window_id == graphics_context.window().id() => {
|
||||
} if window_id == window.id() => {
|
||||
*control_flow = ControlFlow::Exit;
|
||||
}
|
||||
_ => {}
|
||||
|
|
|
|||
|
|
@ -24,13 +24,13 @@ fn main() {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
let mut graphics_context = unsafe { GraphicsContext::new(window) }.unwrap();
|
||||
let mut graphics_context = unsafe { GraphicsContext::new(&window) }.unwrap();
|
||||
|
||||
event_loop.run(move |event, _, control_flow| {
|
||||
*control_flow = ControlFlow::Wait;
|
||||
|
||||
match event {
|
||||
Event::RedrawRequested(window_id) if window_id == graphics_context.window().id() => {
|
||||
Event::RedrawRequested(window_id) if window_id == window.id() => {
|
||||
let buffer = (0..((BUFFER_WIDTH * BUFFER_HEIGHT) as usize))
|
||||
.map(|index| {
|
||||
let y = index / (BUFFER_WIDTH as usize);
|
||||
|
|
@ -50,7 +50,7 @@ fn main() {
|
|||
Event::WindowEvent {
|
||||
event: WindowEvent::CloseRequested,
|
||||
window_id,
|
||||
} if window_id == graphics_context.window().id() => {
|
||||
} if window_id == window.id() => {
|
||||
*control_flow = ControlFlow::Exit;
|
||||
}
|
||||
_ => {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue