From e435a8c486913a39ee908282be9ddf15d661e23e Mon Sep 17 00:00:00 2001 From: Petr Volf Date: Mon, 5 Dec 2022 11:21:05 +0100 Subject: [PATCH] removed wayland support due to https://github.com/rust-windowing/winit/pull/2429, drag&drop scenes to window --- Cargo.lock | 430 +----------------------- blackhole/Cargo.toml | 4 +- blackhole/src/bin/blackhole/args.rs | 10 + blackhole/src/bin/blackhole/main-cli.rs | 2 - blackhole/src/bin/blackhole/main.rs | 46 ++- blackhole/src/bin/blackhole/renderer.rs | 38 ++- blackhole/src/framebuffer.rs | 6 + 7 files changed, 78 insertions(+), 458 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 676400a..55407ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,18 +23,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "arrayref" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" - -[[package]] -name = "arrayvec" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" - [[package]] name = "atty" version = "0.2.14" @@ -102,37 +90,12 @@ version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" -[[package]] -name = "bytemuck" -version = "1.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aaa3a8d9a1ca92e282c96a32d6511b695d7d994d1d102ba85d279f9b2756947f" - -[[package]] -name = "calloop" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bcf530afb40e45e14440701e5e996d7fd139e84a912a4d83a8d6a0fb3e58663" -dependencies = [ - "log", - "nix 0.25.0", - "slotmap", - "thiserror", - "vec_map", -] - [[package]] name = "cast" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" -[[package]] -name = "cc" -version = "1.0.77" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4" - [[package]] name = "cfg-if" version = "1.0.0" @@ -249,15 +212,6 @@ dependencies = [ "os_str_bytes", ] -[[package]] -name = "cmake" -version = "0.1.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db34956e100b30725f2eb215f90d4871051239535632f84fea3bc92722c66b7c" -dependencies = [ - "cc", -] - [[package]] name = "cocoa" version = "0.24.1" @@ -269,7 +223,7 @@ dependencies = [ "cocoa-foundation", "core-foundation", "core-graphics", - "foreign-types 0.3.2", + "foreign-types", "libc", "objc", ] @@ -284,7 +238,7 @@ dependencies = [ "block", "core-foundation", "core-graphics-types", - "foreign-types 0.3.2", + "foreign-types", "libc", "objc", ] @@ -314,7 +268,7 @@ dependencies = [ "bitflags", "core-foundation", "core-graphics-types", - "foreign-types 0.3.2", + "foreign-types", "libc", ] @@ -326,19 +280,7 @@ checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b" dependencies = [ "bitflags", "core-foundation", - "foreign-types 0.3.2", - "libc", -] - -[[package]] -name = "core-text" -version = "19.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99d74ada66e07c1cefa18f8abfba765b486f250de2e4a999e5727fc0dd4b4a25" -dependencies = [ - "core-foundation", - "core-graphics", - "foreign-types 0.3.2", + "foreign-types", "libc", ] @@ -439,29 +381,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "crossfont" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21fd3add36ea31aba1520aa5288714dd63be506106753226d0eb387a93bc9c45" -dependencies = [ - "cocoa", - "core-foundation", - "core-foundation-sys", - "core-graphics", - "core-text", - "dwrote", - "foreign-types 0.5.0", - "freetype-rs", - "libc", - "log", - "objc", - "once_cell", - "pkg-config", - "servo-fontconfig", - "winapi", -] - [[package]] name = "crypto-common" version = "0.1.6" @@ -538,42 +457,12 @@ dependencies = [ "libloading", ] -[[package]] -name = "downcast-rs" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" - -[[package]] -name = "dwrote" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439a1c2ba5611ad3ed731280541d36d2e9c4ac5e7fb818a27b604bdc5a6aa65b" -dependencies = [ - "lazy_static", - "libc", - "serde", - "serde_derive", - "winapi", - "wio", -] - [[package]] name = "either" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" -[[package]] -name = "expat-sys" -version = "2.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658f19728920138342f68408b7cf7644d90d4784353d8ebc32e7e8663dbe45fa" -dependencies = [ - "cmake", - "pkg-config", -] - [[package]] name = "flate2" version = "1.0.24" @@ -596,28 +485,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" dependencies = [ - "foreign-types-shared 0.1.1", -] - -[[package]] -name = "foreign-types" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" -dependencies = [ - "foreign-types-macros", - "foreign-types-shared 0.3.1", -] - -[[package]] -name = "foreign-types-macros" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8469d0d40519bc608ec6863f1cc88f3f1deee15913f2f3b3e573d81ed38cccc" -dependencies = [ - "proc-macro2", - "quote", - "syn", + "foreign-types-shared", ] [[package]] @@ -626,34 +494,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" -[[package]] -name = "foreign-types-shared" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" - -[[package]] -name = "freetype-rs" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74eadec9d0a5c28c54bb9882e54787275152a4e36ce206b45d7451384e5bf5fb" -dependencies = [ - "bitflags", - "freetype-sys", - "libc", -] - -[[package]] -name = "freetype-sys" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a37d4011c0cc628dfa766fcc195454f4b068d7afdc2adfd28861191d866e731a" -dependencies = [ - "cmake", - "libc", - "pkg-config", -] - [[package]] name = "generic-array" version = "0.14.6" @@ -721,7 +561,7 @@ dependencies = [ "objc", "once_cell", "raw-window-handle 0.5.0", - "wayland-sys 0.30.0", + "wayland-sys", "windows-sys 0.36.1", "x11-dl", ] @@ -919,21 +759,6 @@ dependencies = [ "libc", ] -[[package]] -name = "memchr" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - -[[package]] -name = "memmap2" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b182332558b18d807c4ce1ca8ca983b34c3ee32765e47b3f0f69b90355cc1dc" -dependencies = [ - "libc", -] - [[package]] name = "memoffset" version = "0.6.5" @@ -943,12 +768,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - [[package]] name = "miniz_oxide" version = "0.5.4" @@ -1028,41 +847,6 @@ dependencies = [ "jni-sys", ] -[[package]] -name = "nix" -version = "0.24.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc" -dependencies = [ - "bitflags", - "cfg-if", - "libc", - "memoffset", -] - -[[package]] -name = "nix" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e322c04a9e3440c327fca7b6c8a63e6890a32fa2ad689db972425f07e0d22abb" -dependencies = [ - "autocfg", - "bitflags", - "cfg-if", - "libc", - "memoffset", -] - -[[package]] -name = "nom" -version = "7.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8903e5a29a317527874d0402f867152a3d21c908bb0b933e416c65e301d4c36" -dependencies = [ - "memchr", - "minimal-lexical", -] - [[package]] name = "num-traits" version = "0.2.15" @@ -1410,15 +1194,6 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" -[[package]] -name = "safe_arch" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1ff3d6d9696af502cc3110dacce942840fb06ff4514cad92236ecc455f2ce05" -dependencies = [ - "bytemuck", -] - [[package]] name = "same-file" version = "1.0.6" @@ -1428,30 +1203,12 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scoped-tls" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" - [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" -[[package]] -name = "sctk-adwaita" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61270629cc6b4d77ec1907db1033d5c2e1a404c412743621981a871dc9c12339" -dependencies = [ - "crossfont", - "log", - "smithay-client-toolkit", - "tiny-skia", -] - [[package]] name = "serde" version = "1.0.147" @@ -1483,27 +1240,6 @@ dependencies = [ "serde", ] -[[package]] -name = "servo-fontconfig" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7e3e22fe5fd73d04ebf0daa049d3efe3eae55369ce38ab16d07ddd9ac5c217c" -dependencies = [ - "libc", - "servo-fontconfig-sys", -] - -[[package]] -name = "servo-fontconfig-sys" -version = "5.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e36b879db9892dfa40f95da1c38a835d41634b825fbd8c4c418093d53c24b388" -dependencies = [ - "expat-sys", - "freetype-sys", - "pkg-config", -] - [[package]] name = "sha1" version = "0.10.5" @@ -1515,40 +1251,12 @@ dependencies = [ "digest", ] -[[package]] -name = "slotmap" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1e08e261d0e8f5c43123b7adf3e4ca1690d655377ac93a03b2c9d3e98de1342" -dependencies = [ - "version_check", -] - [[package]] name = "smallvec" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" -[[package]] -name = "smithay-client-toolkit" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f307c47d32d2715eb2e0ece5589057820e0e5e70d07c247d1063e844e107f454" -dependencies = [ - "bitflags", - "calloop", - "dlib", - "lazy_static", - "log", - "memmap2", - "nix 0.24.2", - "pkg-config", - "wayland-client", - "wayland-cursor", - "wayland-protocols", -] - [[package]] name = "strsim" version = "0.10.0" @@ -1601,31 +1309,6 @@ dependencies = [ "syn", ] -[[package]] -name = "tiny-skia" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "642680569bb895b16e4b9d181c60be1ed136fa0c9c7f11d004daf053ba89bf82" -dependencies = [ - "arrayref", - "arrayvec", - "bytemuck", - "cfg-if", - "png", - "safe_arch", - "tiny-skia-path", -] - -[[package]] -name = "tiny-skia-path" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c114d32f0c2ee43d585367cb013dfaba967ab9f62b90d9af0d696e955e70fa6c" -dependencies = [ - "arrayref", - "bytemuck", -] - [[package]] name = "tinytemplate" version = "1.2.1" @@ -1663,12 +1346,6 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "version_check" version = "0.9.4" @@ -1746,79 +1423,6 @@ version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" -[[package]] -name = "wayland-client" -version = "0.29.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f3b068c05a039c9f755f881dc50f01732214f5685e379829759088967c46715" -dependencies = [ - "bitflags", - "downcast-rs", - "libc", - "nix 0.24.2", - "scoped-tls", - "wayland-commons", - "wayland-scanner", - "wayland-sys 0.29.5", -] - -[[package]] -name = "wayland-commons" -version = "0.29.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8691f134d584a33a6606d9d717b95c4fa20065605f798a3f350d78dced02a902" -dependencies = [ - "nix 0.24.2", - "once_cell", - "smallvec", - "wayland-sys 0.29.5", -] - -[[package]] -name = "wayland-cursor" -version = "0.29.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6865c6b66f13d6257bef1cd40cbfe8ef2f150fb8ebbdb1e8e873455931377661" -dependencies = [ - "nix 0.24.2", - "wayland-client", - "xcursor", -] - -[[package]] -name = "wayland-protocols" -version = "0.29.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b950621f9354b322ee817a23474e479b34be96c2e909c14f7bc0100e9a970bc6" -dependencies = [ - "bitflags", - "wayland-client", - "wayland-commons", - "wayland-scanner", -] - -[[package]] -name = "wayland-scanner" -version = "0.29.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f4303d8fa22ab852f789e75a967f0a2cdc430a607751c0499bada3e451cbd53" -dependencies = [ - "proc-macro2", - "quote", - "xml-rs", -] - -[[package]] -name = "wayland-sys" -version = "0.29.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be12ce1a3c39ec7dba25594b97b42cb3195d54953ddb9d3d95a7c3902bc6e9d4" -dependencies = [ - "dlib", - "lazy_static", - "pkg-config", -] - [[package]] name = "wayland-sys" version = "0.30.0" @@ -1995,25 +1599,12 @@ dependencies = [ "percent-encoding", "raw-window-handle 0.4.3", "raw-window-handle 0.5.0", - "sctk-adwaita", - "smithay-client-toolkit", "wasm-bindgen", - "wayland-client", - "wayland-protocols", "web-sys", "windows-sys 0.36.1", "x11-dl", ] -[[package]] -name = "wio" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d129932f4644ac2396cb456385cbf9e63b5b30c6e8dc4820bdca4eb082037a5" -dependencies = [ - "winapi", -] - [[package]] name = "x11-dl" version = "2.20.1" @@ -2025,15 +1616,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "xcursor" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "463705a63313cd4301184381c5e8042f0a7e9b4bb63653f216311d4ae74690b7" -dependencies = [ - "nom", -] - [[package]] name = "xml-rs" version = "0.8.4" diff --git a/blackhole/Cargo.toml b/blackhole/Cargo.toml index 2611e9d..2cd2255 100644 --- a/blackhole/Cargo.toml +++ b/blackhole/Cargo.toml @@ -23,9 +23,9 @@ once_cell = "1.16.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" json5 = "0.4.1" -winit = "0.27.5" +winit = { version = "0.27.5", features = ["x11"], default-features = false } glutin = "0.30.2" -glutin-winit = "0.2.1" +glutin-winit = { version = "0.2.1", features = ["egl", "glx", "x11", "wgl"], default-features = false } raw-window-handle = "0.5.0" gl = "0.14.0" gl_wrapper = {path = "../gl_wrapper"} diff --git a/blackhole/src/bin/blackhole/args.rs b/blackhole/src/bin/blackhole/args.rs index bbb0ddc..d8a57d6 100644 --- a/blackhole/src/bin/blackhole/args.rs +++ b/blackhole/src/bin/blackhole/args.rs @@ -17,3 +17,13 @@ pub struct Args { #[arg(short, long, default_value_t = 0)] pub threads: usize, } + +#[derive(Debug, Parser)] +pub struct ArgsInteractive { + #[arg(value_enum, default_value_t = RenderMode::Shaded)] + pub mode: RenderMode, + #[arg(short, long, default_value_t = 1)] + pub samples: usize, + #[arg(short, long, default_value_t = 0)] + pub threads: usize, +} diff --git a/blackhole/src/bin/blackhole/main-cli.rs b/blackhole/src/bin/blackhole/main-cli.rs index b0acefa..d6eb2d8 100644 --- a/blackhole/src/bin/blackhole/main-cli.rs +++ b/blackhole/src/bin/blackhole/main-cli.rs @@ -5,7 +5,6 @@ use cgmath::{InnerSpace, Vector3}; use clap::Parser; -use blackhole::filter::BlackmanHarrisFilter; use blackhole::framebuffer::{FrameBuffer, Pixel}; mod args; @@ -40,7 +39,6 @@ fn main() { mode: args.mode, samples: args.samples, threads: args.threads, - filter: Box::new(BlackmanHarrisFilter::new(1.5)), frame: Frame { width: args.width, height: args.height, diff --git a/blackhole/src/bin/blackhole/main.rs b/blackhole/src/bin/blackhole/main.rs index 11d7590..ead1e7b 100644 --- a/blackhole/src/bin/blackhole/main.rs +++ b/blackhole/src/bin/blackhole/main.rs @@ -19,7 +19,6 @@ use winit::event::{Event, WindowEvent}; use winit::event_loop::{ControlFlow, EventLoop}; use winit::window::{Window, WindowBuilder}; -use blackhole::filter::BlackmanHarrisFilter; use blackhole::framebuffer::FrameBuffer; use gl_wrapper::geometry::{GeometryBuilder, VertexAttribute}; @@ -33,40 +32,23 @@ mod renderer; mod scene_loader; mod shaders; +use crate::args::ArgsInteractive; use crate::renderer::{RenderInMsg, RenderOutMsg}; -use args::Args; -use blackhole::frame::{Frame, Region}; use renderer::{RenderMode, Renderer}; use scene_loader::SceneLoader; fn main() { // clion needs help in trait annotation - let args = ::parse(); + let args = ::parse(); - let fb = FrameBuffer::new(args.width, args.height); + let fb = FrameBuffer::default(); let loader = SceneLoader::new(); - let scene = loader.load_path(args.scene); - - let scene = match scene { - Ok(v) => v, - Err(e) => { - eprintln!("Could not read scene description: {e}"); - std::process::exit(-1); - } - }; - let mut renderer = Renderer { mode: args.mode, samples: args.samples, threads: args.threads, - filter: Box::new(BlackmanHarrisFilter::new(1.5)), - frame: Frame { - width: args.width, - height: args.height, - region: Region::Whole, - }, ..Default::default() }; @@ -124,7 +106,7 @@ fn main() { let fb_clone = Arc::clone(&fb); let mut render_thread = Some(std::thread::spawn(move || { - renderer.render_interactive(&scene, fb_clone, tx_out, rx_in); + renderer.render_interactive(fb_clone, tx_out, rx_in); })); tx_in.send(RenderInMsg::Restart).unwrap(); @@ -133,8 +115,8 @@ fn main() { let read_lock = fb.read().unwrap(); Texture2D::new( - args.width as u32, - args.height as u32, + 1280, + 720, unsafe { read_lock.as_f32_slice() }, TextureFormats::RgbaF32, ) @@ -181,6 +163,22 @@ fn main() { .unwrap(); } } + WindowEvent::DroppedFile(path) => { + let scene_res = loader.load_path(&path); + + let scene = match scene_res { + Ok(v) => { + eprintln!("Read scene file from {:?}", path); + v + } + Err(e) => { + eprintln!("Could not read scene description: {e}"); + return; + } + }; + + tx_in.send(RenderInMsg::SceneChange(scene)).unwrap(); + } WindowEvent::CloseRequested => { control_flow.set_exit(); tx_in.send(RenderInMsg::Exit).unwrap(); diff --git a/blackhole/src/bin/blackhole/renderer.rs b/blackhole/src/bin/blackhole/renderer.rs index 3e2592c..2d567e7 100644 --- a/blackhole/src/bin/blackhole/renderer.rs +++ b/blackhole/src/bin/blackhole/renderer.rs @@ -113,19 +113,20 @@ impl Renderer { pub fn render_interactive( &mut self, - scene: &Scene, front_fb: Arc>, tx: Sender, rx: Receiver, ) -> () { - let mut should_render = true; + let mut should_render = false; let mut back_fb = FrameBuffer::new(self.frame.width, self.frame.height); - let max_step = scene.max_possible_step(scene.camera.location); + let mut scene: Option = None; 'main: loop { - if should_render { + if should_render && scene.is_some() { + let scene_unwrapped = scene.as_ref().unwrap(); + let max_step = scene_unwrapped.max_possible_step(scene_unwrapped.camera.location); for i in 0..self.samples { if let Some(msg) = rx.try_iter().next() { match msg { @@ -141,6 +142,11 @@ impl Renderer { } continue 'main; } + RenderInMsg::SceneChange(s) => { + scene = Some(s); + should_render = true; + continue 'main; + } RenderInMsg::Restart => { should_render = true; continue 'main; @@ -168,7 +174,14 @@ impl Renderer { .enumerate() { self.scanline_another_target( - scene, max_step, y, slice_in, slice_out, 0, i, offset, + scene_unwrapped, + max_step, + y, + slice_in, + slice_out, + 0, + i, + offset, ); } } else { @@ -185,7 +198,14 @@ impl Renderer { .enumerate() .for_each(|(y, (slice_out, slice_in))| { self.scanline_another_target( - scene, max_step, y, slice_in, slice_out, 0, i, offset, + scene_unwrapped, + max_step, + y, + slice_in, + slice_out, + 0, + i, + offset, ) }) }); @@ -215,6 +235,11 @@ impl Renderer { } continue 'main; } + RenderInMsg::SceneChange(s) => { + scene = Some(s); + should_render = true; + continue 'main; + } RenderInMsg::Restart => { should_render = true; continue 'main; @@ -523,6 +548,7 @@ impl Default for Renderer { pub enum RenderInMsg { Resize(u32, u32), + SceneChange(Scene), Restart, Stop, Exit, diff --git a/blackhole/src/framebuffer.rs b/blackhole/src/framebuffer.rs index 2e605cb..41aabb0 100644 --- a/blackhole/src/framebuffer.rs +++ b/blackhole/src/framebuffer.rs @@ -48,6 +48,12 @@ impl FrameBuffer { } } +impl Default for FrameBuffer { + fn default() -> Self { + Self::new(1280, 720) + } +} + #[derive(Copy, Clone)] pub struct Pixel { pub r: f32,