Skip to content

Commit f1a7174

Browse files
committed
Upgrade numeric, geometric, and rendering dependencies.
This change upgrades `decorum`, `theon`, `num`, `wgpu`, and some other dependencies that are primarily used for geometry and rendering. Some of these dependencies are coupled. For example, this change also upgrades dependencies on linear algebra crates to support a later version of `theon`.
1 parent 5cae262 commit f1a7174

23 files changed

+530
-457
lines changed

examples/sphere/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ license = "MIT"
77
publish = false
88

99
[dependencies]
10+
nalgebra = "^0.33.0"
11+
theon = "^0.1.0"
1012

1113
[dependencies.pictor]
1214
path = "../../pictor"

examples/sphere/src/main.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
use plexus::integration::nalgebra;
2-
use plexus::integration::theon;
3-
41
use nalgebra::Point3;
52
use pictor::pipeline::{self, Vertex};
63
use plexus::prelude::*;

examples/subdivide/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ license = "MIT"
77
publish = false
88

99
[dependencies]
10+
nalgebra = "^0.33.0"
1011
smallvec = "^1.0.0"
12+
theon = "^0.1.0"
1113

1214
[dependencies.pictor]
1315
path = "../../pictor"

examples/subdivide/src/main.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#![allow(clippy::iter_nth_zero)]
22

3-
use plexus::integration::nalgebra;
4-
use plexus::integration::theon;
5-
63
use nalgebra::Point3;
74
use pictor::pipeline::{self, Vertex};
85
use plexus::geometry::AsPositionMut;

examples/teapot/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ license = "MIT"
77
publish = false
88

99
[dependencies]
10+
nalgebra = "^0.33.0"
11+
theon = "^0.1.0"
1012

1113
[dependencies.pictor]
1214
path = "../../pictor"

examples/teapot/src/main.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
use plexus::integration::nalgebra;
2-
use plexus::integration::theon;
3-
41
use nalgebra::Point3;
52
use pictor::pipeline::{self, Vertex};
63
use plexus::encoding::ply::{FromPly, PositionEncoding};

pictor/Cargo.toml

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@
22
name = "pictor"
33
version = "0.0.0"
44
edition = "2021"
5-
rust-version = "1.65.0"
5+
rust-version = "1.80.0"
66
authors = ["Sean Olson <olson.sean.k@gmail.com>"]
77
license = "MIT"
88
description = "Renderer and support library for Plexus examples."
99
publish = false
1010

1111
[dependencies]
12-
bytemuck = "^1.4.0"
13-
decorum = "^0.3.1"
14-
lazy_static = "^1.4.0"
15-
num = "^0.3.0"
16-
rand = "^0.7.0"
17-
winit = "^0.24.0"
12+
bytemuck = "^1.13.0" # optional for winit, `1.21.0` latest.
13+
decorum = "^0.4.0"
14+
naga = "^23.0.0"
15+
nalgebra = "^0.33.0"
16+
num = "^0.4.3"
17+
rand = "^0.8.5"
18+
theon = "^0.1.0"
19+
winit = "^0.30.8"
1820

1921
[dependencies.futures]
20-
version = "=0.3"
22+
version = "^0.3.31"
2123
default-features = false
2224
features = [
2325
"std",
@@ -29,8 +31,6 @@ path = "../plexus"
2931
default-features = false
3032
features = ["geometry-nalgebra"]
3133

32-
# TODO: Migrate to a published release of `wgpu`.
3334
[dependencies.wgpu]
34-
#version = "^0.6.0"
35-
git = "https://github.com/gfx-rs/wgpu-rs.git"
36-
rev = "e798278"
35+
version = "^23.0.1"
36+
features = ["glsl"]

pictor/src/camera.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
use plexus::integration::nalgebra;
2-
3-
use lazy_static::lazy_static;
41
use nalgebra::{Isometry3, Matrix4, Orthographic3, Perspective3, Point3, Vector3};
5-
use wgpu::SwapChainDescriptor;
2+
use std::sync::LazyLock;
3+
use wgpu::SurfaceConfiguration;
64

7-
lazy_static! {
8-
#[rustfmt::skip]
9-
static ref OPENGL_TO_WGPU_TRANSFORM: Matrix4<f32> = Matrix4::new(
5+
#[rustfmt::skip]
6+
static OPENGL_TO_WGPU_TRANSFORM: LazyLock<Matrix4<f32>> = LazyLock::new(|| {
7+
Matrix4::new(
108
1.0, 0.0, 0.0, 0.0,
119
0.0, 1.0, 0.0, 0.0,
1210
0.0, 0.0, 0.5, 0.0,
1311
0.0, 0.0, 0.5, 1.0,
14-
);
15-
}
12+
)
13+
});
1614

1715
pub enum Projection {
1816
Perspective(Perspective3<f32>),
@@ -48,13 +46,13 @@ impl Camera {
4846
self.view = Isometry3::look_at_rh(from, to, &Vector3::y());
4947
}
5048

51-
pub fn reproject(&mut self, descriptor: &SwapChainDescriptor) {
49+
pub fn reproject(&mut self, surface: &SurfaceConfiguration) {
5250
match self.projection {
5351
Projection::Perspective(ref mut perspective) => {
54-
perspective.set_aspect(descriptor.width as f32 / descriptor.height as f32);
52+
perspective.set_aspect(surface.width as f32 / surface.height as f32);
5553
}
5654
Projection::Orthographic(ref mut orthographic) => {
57-
let inverse = descriptor.height as f32 / descriptor.width as f32;
55+
let inverse = surface.height as f32 / surface.width as f32;
5856
let radius = (orthographic.right() - orthographic.left()) * inverse * 0.5;
5957
orthographic.set_bottom_and_top(-radius, radius);
6058
}

pictor/src/harness.rs

+63-49
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@ use futures::executor::{self, LocalPool, LocalSpawner};
22
use futures::task::LocalSpawn;
33
use std::cmp;
44
use std::fmt::Debug;
5-
use wgpu::{Device, Queue, SwapChainDescriptor, SwapChainTexture};
6-
use winit::event::{Event, WindowEvent};
7-
use winit::event_loop::{ControlFlow, EventLoop};
8-
use winit::window::Window;
5+
use winit::application::ApplicationHandler;
6+
use winit::event::WindowEvent;
7+
use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop};
8+
use winit::window::{Window, WindowId};
99

1010
use crate::renderer::Renderer;
1111

12-
use ControlFlow::Exit;
13-
use ControlFlow::Poll;
14-
1512
struct Executor {
1613
pool: LocalPool,
1714
spawner: LocalSpawner,
@@ -41,17 +38,17 @@ pub enum Reaction {
4138
}
4239

4340
pub trait ConfigureStage {
44-
fn device(&self) -> &Device;
41+
fn device(&self) -> &wgpu::Device;
4542

46-
fn queue(&self) -> &Queue;
43+
fn queue(&self) -> &wgpu::Queue;
4744

48-
fn swap_chain_descriptor(&self) -> &SwapChainDescriptor;
45+
fn surface_configuration(&self) -> &wgpu::SurfaceConfiguration;
4946
}
5047

5148
pub trait RenderStage {
52-
fn device(&self) -> &Device;
49+
fn device(&self) -> &wgpu::Device;
5350

54-
fn queue(&self) -> &Queue;
51+
fn queue(&self) -> &wgpu::Queue;
5552
}
5653

5754
pub trait Application: 'static + Sized {
@@ -73,7 +70,7 @@ pub trait Application: 'static + Sized {
7370
fn render(
7471
&mut self,
7572
stage: &impl RenderStage,
76-
frame: &SwapChainTexture,
73+
view: &wgpu::TextureView,
7774
spawn: &impl LocalSpawn,
7875
);
7976
}
@@ -83,48 +80,65 @@ where
8380
T: Application,
8481
F: FnOnce(&EventLoop<()>) -> Window,
8582
{
86-
let mut executor = Executor::new();
87-
let reactor = EventLoop::new();
88-
let mut renderer = executor::block_on(Renderer::try_from_window(f(&reactor))).unwrap();
89-
let mut application = T::configure(configuration, &renderer).unwrap();
90-
reactor.run(move |event, _, reaction| {
91-
*reaction = Poll;
92-
match event {
93-
Event::MainEventsCleared => {
94-
executor.flush();
95-
}
96-
Event::RedrawRequested(_) => {
97-
let swap_chain = &mut renderer.swap_chain;
98-
let frame = match swap_chain.get_current_frame() {
99-
Ok(frame) => frame,
100-
Err(_) => {
101-
*swap_chain = renderer
102-
.device
103-
.create_swap_chain(&renderer.surface, &renderer.swap_chain_descriptor);
104-
swap_chain.get_current_frame().unwrap()
105-
}
106-
};
107-
application.render(&renderer, &frame.output, executor.spawner());
108-
}
109-
Event::WindowEvent { event, .. } => match event {
83+
struct Run<'window, T> {
84+
executor: Executor,
85+
application: T,
86+
window: &'window Window,
87+
renderer: Renderer<'window>,
88+
}
89+
90+
impl<'window, T> ApplicationHandler<()> for Run<'window, T>
91+
where
92+
T: Application,
93+
{
94+
fn resumed(&mut self, _reactor: &ActiveEventLoop) {}
95+
96+
fn window_event(&mut self, reactor: &ActiveEventLoop, _: WindowId, event: WindowEvent) {
97+
match event {
98+
WindowEvent::RedrawRequested => {
99+
let frame = self.renderer.surface.get_current_texture().unwrap();
100+
let view = frame
101+
.texture
102+
.create_view(&wgpu::TextureViewDescriptor::default());
103+
self.application
104+
.render(&self.renderer, &view, self.executor.spawner());
105+
frame.present();
106+
}
110107
WindowEvent::CloseRequested => {
111-
*reaction = Exit;
108+
reactor.exit();
112109
}
113110
WindowEvent::Resized(dimensions) => {
114-
renderer.swap_chain_descriptor.width = cmp::max(1, dimensions.width);
115-
renderer.swap_chain_descriptor.height = cmp::max(1, dimensions.height);
116-
application.resize(&renderer);
117-
renderer.swap_chain = renderer
118-
.device
119-
.create_swap_chain(&renderer.surface, &renderer.swap_chain_descriptor);
111+
self.renderer.surface_configuration.width = cmp::max(1, dimensions.width);
112+
self.renderer.surface_configuration.height = cmp::max(1, dimensions.height);
113+
self.application.resize(&self.renderer);
114+
self.renderer
115+
.surface
116+
.configure(&self.renderer.device, &self.renderer.surface_configuration);
117+
self.window.request_redraw();
120118
}
121119
_ => {
122-
if let Reaction::Abort = application.react(event) {
123-
*reaction = Exit;
120+
if let Reaction::Abort = self.application.react(event) {
121+
reactor.exit();
124122
}
125123
}
126-
},
127-
_ => {}
124+
}
125+
// TODO: This should probably be done in reaction to much more specific events.
126+
self.executor.flush();
128127
}
129-
});
128+
}
129+
130+
let executor = Executor::new();
131+
let reactor = EventLoop::new().unwrap();
132+
reactor.set_control_flow(ControlFlow::Poll);
133+
let window = f(&reactor);
134+
let renderer = executor::block_on(Renderer::try_from_window(&window)).unwrap();
135+
let application = T::configure(configuration, &renderer).unwrap();
136+
reactor
137+
.run_app(&mut Run {
138+
executor,
139+
application,
140+
window: &window,
141+
renderer,
142+
})
143+
.unwrap();
130144
}

pictor/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ mod renderer;
55

66
pub use crate::camera::*;
77
pub use crate::harness::*;
8+
9+
// TODO: Compile shaders from source code rather than statically loading binary SpirV.

0 commit comments

Comments
 (0)