Skip to content

Commit

Permalink
update to winit 0.29.4 (#544)
Browse files Browse the repository at this point in the history
Co-authored-by: Connor Fitzgerald <[email protected]>
  • Loading branch information
pillowtrucker and cwfitzgerald authored Dec 31, 2023
1 parent 64167c6 commit d7869b8
Show file tree
Hide file tree
Showing 25 changed files with 425 additions and 644 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Per Keep a Changelog there are 6 main categories of changes:
### Changes
- rend3: Update to wgpu 0.13, naga 0.9 @garyttierney
- rend3: Convert all shaders to WGSL using a custom preprocessing solution @cwfitzgerald
- rend3: Update to winit 0.29.4 @pillowtrucker
- rend3-framework: Consolidate many arguments into single `SetupContext` and `EventContext` structs. @cwfitzgerald

### Fixes
- Fixed renderpass compatibility checks to avoid issues when RODS is used. @OptimisticPeach
Expand Down
6 changes: 1 addition & 5 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ wildcards = "allow"
skip = [
# gltf / reqwest
{ name = "base64", version = "0.13.1" },
# ddsfile
{ name = "num-traits", version = "0.1.43" },
# tokio
{ name = "socket2", version = "0.4.9" },
]
skip-tree = [
# winit brings in lots of duplicate deps that we can't fix
{ name = "winit", version = "0.28" },
{ name = "winit", version = "0.29.4" },
# loom is depended on by tracy-client but under a custom cfg that is never on.
{ name = "loom", version = "0.5" },
]
Expand Down
2 changes: 1 addition & 1 deletion examples/animation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ rend3-gltf = { version = "^0.3.0", path = "../../rend3-gltf" }
# std::time::Instant that works on wasm
web-time = "0.2"
# windowing
winit = "0.28"
winit = "0.29.4"
image = { version = "0.24", default-features = false, features = ["jpeg"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down
70 changes: 25 additions & 45 deletions examples/animation/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{path::Path, sync::Arc};
use std::path::Path;

use rend3::types::DirectionalLightHandle;
use winit::event::WindowEvent;

const SAMPLE_COUNT: rend3::types::SampleCount = rend3::types::SampleCount::One;

Expand Down Expand Up @@ -41,20 +42,13 @@ impl rend3_framework::App for AnimationExample {
SAMPLE_COUNT
}

fn setup(
&mut self,
_event_loop: &winit::event_loop::EventLoop<rend3_framework::UserResizeEvent<()>>,
_window: &winit::window::Window,
renderer: &Arc<rend3::Renderer>,
_routines: &Arc<rend3_framework::DefaultRoutines>,
_surface_format: rend3::types::TextureFormat,
) {
fn setup(&mut self, context: rend3_framework::SetupContext<'_>) {
let view_location = glam::Vec3::new(0.0, -1.5, 5.0);
let view = glam::Mat4::from_euler(glam::EulerRot::XYZ, 0.0, 0.0, 0.0);
let view = view * glam::Mat4::from_translation(view_location);

// Set camera's location
renderer.set_camera_data(rend3::types::Camera {
context.renderer.set_camera_data(rend3::types::Camera {
projection: rend3::types::CameraProjection::Perspective { vfov: 60.0, near: 0.1 },
view,
});
Expand All @@ -65,7 +59,7 @@ impl rend3_framework::App for AnimationExample {
let gltf_data = std::fs::read(path).unwrap();
let parent_directory = path.parent().unwrap();
let (loaded_scene, loaded_instance) = pollster::block_on(rend3_gltf::load_gltf(
renderer,
context.renderer,
&gltf_data,
&rend3_gltf::GltfLoadSettings::default(),
|p| async move { rend3_gltf::filesystem_io_func(&parent_directory, &p).await },
Expand All @@ -75,7 +69,7 @@ impl rend3_framework::App for AnimationExample {
// Create a single directional light
//
// We need to keep the directional light handle alive.
let directional_light_handle = renderer.add_directional_light(rend3::types::DirectionalLight {
let directional_light_handle = context.renderer.add_directional_light(rend3::types::DirectionalLight {
color: glam::Vec3::ONE,
intensity: 5.0,
// Direction will be normalized
Expand All @@ -98,7 +92,7 @@ impl rend3_framework::App for AnimationExample {
let gltf_data = std::fs::read(path).unwrap();
let parent_directory = path.parent().unwrap();
let (loaded_scene, loaded_instance) = pollster::block_on(rend3_gltf::load_gltf(
renderer,
context.renderer,
&gltf_data,
&rend3_gltf::GltfLoadSettings::default(),
|p| async move { rend3_gltf::filesystem_io_func(&parent_directory, &p).await },
Expand All @@ -116,49 +110,35 @@ impl rend3_framework::App for AnimationExample {
self.animated_objects = vec![animated_object, animated_object2];
}

fn handle_event(
&mut self,
window: &winit::window::Window,
renderer: &Arc<rend3::Renderer>,
routines: &Arc<rend3_framework::DefaultRoutines>,
base_rendergraph: &rend3_routine::base::BaseRenderGraph,
surface: Option<&Arc<rend3::types::Surface>>,
resolution: glam::UVec2,
event: rend3_framework::Event<'_, ()>,
control_flow: impl FnOnce(winit::event_loop::ControlFlow),
) {
fn handle_event(&mut self, context: rend3_framework::EventContext<'_>, event: winit::event::Event<()>) {
#[allow(clippy::single_match)]
match event {
// Close button was clicked, we should close.
rend3_framework::Event::WindowEvent {
event: winit::event::WindowEvent::CloseRequested,
..
// Render!
winit::event::Event::WindowEvent {
window_id: _,
event: WindowEvent::RedrawRequested,
} => {
control_flow(winit::event_loop::ControlFlow::Exit);
}
rend3_framework::Event::MainEventsCleared => {
let now = web_time::Instant::now();

self.animated_objects.iter_mut().for_each(|animated_object| {
let delta = now.duration_since(animated_object.last_frame_time).as_secs_f32();
animated_object.last_frame_time = now;
update(renderer, delta, animated_object);
update(context.renderer, delta, animated_object);
});

window.request_redraw();
}
// Render!
rend3_framework::Event::RedrawRequested(_) => {
context.window.request_redraw();

// Get a frame
let frame = surface.unwrap().get_current_texture().unwrap();
let frame = context.surface.unwrap().get_current_texture().unwrap();

// Swap the instruction buffers so that our frame's changes can be processed.
renderer.swap_instruction_buffers();
context.renderer.swap_instruction_buffers();
// Evaluate our frame's world-change instructions
let mut eval_output = renderer.evaluate_instructions();
let mut eval_output = context.renderer.evaluate_instructions();

// Lock the routines
let pbr_routine = rend3_framework::lock(&routines.pbr);
let tonemapping_routine = rend3_framework::lock(&routines.tonemapping);
let pbr_routine = rend3_framework::lock(&context.routines.pbr);
let tonemapping_routine = rend3_framework::lock(&context.routines.tonemapping);

// Build a rendergraph
let mut graph = rend3::graph::RenderGraph::new();
Expand All @@ -168,10 +148,10 @@ impl rend3_framework::App for AnimationExample {
&frame,
0..1,
0..1,
rend3::graph::ViewportRect::from_size(resolution),
rend3::graph::ViewportRect::from_size(context.resolution),
);
// Add the default rendergraph without a skybox
base_rendergraph.add_to_graph(
context.base_rendergraph.add_to_graph(
&mut graph,
rend3_routine::base::BaseRenderGraphInputs {
eval_output: &eval_output,
Expand All @@ -182,7 +162,7 @@ impl rend3_framework::App for AnimationExample {
},
target: rend3_routine::base::OutputRenderTarget {
handle: frame_handle,
resolution,
resolution: context.resolution,
samples: SAMPLE_COUNT,
},
},
Expand All @@ -193,7 +173,7 @@ impl rend3_framework::App for AnimationExample {
);

// Dispatch a render using the built up rendergraph!
graph.execute(renderer, &mut eval_output);
graph.execute(context.renderer, &mut eval_output);

// Present the frame
frame.present();
Expand Down
2 changes: 1 addition & 1 deletion examples/cube-no-framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ rend3-routine = { version = "^0.3.0", path = "../../rend3-routine" }
# Provides `block_on` to wait for futures from sync code
pollster = "0.3"
# windowing
winit = "0.28"
winit = "0.29.4"

[target.'cfg(target_arch = "wasm32")'.dependencies]
console_log = "1"
Expand Down
144 changes: 73 additions & 71 deletions examples/cube-no-framework/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn main() {
env_logger::init();

// Create event loop and window
let event_loop = winit::event_loop::EventLoop::new();
let event_loop = winit::event_loop::EventLoop::new().unwrap();
let window = {
let mut builder = winit::window::WindowBuilder::new();
builder = builder.with_title("rend3 cube");
Expand Down Expand Up @@ -176,76 +176,78 @@ fn main() {

let mut resolution = glam::UVec2::new(window_size.width, window_size.height);

event_loop.run(move |event, _, control| match event {
// Close button was clicked, we should close.
winit::event::Event::WindowEvent {
event: winit::event::WindowEvent::CloseRequested,
..
} => {
*control = winit::event_loop::ControlFlow::Exit;
}
// Window was resized, need to resize renderer.
winit::event::Event::WindowEvent {
event: winit::event::WindowEvent::Resized(physical_size),
..
} => {
resolution = glam::UVec2::new(physical_size.width, physical_size.height);
// Reconfigure the surface for the new size.
rend3::configure_surface(
&surface,
&renderer.device,
preferred_format,
glam::UVec2::new(resolution.x, resolution.y),
rend3::types::PresentMode::Fifo,
);
// Tell the renderer about the new aspect ratio.
renderer.set_aspect_ratio(resolution.x as f32 / resolution.y as f32);
}
// Render!
winit::event::Event::MainEventsCleared => {
// Get a frame
let frame = surface.get_current_texture().unwrap();

// Swap the instruction buffers so that our frame's changes can be processed.
renderer.swap_instruction_buffers();
// Evaluate our frame's world-change instructions
let mut eval_output = renderer.evaluate_instructions();

// Build a rendergraph
let mut graph = rend3::graph::RenderGraph::new();

// Import the surface texture into the render graph.
let frame_handle =
graph.add_imported_render_target(&frame, 0..1, 0..1, rend3::graph::ViewportRect::from_size(resolution));
// Add the default rendergraph without a skybox
base_rendergraph.add_to_graph(
&mut graph,
rend3_routine::base::BaseRenderGraphInputs {
eval_output: &eval_output,
routines: rend3_routine::base::BaseRenderGraphRoutines {
pbr: &pbr_routine,
skybox: None,
tonemapping: &tonemapping_routine,
event_loop
.run(move |event, _event_loop_window_target| match event {
// Window was resized, need to resize renderer.
winit::event::Event::WindowEvent {
event: winit::event::WindowEvent::Resized(physical_size),
..
} => {
resolution = glam::UVec2::new(physical_size.width, physical_size.height);
// Reconfigure the surface for the new size.
rend3::configure_surface(
&surface,
&renderer.device,
preferred_format,
glam::UVec2::new(resolution.x, resolution.y),
rend3::types::PresentMode::Fifo,
);
// Tell the renderer about the new aspect ratio.
renderer.set_aspect_ratio(resolution.x as f32 / resolution.y as f32);
}
// Render!
winit::event::Event::WindowEvent {
event: winit::event::WindowEvent::RedrawRequested,
..
} => {
// Get a frame
let frame = surface.get_current_texture().unwrap();

// Swap the instruction buffers so that our frame's changes can be processed.
renderer.swap_instruction_buffers();
// Evaluate our frame's world-change instructions
let mut eval_output = renderer.evaluate_instructions();

// Build a rendergraph
let mut graph = rend3::graph::RenderGraph::new();

// Import the surface texture into the render graph.
let frame_handle = graph.add_imported_render_target(
&frame,
0..1,
0..1,
rend3::graph::ViewportRect::from_size(resolution),
);
// Add the default rendergraph without a skybox
base_rendergraph.add_to_graph(
&mut graph,
rend3_routine::base::BaseRenderGraphInputs {
eval_output: &eval_output,
routines: rend3_routine::base::BaseRenderGraphRoutines {
pbr: &pbr_routine,
skybox: None,
tonemapping: &tonemapping_routine,
},
target: rend3_routine::base::OutputRenderTarget {
handle: frame_handle,
resolution,
samples: rend3::types::SampleCount::One,
},
},
target: rend3_routine::base::OutputRenderTarget {
handle: frame_handle,
resolution,
samples: rend3::types::SampleCount::One,
rend3_routine::base::BaseRenderGraphSettings {
ambient_color: glam::Vec4::ZERO,
clear_color: glam::Vec4::new(0.10, 0.05, 0.10, 1.0), // Nice scene-referred purple
},
},
rend3_routine::base::BaseRenderGraphSettings {
ambient_color: glam::Vec4::ZERO,
clear_color: glam::Vec4::new(0.10, 0.05, 0.10, 1.0), // Nice scene-referred purple
},
);

// Dispatch a render using the built up rendergraph!
graph.execute(&renderer, &mut eval_output);

// Present the frame
frame.present();
}
// Other events we don't care about
_ => {}
});
);

// Dispatch a render using the built up rendergraph!
graph.execute(&renderer, &mut eval_output);

// Present the frame
frame.present();
}
// Other events we don't care about
_ => {}
})
.expect("");
}
2 changes: 1 addition & 1 deletion examples/cube/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ rend3-routine = { version = "^0.3.0", path = "../../rend3-routine" }
# Framework that deals with the event loop, setting up the renderer, and platform differences.
rend3-framework = { version = "^0.3.0", path = "../../rend3-framework" }
# windowing
winit = "0.28"
winit = "0.29.4"

[target.'cfg(target_arch = "wasm32")'.dependencies]
console_log = "1"
Expand Down
Loading

0 comments on commit d7869b8

Please sign in to comment.