qt-tracing/src/main.rs
2025-11-24 18:08:03 +03:00

105 lines
2.4 KiB
Rust

use std::{f32::consts::PI, sync::Arc};
use glam::uvec2;
use photon_light::{Core, RedrawArgs, SphericalPosition, UseNormal, init_gpu_inner};
use winit::{
application::ApplicationHandler,
event::WindowEvent,
event_loop::{ActiveEventLoop, ControlFlow, EventLoop},
window::Window,
};
const TITLE: &str = "WGPU example";
struct MainWindow {
window: Arc<Window>,
core: Core,
}
impl MainWindow {
fn new(event_loop: &ActiveEventLoop) -> Self {
let window = event_loop
.create_window(Window::default_attributes().with_title(TITLE))
.unwrap();
let window = Arc::new(window);
let gpu = pollster::block_on(init_gpu_inner(|instance| {
instance.create_surface(Arc::clone(&window))
}))
.unwrap();
let core = Core::new(gpu, uvec2(1, 1));
Self { window, core }
}
fn event(&mut self, event_loop: &ActiveEventLoop, event: WindowEvent) {
match event {
WindowEvent::CloseRequested => event_loop.exit(),
WindowEvent::Resized(physical_size) => self
.core
.configure(uvec2(physical_size.width, physical_size.height)),
WindowEvent::RedrawRequested => self.core.redraw(&RedrawArgs {
camera_position: SphericalPosition {
yaw: PI / 4.,
pitch: 0.5f32.sqrt().atan(),
distance: 3.0,
},
light_position: SphericalPosition {
yaw: 0.0,
pitch: PI / 3.,
distance: 1.0,
},
light_radius: 0.125,
light_spread: 0.125,
accum_sigma: 0.025,
accum_scale: 0.01,
reflections: 2,
use_normal: UseNormal::Light,
show_axes: true,
show_shapes: true,
show_hit_emission: false,
show_miss_emission: false,
show_direct_hit: false,
show_indirect_hit: false,
show_light: true,
}),
_ => {}
}
}
}
struct Application {
main_window: Option<MainWindow>,
}
impl Application {
fn new() -> Self {
Self { main_window: None }
}
}
impl ApplicationHandler for Application {
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
self.main_window = Some(MainWindow::new(event_loop));
}
fn window_event(
&mut self,
event_loop: &ActiveEventLoop,
window_id: winit::window::WindowId,
event: WindowEvent,
) {
let window = self
.main_window
.as_mut()
.expect("window must exist to recieve events");
assert_eq!(window.window.id(), window_id);
window.event(event_loop, event);
}
}
fn main() {
let event_loop = EventLoop::new().unwrap();
event_loop.set_control_flow(ControlFlow::Wait);
let mut app = Application::new();
event_loop.run_app(&mut app).unwrap();
}