diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b34171b0..c1fb9b7b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,6 +22,11 @@ jobs: rust-linux: name: Rust (Linux) runs-on: ubuntu-latest + env: + # ponytail: apriltag-sys 0.3's bundled C uses `void (*f)()` callbacks, which the + # runner's GCC now compiles as C23 (zero args) and rejects. Drop once apriltag + # moves to apriltag-sys 0.4. + CFLAGS: -std=gnu17 steps: - uses: actions/checkout@v6 # NDI is intentionally opt-in (it needs a proprietary SDK), so CI builds the diff --git a/Cargo.lock b/Cargo.lock index 96c9c9f8..3e69c1d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -256,7 +256,7 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -267,7 +267,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -313,15 +313,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "arbitrary" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d036a3c4ab069c7b410a2ce876bd74808d2d0888a82667669f8e783a898bf1" -dependencies = [ - "derive_arbitrary", -] - [[package]] name = "arboard" version = "3.6.1" @@ -417,9 +408,9 @@ dependencies = [ [[package]] name = "async-executor" -version = "1.14.0" +version = "1.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c96bf972d85afc50bf5ab8fe2d54d1586b4e0b46c97c50a0c9e71e2f7bcd812a" +checksum = "f426a31126c735126297bc5ea7a521263c9faff4f63ca415267ee625651c4f37" dependencies = [ "async-task", "concurrent-queue", @@ -453,7 +444,7 @@ dependencies = [ "futures-lite", "parking", "polling", - "rustix 1.1.4", + "rustix 1.1.6", "slab", "windows-sys 0.61.2", ] @@ -495,7 +486,7 @@ dependencies = [ "cfg-if 1.0.4", "event-listener", "futures-lite", - "rustix 1.1.4", + "rustix 1.1.6", ] [[package]] @@ -506,7 +497,7 @@ checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -521,7 +512,7 @@ dependencies = [ "cfg-if 1.0.4", "futures-core", "futures-io", - "rustix 1.1.4", + "rustix 1.1.6", "signal-hook-registry", "slab", "windows-sys 0.61.2", @@ -541,7 +532,7 @@ checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -679,7 +670,7 @@ dependencies = [ "regex", "rustc-hash 1.1.0", "shlex 1.3.0", - "syn", + "syn 2.0.117", "which", ] @@ -700,7 +691,7 @@ dependencies = [ "regex", "rustc-hash 2.1.2", "shlex 1.3.0", - "syn", + "syn 2.0.117", ] [[package]] @@ -808,7 +799,7 @@ checksum = "f9abbd1bc6865053c427f7198e6af43bfdedc55ab791faed4fbd361d789575ff" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -851,7 +842,7 @@ checksum = "4dbf9978365bac10f54d1d4b04f7ce4427e51f71d61f2fe15e3fed5166474df7" dependencies = [ "bitflags 2.13.1", "polling", - "rustix 1.1.4", + "rustix 1.1.6", "slab", "tracing", ] @@ -875,7 +866,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "138efcf0940a02ebf0cc8d1eff41a1682a46b431630f4c52450d6265876021fa" dependencies = [ "calloop 0.14.4", - "rustix 1.1.4", + "rustix 1.1.6", "wayland-backend", "wayland-client", ] @@ -936,9 +927,9 @@ dependencies = [ [[package]] name = "chacha20" -version = "0.10.0" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601" +checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" dependencies = [ "cfg-if 1.0.4", "cpufeatures 0.3.0", @@ -978,9 +969,9 @@ dependencies = [ [[package]] name = "clipboard-win" -version = "5.4.1" +version = "5.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bde03770d3df201d4fb868f2c9c59e66a3e4e2bd06692a0fe701e7103c7e84d4" +checksum = "052af7878466feccda12ba7a6a67d019d712f296809559b47c12c8cc196d3a9a" dependencies = [ "error-code", ] @@ -1113,6 +1104,15 @@ dependencies = [ "web-sys", ] +[[package]] +name = "constant_time_eq" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "144e7f1de087984240b7816d47f698b414979faa6f40839c5b86d6bd47db57b7" +dependencies = [ + "rustversion", +] + [[package]] name = "core-foundation" version = "0.7.0" @@ -1496,17 +1496,6 @@ dependencies = [ "powerfmt", ] -[[package]] -name = "derive_arbitrary" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e567bd82dcff979e4b03460c307b3cdc9e96fde3d73bed1496d2bc75d9dd62a" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "dify" version = "0.8.0" @@ -1548,7 +1537,7 @@ dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -1577,7 +1566,7 @@ checksum = "1ac70aa55017e108007fbaf5aa0f54b021c98f92ff8af59d42eda9da96e3dd4f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -1631,7 +1620,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51a91c9b32ac4e8105dec255e849e0d66e27d7c34d184364fb93e469db08f690" dependencies = [ "drm-sys", - "rustix 1.1.4", + "rustix 1.1.6", ] [[package]] @@ -1882,7 +1871,7 @@ checksum = "67c78a4d8fdf9953a5c9d458f9efe940fd97a0cab0941c075a813ac594733827" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -1952,7 +1941,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -2172,7 +2161,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -2189,9 +2178,9 @@ checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" [[package]] name = "form_urlencoded" -version = "1.2.2" +version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +checksum = "afa489199eaffb1211795df1c6236ce1ad0d41a6fa45250add73e3b02420f06e" dependencies = [ "percent-encoding", ] @@ -2238,7 +2227,7 @@ checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -2309,7 +2298,7 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8" dependencies = [ - "rustix 1.1.4", + "rustix 1.1.6", "windows-link", ] @@ -2697,12 +2686,6 @@ dependencies = [ "pin-project-lite", ] -[[package]] -name = "http-range-header" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9171a2ea8a68358193d15dd5d70c1c10a2afc3e7e4c5bc92bc9f025cebd7359c" - [[package]] name = "httparse" version = "1.10.1" @@ -2883,6 +2866,16 @@ dependencies = [ "icu_properties", ] +[[package]] +name = "if-addrs" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69b2eeee38fef3aa9b4cc5f1beea8a2444fc00e7377cafae396de3f5c2065e24" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + [[package]] name = "if-addrs" version = "0.15.0" @@ -2956,17 +2949,6 @@ dependencies = [ "mint", ] -[[package]] -name = "imgui-wgpu" -version = "0.28.0" -dependencies = [ - "bytemuck", - "imgui", - "log", - "smallvec", - "wgpu", -] - [[package]] name = "imgui-winit-support" version = "0.13.0" @@ -3026,16 +3008,6 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" -[[package]] -name = "isf" -version = "0.1.0" -source = "git+https://github.com/BlueJayLouche/isf.git#2b9f8cd691b8e473cf10fb2c6b74be76602e914d" -dependencies = [ - "serde", - "serde_json", - "thiserror 1.0.69", -] - [[package]] name = "isf-example" version = "0.1.0" @@ -3123,7 +3095,7 @@ checksum = "47b605b0c050d845fc355bb11eb3f9a8deddc218ea60c76e61aa1f2adfb2c96a" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -3171,7 +3143,7 @@ dependencies = [ "quote", "rustc_version", "simd_cesu8", - "syn", + "syn 2.0.117", ] [[package]] @@ -3211,7 +3183,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38c0b942f458fe50cdac086d2f946512305e5631e720728f2a61aabcd47a6264" dependencies = [ "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -3304,7 +3276,7 @@ checksum = "ce2797d1a7ff34b0caca1a3259eed199527c037f5d7af63382782910909da6d3" dependencies = [ "bitflags 2.13.1", "byteorder", - "if-addrs", + "if-addrs 0.15.0", "log", "rusb", "socket2 0.5.10", @@ -3825,6 +3797,18 @@ dependencies = [ "jni-sys 0.3.1", ] +[[package]] +name = "nix" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77730ed34f01f4990cb2ea67fec715ecebc6fab9a6396cf83c5529b13f581bdc" +dependencies = [ + "bitflags 2.13.1", + "cfg-if 1.0.4", + "cfg_aliases", + "libc", +] + [[package]] name = "nohash-hasher" version = "0.2.0" @@ -3962,7 +3946,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -4044,7 +4028,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -4621,7 +4605,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -4656,7 +4640,7 @@ checksum = "c96395f0a926bc13b1c17622aaddda1ecb55d49c8f1bf9777e4d877800a43f8b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -4711,7 +4695,7 @@ dependencies = [ "concurrent-queue", "hermit-abi", "pin-project-lite", - "rustix 1.1.4", + "rustix 1.1.6", "windows-sys 0.61.2", ] @@ -4788,7 +4772,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" dependencies = [ "proc-macro2", - "syn", + "syn 2.0.117", ] [[package]] @@ -4818,17 +4802,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "prodjlink-rs" -version = "0.1.0" -source = "git+https://github.com/BlueJayLouche/prodjlink-rs?rev=e086a448560cf913bb1f2fdfe1bcc7dbd8af1a9f#e086a448560cf913bb1f2fdfe1bcc7dbd8af1a9f" -dependencies = [ - "libc", - "log", - "parking_lot", - "socket2 0.5.10", -] - [[package]] name = "profiling" version = "1.0.18" @@ -5203,40 +5176,6 @@ dependencies = [ "libusb1-sys", ] -[[package]] -name = "rust-embed" -version = "8.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04113cb9355a377d83f06ef1f0a45b8ab8cd7d8b1288160717d66df5c7988d27" -dependencies = [ - "rust-embed-impl", - "rust-embed-utils", - "walkdir", -] - -[[package]] -name = "rust-embed-impl" -version = "8.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0902e4c7c8e997159ab384e6d0fc91c221375f6894346ae107f47dd0f3ccaa" -dependencies = [ - "proc-macro2", - "quote", - "rust-embed-utils", - "syn", - "walkdir", -] - -[[package]] -name = "rust-embed-utils" -version = "8.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bcdef0be6fe7f6fa333b1073c949729274b05f123a0ad7efcb8efd878e5c3b1" -dependencies = [ - "sha2", - "walkdir", -] - [[package]] name = "rustc-hash" version = "1.1.0" @@ -5287,15 +5226,15 @@ dependencies = [ [[package]] name = "rustix" -version = "1.1.4" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa" dependencies = [ "bitflags 2.13.1", "errno", "libc", "linux-raw-sys 0.12.1", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -5314,7 +5253,6 @@ dependencies = [ "serde_json", "tokio", "tower", - "tower-http", "utoipa", "utoipa-swagger-ui", ] @@ -5325,7 +5263,6 @@ version = "0.1.0" dependencies = [ "anyhow", "cpal", - "crossbeam", "log", "realfft", "rustfft", @@ -5348,14 +5285,12 @@ dependencies = [ "serde_json", "tokio", "tower", - "tower-http", ] [[package]] name = "rustjay-core" version = "0.1.0" dependencies = [ - "anyhow", "bytemuck", "log", "serde", @@ -5372,7 +5307,6 @@ dependencies = [ "bytemuck", "dirs", "drm", - "env_logger", "gbm", "glow", "image", @@ -5414,16 +5348,13 @@ dependencies = [ "egui-winit", "egui_kittest", "imgui", - "imgui-wgpu", "imgui-winit-support", "log", - "pollster 0.4.0", "qrcode", "rustjay-audio", - "rustjay-control", "rustjay-core", + "rustjay-imgui-wgpu", "rustjay-io", - "rustjay-presets", "serde", "serde_json", "syphon-core", @@ -5431,6 +5362,17 @@ dependencies = [ "winit", ] +[[package]] +name = "rustjay-imgui-wgpu" +version = "0.28.0" +dependencies = [ + "bytemuck", + "imgui", + "log", + "smallvec", + "wgpu", +] + [[package]] name = "rustjay-io" version = "0.1.0" @@ -5461,7 +5403,6 @@ dependencies = [ "serde_json", "syphon-core", "syphon-wgpu", - "tokio", "v4l", "wgpu", "wgpu-hal", @@ -5475,7 +5416,6 @@ dependencies = [ "anyhow", "bytemuck", "image", - "isf", "log", "naga 29.0.3", "pollster 0.4.0", @@ -5483,6 +5423,7 @@ dependencies = [ "serde", "serde_json", "shaderc", + "thiserror 2.0.18", "wgpu", ] @@ -5551,6 +5492,18 @@ dependencies = [ "serde_json", ] +[[package]] +name = "rustjay-prodjlink" +version = "0.1.0" +source = "git+https://github.com/BlueJayLouche/prodjlink-rs?rev=b48000ff8c7a0dd09c65c91c584da5063701a19c#b48000ff8c7a0dd09c65c91c584da5063701a19c" +dependencies = [ + "if-addrs 0.13.4", + "libc", + "log", + "parking_lot", + "socket2 0.5.10", +] + [[package]] name = "rustjay-projection" version = "0.1.0" @@ -5579,7 +5532,6 @@ version = "0.1.0" dependencies = [ "anyhow", "bytemuck", - "image", "log", "pollster 0.4.0", "rustjay-core", @@ -5597,8 +5549,8 @@ name = "rustjay-sync" version = "0.1.0" dependencies = [ "log", - "prodjlink-rs", "rustjay-core", + "rustjay-prodjlink", "rusty_link", ] @@ -5706,7 +5658,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -5741,7 +5693,7 @@ checksum = "175ee3e80ae9982737ca543e96133087cbd9a485eecc3bc4de9c1a37b47ea59c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -5776,17 +5728,6 @@ dependencies = [ "digest", ] -[[package]] -name = "sha2" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" -dependencies = [ - "cfg-if 1.0.4", - "cpufeatures 0.2.17", - "digest", -] - [[package]] name = "shaderc" version = "0.10.1" @@ -5950,7 +5891,7 @@ dependencies = [ "libc", "log", "memmap2", - "rustix 1.1.4", + "rustix 1.1.6", "thiserror 2.0.18", "wayland-backend", "wayland-client", @@ -6007,7 +5948,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -6093,6 +6034,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "3.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "sync_wrapper" version = "1.0.2" @@ -6107,7 +6059,7 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -6172,8 +6124,8 @@ dependencies = [ "fastrand", "getrandom 0.4.2", "once_cell", - "rustix 1.1.4", - "windows-sys 0.61.2", + "rustix 1.1.6", + "windows-sys 0.52.0", ] [[package]] @@ -6234,7 +6186,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -6245,7 +6197,7 @@ checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -6370,9 +6322,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.52.3" +version = "1.54.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc7f01b389ac15039e4dc9531aa973a135d7a4135281b12d7c1bc79fd57fffe" +checksum = "b52fd3255258d26fac7264ab5a76b53c13367136dc011d3d6ad4f8ed070396a3" dependencies = [ "bytes", "libc", @@ -6391,7 +6343,7 @@ checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -6406,19 +6358,6 @@ dependencies = [ "tungstenite", ] -[[package]] -name = "tokio-util" -version = "0.7.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - [[package]] name = "toml" version = "1.1.4+spec-1.1.0" @@ -6478,31 +6417,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "tower-http" -version = "0.6.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" -dependencies = [ - "bitflags 2.13.1", - "bytes", - "futures-core", - "futures-util", - "http", - "http-body", - "http-body-util", - "http-range-header", - "httpdate", - "mime", - "mime_guess", - "percent-encoding", - "pin-project-lite", - "tokio", - "tokio-util", - "tower-layer", - "tower-service", -] - [[package]] name = "tower-layer" version = "0.3.3" @@ -6535,7 +6449,7 @@ checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -6588,6 +6502,12 @@ dependencies = [ "rustc-hash 2.1.2", ] +[[package]] +name = "typed-path" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce898823d8cd0f028662d2f349694b1af0a5cc9be83f1d213a00d3147445e1e" + [[package]] name = "typenum" version = "1.20.0" @@ -6602,7 +6522,7 @@ checksum = "f2f6fb2847f6742cd76af783a2a2c49e9375d0a111c7bef6f71cd9e738c72d6e" dependencies = [ "memoffset", "tempfile", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -6661,9 +6581,9 @@ checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" [[package]] name = "url" -version = "2.5.8" +version = "2.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +checksum = "f00cd2407bb42c0ef17be88d4cf020f5cceffd121665bac9b8b9493a369b3b1a" dependencies = [ "form_urlencoded", "idna", @@ -6720,9 +6640,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "utoipa" -version = "5.5.0" +version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bde15df68e80b16c7d16b9616e80770ad158988daa56a27dccd1e55558b0160" +checksum = "8765fe27aeff71012a3f90fa474cf1df863a7d0dd81ed25de4e63fff2544994f" dependencies = [ "indexmap", "serde", @@ -6732,27 +6652,26 @@ dependencies = [ [[package]] name = "utoipa-gen" -version = "5.5.0" +version = "6.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ba0b99ee52df3028635d93840c797102da61f8a7bb3cf751032455895b52ef8" +checksum = "d935f1c83fdf8b88f09bbe050d0cea78ea4afee6d7b0317403228c1200b2c8ab" dependencies = [ "proc-macro2", "quote", "regex", - "syn", + "syn 3.0.10", ] [[package]] name = "utoipa-swagger-ui" -version = "9.0.2" +version = "10.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d047458f1b5b65237c2f6dc6db136945667f40a7668627b3490b9513a3d43a55" +checksum = "4f1fd2f9615838885c6ff4115fde8a2b58825dc7b4617f78d29c167377a15c92" dependencies = [ "axum", - "base64 0.22.1", + "base64 0.23.1", "mime_guess", "regex", - "rust-embed", "serde", "serde_json", "url", @@ -6763,9 +6682,9 @@ dependencies = [ [[package]] name = "utoipa-swagger-ui-vendored" -version = "0.1.2" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2eebbbfe4093922c2b6734d7c679ebfebd704a0d7e56dfcb0d05818ce28977d" +checksum = "552a64d6a0d251ae28bc021838800943cce60c9ec2e60ff331f54e79f696268f" [[package]] name = "uuid" @@ -6973,7 +6892,7 @@ dependencies = [ "bumpalo", "proc-macro2", "quote", - "syn", + "syn 2.0.117", "wasm-bindgen-shared", ] @@ -7028,7 +6947,7 @@ checksum = "2857dd20b54e916ec7253b3d6b4d5c4d7d4ca2c33c2e11c6c76a99bd8744755d" dependencies = [ "cc", "downcast-rs", - "rustix 1.1.4", + "rustix 1.1.6", "scoped-tls", "smallvec", "wayland-sys", @@ -7041,7 +6960,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "645c7c96bb74690c3189b5c9cb4ca1627062bb23693a4fad9d8c3de958260144" dependencies = [ "bitflags 2.13.1", - "rustix 1.1.4", + "rustix 1.1.6", "wayland-backend", "wayland-scanner", ] @@ -7063,7 +6982,7 @@ version = "0.31.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a52d18780be9b1314328a3de5f930b73d2200112e3849ca6cb11822793fb34d" dependencies = [ - "rustix 1.1.4", + "rustix 1.1.6", "wayland-client", "xcursor", ] @@ -7151,7 +7070,7 @@ checksum = "cc1846eb04c49182e04f4a099e2a830a2b745610bbc1d61246e206f29c7000a0" dependencies = [ "bitflags 2.13.1", "downcast-rs", - "rustix 1.1.4", + "rustix 1.1.6", "wayland-backend", "wayland-scanner", ] @@ -7452,7 +7371,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -7514,7 +7433,7 @@ checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -7525,7 +7444,7 @@ checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -7899,7 +7818,7 @@ dependencies = [ "heck", "indexmap", "prettyplease", - "syn", + "syn 2.0.117", "wasm-metadata", "wit-bindgen-core", "wit-component", @@ -7915,7 +7834,7 @@ dependencies = [ "prettyplease", "proc-macro2", "quote", - "syn", + "syn 2.0.117", "wit-bindgen-core", "wit-bindgen-rust", ] @@ -7985,7 +7904,7 @@ dependencies = [ "libc", "libloading 0.8.9", "once_cell", - "rustix 1.1.4", + "rustix 1.1.6", "x11rb-protocol", ] @@ -8060,7 +7979,7 @@ checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", "synstructure", ] @@ -8086,7 +8005,7 @@ dependencies = [ "hex", "libc", "ordered-stream", - "rustix 1.1.4", + "rustix 1.1.6", "serde", "serde_repr", "tracing", @@ -8117,7 +8036,7 @@ checksum = "10da05367f3a7b7553c8cdf8fa91aee6b64afebe32b51c95177957efc47ca3a0" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", "zbus-lockstep", "zbus_xml", "zvariant", @@ -8132,7 +8051,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 2.0.117", "zbus_names", "zvariant", "zvariant_utils", @@ -8178,7 +8097,7 @@ checksum = "70e3cd084b1788766f53af483dd21f93881ff30d7320490ec3ef7526d203bad4" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] @@ -8198,10 +8117,30 @@ checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", "synstructure", ] +[[package]] +name = "zeroize" +version = "1.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85ccff8a4805aba1eaa4cd4afcd49f7557dd2cf5fd79ffc37f8959466effc5aa" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c50655cbb0fe3fc43170059e702f1ce5e19b84cec58dc87b037a09935c2f328" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + [[package]] name = "zerotrie" version = "0.2.4" @@ -8232,20 +8171,26 @@ checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.117", ] [[package]] name = "zip" -version = "3.0.0" +version = "9.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12598812502ed0105f607f941c386f43d441e00148fce9dec3ca5ffb0bde9308" +checksum = "2d8dbe089cf6b0448b78f5fc50139ab5aaa40d08ac07cdc1baf2c13add35fcce" dependencies = [ - "arbitrary", + "constant_time_eq", "crc32fast", "flate2", + "getrandom 0.4.2", "indexmap", + "libc", "memchr", + "nix", + "typed-path", + "windows-sys 0.60.2", + "zeroize", "zopfli", ] @@ -8312,7 +8257,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 2.0.117", "zvariant_utils", ] @@ -8325,6 +8270,6 @@ dependencies = [ "proc-macro2", "quote", "serde", - "syn", + "syn 2.0.117", "winnow", ] diff --git a/Cargo.toml b/Cargo.toml index ecadccdd..a9c2dc77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,8 @@ khronos-egl = { version = "6", features = ["dynamic"] } # GUI imgui = "0.12" -imgui-wgpu = "0.28" +# ponytail: upstream master has wgpu 30 but no release yet; back to plain "0.29" once it ships. +imgui-wgpu = { package = "rustjay-imgui-wgpu", path = "vendor/imgui-wgpu", version = "0.28.0" } imgui-winit-support = "0.13" egui = "0.36" egui-wgpu = "0.36" @@ -78,12 +79,8 @@ rosc = "0.11" # Web server axum = { version = "0.8", features = ["ws"] } -tower-http = { version = "0.6", features = ["fs", "cors"] } # Config / serialisation helpers -toml = "1.0" -chrono = { version = "0.4", features = ["serde"] } -instant = "0.1" dirs = "6.0" rand = "0.8" qrcode = "0.14" @@ -101,18 +98,15 @@ rustjay-mixer = { path = "crates/rustjay-mixer", version = "0.1.0" } rustjay-engine = { path = "crates/rustjay-engine", version = "0.1.0", default-features = false } rustjay-isf = { path = "crates/rustjay-isf", version = "0.1.0" } rustjay-api = { path = "crates/rustjay-api", version = "0.1.0" } -isf = { git = "https://github.com/BlueJayLouche/isf.git" } rustjay-projection = { path = "crates/rustjay-projection", version = "0.1.0" } rustjay-lighting = { path = "crates/rustjay-lighting", version = "0.1.0" } rustjay-ledmap = { path = "crates/rustjay-ledmap", version = "0.1.0" } syphon-core = "0.4.0" -syphon-metal = "0.4.2" syphon-wgpu = "0.4.3" [patch.crates-io] wgpu-hal = { path = "vendor/wgpu-hal" } nokhwa-bindings-macos = { path = "vendor/nokhwa-bindings-macos" } -imgui-wgpu = { path = "vendor/imgui-wgpu" } [profile.release] opt-level = 3 diff --git a/README.md b/README.md index 7f8bac0a..6681ebeb 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ rustjay-engine/ ```toml # Cargo.toml [dependencies] -rustjay-engine = { git = "https://github.com/BlueJayLouche/rustjay-engine" } +rustjay-engine = "0.1" bytemuck = { version = "1.21", features = ["derive"] } serde = { version = "1.0", features = ["derive"] } anyhow = "1.0" @@ -79,6 +79,16 @@ env_logger = "0.11" log = "0.4" ``` +The engine repo carries two runtime fixes that crates.io builds don't get: `wgpu-hal` +(EGL config selection on Raspberry Pi / Mesa vc4) and `nokhwa-bindings-macos` (USB and +Continuity cameras that crash AVFoundation). If you target either, pull them in: + +```toml +[patch.crates-io] +wgpu-hal = { git = "https://github.com/BlueJayLouche/rustjay-engine" } +nokhwa-bindings-macos = { git = "https://github.com/BlueJayLouche/rustjay-engine" } +``` + ```rust // src/main.rs use rustjay_engine::prelude::*; diff --git a/crates/ledmap-studio/Cargo.toml b/crates/ledmap-studio/Cargo.toml index cb0d6101..3a35f64a 100644 --- a/crates/ledmap-studio/Cargo.toml +++ b/crates/ledmap-studio/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2024" description = "Standalone CV LED-mapping tool: calibrate addressable strips over sACN and export ledmap.json" license = "MIT" +repository = "https://github.com/BlueJayLouche/rustjay-engine" [[bin]] name = "ledmap-studio" diff --git a/crates/rustjay-api/Cargo.toml b/crates/rustjay-api/Cargo.toml index f15ff5dc..8ae7b494 100644 --- a/crates/rustjay-api/Cargo.toml +++ b/crates/rustjay-api/Cargo.toml @@ -18,10 +18,9 @@ serde = { workspace = true } serde_json = { workspace = true } log = { workspace = true } anyhow = { workspace = true } -tower-http = { workspace = true } -utoipa = { version = "5.5", features = ["axum_extras"] } -utoipa-swagger-ui = { version = "9.0", features = ["axum", "vendored"] } +utoipa = { version = "6.0", features = ["axum_extras"] } +utoipa-swagger-ui = { version = "10.0.2", features = ["axum", "vendored"] } json-patch = "4.2" futures-util = "0.3" rand = { workspace = true } diff --git a/crates/rustjay-api/src/openapi.rs b/crates/rustjay-api/src/openapi.rs index 3be40146..df0b986e 100644 --- a/crates/rustjay-api/src/openapi.rs +++ b/crates/rustjay-api/src/openapi.rs @@ -82,3 +82,14 @@ use utoipa::OpenApi; ) )] pub struct ApiDoc; + +#[cfg(test)] +mod tests { + // Guards utoipa major bumps: the spec must still generate with its routes. + #[test] + fn spec_lists_routes() { + let json = ::openapi().to_json().unwrap(); + assert!(json.contains("\"/api/health\""), "health route missing from spec"); + assert!(json.contains("\"paths\"")); + } +} diff --git a/crates/rustjay-audio/Cargo.toml b/crates/rustjay-audio/Cargo.toml index 64892218..abd8b19b 100644 --- a/crates/rustjay-audio/Cargo.toml +++ b/crates/rustjay-audio/Cargo.toml @@ -16,4 +16,3 @@ anyhow = { workspace = true } cpal = { workspace = true } rustfft = { workspace = true } realfft = { workspace = true } -crossbeam = { workspace = true } diff --git a/crates/rustjay-control/Cargo.toml b/crates/rustjay-control/Cargo.toml index 724fdf48..44d4a537 100644 --- a/crates/rustjay-control/Cargo.toml +++ b/crates/rustjay-control/Cargo.toml @@ -23,7 +23,6 @@ tokio = { workspace = true } midir = { workspace = true } rosc = { workspace = true } axum = { workspace = true } -tower-http = { workspace = true } rand = { workspace = true } [dev-dependencies] diff --git a/crates/rustjay-core/Cargo.toml b/crates/rustjay-core/Cargo.toml index 514cc95c..f3905f92 100644 --- a/crates/rustjay-core/Cargo.toml +++ b/crates/rustjay-core/Cargo.toml @@ -12,7 +12,6 @@ categories = ["graphics", "multimedia::video"] serde = { workspace = true } serde_json = { workspace = true } log = { workspace = true } -anyhow = { workspace = true } wgpu = { workspace = true } bytemuck = { workspace = true } uuid = { workspace = true } diff --git a/crates/rustjay-engine/Cargo.toml b/crates/rustjay-engine/Cargo.toml index 9dd9ff1a..dfaedb87 100644 --- a/crates/rustjay-engine/Cargo.toml +++ b/crates/rustjay-engine/Cargo.toml @@ -32,7 +32,6 @@ serde = { workspace = true } serde_json = { workspace = true } dirs = { workspace = true } tokio = { workspace = true } -env_logger = "0.11" imgui = { workspace = true } [target.'cfg(target_os = "macos")'.dependencies] diff --git a/crates/rustjay-gui/Cargo.toml b/crates/rustjay-gui/Cargo.toml index 527d2bd6..29e7ca3a 100644 --- a/crates/rustjay-gui/Cargo.toml +++ b/crates/rustjay-gui/Cargo.toml @@ -12,8 +12,6 @@ categories = ["graphics", "gui"] rustjay-core = { workspace = true } rustjay-audio = { workspace = true } rustjay-io = { workspace = true, default-features = false } -rustjay-control = { workspace = true } -rustjay-presets = { workspace = true } log = { workspace = true } anyhow = { workspace = true } wgpu = { workspace = true } @@ -27,8 +25,7 @@ egui-wgpu = { workspace = true, optional = true } egui-winit = { workspace = true, optional = true } serde = { workspace = true } serde_json = { workspace = true } -pollster = { workspace = true } -qrcode = { workspace = true } +qrcode = { workspace = true, optional = true } [features] default = ["imgui-renderer"] @@ -38,11 +35,11 @@ default = ["imgui-renderer"] # dependency, so imgui tabs build regardless of this flag. imgui-renderer = ["dep:imgui-wgpu"] ndi = ["rustjay-core/ndi"] -egui = ["dep:egui", "dep:egui-wgpu", "dep:egui-winit"] +egui = ["dep:egui", "dep:egui-wgpu", "dep:egui-winit", "dep:qrcode"] link = ["rustjay-core/link"] prodj = ["rustjay-core/prodj"] -mtc = ["rustjay-control/mtc"] +mtc = [] [dev-dependencies] egui_kittest = { version = "=0.36.1", features = ["snapshot", "wgpu"] } diff --git a/crates/rustjay-io/Cargo.toml b/crates/rustjay-io/Cargo.toml index b49d1afd..1f6ca239 100644 --- a/crates/rustjay-io/Cargo.toml +++ b/crates/rustjay-io/Cargo.toml @@ -18,7 +18,6 @@ wgpu = { workspace = true } bytemuck = { workspace = true } crossbeam = { workspace = true } cpal = { workspace = true } -tokio = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } diff --git a/crates/rustjay-io/src/output/mod.rs b/crates/rustjay-io/src/output/mod.rs index cf439494..f0199fab 100644 --- a/crates/rustjay-io/src/output/mod.rs +++ b/crates/rustjay-io/src/output/mod.rs @@ -510,6 +510,8 @@ impl OutputManager { pub fn set_led_placement(&mut self, _quad: Option<[[f32; 2]; 4]>) {} /// Returns true if any CPU-path output (NDI, V4L2, Spout, Recorder, LED) needs readback. + // The cfg-gated arms compile out on some targets, leaving an `if … { return true } false`. + #[allow(clippy::needless_bool)] fn needs_readback(&self) -> bool { if self.recorder.is_some() { return true; diff --git a/crates/rustjay-isf/Cargo.toml b/crates/rustjay-isf/Cargo.toml index cae68dbf..0a045a5a 100644 --- a/crates/rustjay-isf/Cargo.toml +++ b/crates/rustjay-isf/Cargo.toml @@ -3,15 +3,17 @@ name = "rustjay-isf" version = "0.1.0" edition = "2024" description = "ISF (Interactive Shader Format) support for rustjay-engine — GLSL→WGSL transpiler and EffectPlugin adapter" +license = "MIT" +repository = "https://github.com/BlueJayLouche/rustjay-engine" [dependencies] rustjay-core = { workspace = true } wgpu = { workspace = true } -isf = { workspace = true } bytemuck = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } anyhow = { workspace = true } +thiserror = { workspace = true } log = { workspace = true } pollster = { workspace = true } shaderc = { version = "0.10", features = ["build-from-source"] } diff --git a/crates/rustjay-isf/LICENSE-isf-MIT b/crates/rustjay-isf/LICENSE-isf-MIT new file mode 100644 index 00000000..d105eb65 --- /dev/null +++ b/crates/rustjay-isf/LICENSE-isf-MIT @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2020 Nannou Organisation. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/crates/rustjay-isf/src/compile.rs b/crates/rustjay-isf/src/compile.rs index 2cf86e9b..c359d24a 100644 --- a/crates/rustjay-isf/src/compile.rs +++ b/crates/rustjay-isf/src/compile.rs @@ -23,7 +23,7 @@ //! code) can fool them; the corpus shows this is rare. Upgrade path = a real GLSL parser. use std::collections::HashMap; -use isf::{InputType, Isf}; +use crate::isf::{InputType, Isf}; /// GPU manifest: everything the runtime needs to build the bind group layout and /// pack the inputs uniform buffer. diff --git a/crates/rustjay-isf/src/effect.rs b/crates/rustjay-isf/src/effect.rs index 9e7718da..ac567bcb 100644 --- a/crates/rustjay-isf/src/effect.rs +++ b/crates/rustjay-isf/src/effect.rs @@ -6,6 +6,7 @@ //! binding 2 = img_sampler (when textures exist), bindings 3+ = texture2D per //! image/audio input, then PASSES targets and IMPORTED names. +use crate::isf; use std::{ collections::HashMap, path::{Path, PathBuf}, diff --git a/crates/rustjay-isf/src/header.rs b/crates/rustjay-isf/src/header.rs index c7962065..73a19a5c 100644 --- a/crates/rustjay-isf/src/header.rs +++ b/crates/rustjay-isf/src/header.rs @@ -12,6 +12,7 @@ //! (for what `serde_json` itself will not read) or [`repair`] (for what it //! reads but `Isf` will not accept). +use crate::isf; use serde_json::{Map, Value}; /// Parse a shader's ISF header, repairing the malformed-but-common shapes. diff --git a/crates/rustjay-isf/src/isf.rs b/crates/rustjay-isf/src/isf.rs new file mode 100644 index 00000000..d756390f --- /dev/null +++ b/crates/rustjay-isf/src/isf.rs @@ -0,0 +1,434 @@ +// Vendored from https://github.com/BlueJayLouche/isf @ 2b9f8cd (a fork of +// https://github.com/nannou-org/isf). crates.io's `isf` is the unforked 2020 +// release, and crates.io can't take git deps, so the fork lives here. +// Upstream licence: MIT OR Apache-2.0, Copyright (c) 2020 Nannou Organisation +// (MIT text kept in ../LICENSE-isf-MIT). +// ponytail: one-file copy, not a crate — split it out if anything besides +// rustjay-isf ever needs it. + +//! A crate for parsing the ISF aka Interactive Shader Format as described by the spec: +//! +//! https://www.interactiveshaderformat.com/spec +//! +//! Also provides deserialization and serialization of the `Isf` instance for ease of both +//! consuming and generating ISF shaders. +//! +//! The [**parse**](./fn.parse.html) function can parse a given GLSL string to produce an +//! [**Isf**](./struct.Isf.html) instance. The **Isf** type represents a fully structured +//! representation of the format, including typed [**Input**](./struct.Input.html)s. + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use std::collections::BTreeMap; +use std::ops::Deref; +use std::path::PathBuf; +use thiserror::Error; + +/// Representation of the JSON structure parsed from the top-level GLSL comment. +/// +/// This is referred to as the "top-level dict" in the spec. +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] +pub struct Isf { + #[serde(default, rename = "ISFVSN")] + pub isfvsn: Option, + #[serde(default, rename = "VSN")] + pub vsn: Option, + #[serde(default, rename = "DESCRIPTION")] + pub description: Option, + #[serde(default, rename = "CATEGORIES")] + pub categories: Vec, + #[serde(default, rename = "INPUTS")] + pub inputs: Vec, + #[serde(default, rename = "PASSES")] + pub passes: Vec, + #[serde(default, rename = "IMPORTED")] + pub imported: BTreeMap, +} + +/// Describes an input to the ISF shader. +#[derive(Clone, Debug, PartialEq)] +pub struct Input { + pub name: String, + pub label: Option, + pub ty: InputType, +} + +/// Input types supported by ISF. +#[derive(Clone, Debug, PartialEq)] +pub enum InputType { + Event, + Bool(InputBool), + Long(InputLong), + Float(InputFloat), + Point2d(InputPoint2d), + Color(InputColor), + Image, + Audio(InputAudio), + AudioFft(InputAudioFft), +} + +/// Possible values stored for the type. +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] +pub struct InputValues { + #[serde(rename = "DEFAULT")] + pub default: Option, + #[serde(rename = "MIN")] + pub min: Option, + #[serde(rename = "MAX")] + pub max: Option, + #[serde(rename = "IDENTITY")] + pub identity: Option, +} + +#[derive(Clone, Debug, PartialEq)] +pub struct InputBool { + pub default: Option, +} + +#[derive(Clone, Debug, PartialEq)] +pub struct InputLong { + pub input_values: InputValues, + pub values: Vec, + pub labels: Vec, +} + +pub type InputFloat = InputValues; + +pub type InputPoint2d = InputValues<[f32; 2]>; + +pub type InputColor = InputValues>; + +#[derive(Clone, Debug, PartialEq)] +pub struct InputAudio { + pub num_samples: Option, +} + +#[derive(Clone, Debug, PartialEq)] +pub struct InputAudioFft { + pub num_columns: Option, +} + +/// A helper type to simplify implementation of serialize/deserialize for `Input`. +#[derive(Debug, Deserialize, Serialize)] +struct InputDict { + #[serde(rename = "NAME")] + pub name: String, + #[serde(rename = "LABEL")] + pub label: Option, + #[serde(rename = "TYPE")] + pub ty: String, + #[serde(default, rename = "DEFAULT")] + pub default: Option, + #[serde(default, rename = "MIN")] + pub min: Option, + #[serde(default, rename = "MAX")] + pub max: Option, + #[serde(default, rename = "IDENTITY")] + pub identity: Option, + #[serde(default, rename = "VALUES")] + pub values: Vec, + #[serde(default, rename = "LABELS")] + pub labels: Vec, +} + +/// Describes a pass of an ISF shader. +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] +pub struct Pass { + #[serde(default, rename = "TARGET")] + pub target: Option, + #[serde(default, deserialize_with = "deserialize_bool", rename = "PERSISTENT")] + pub persistent: bool, + #[serde(default, deserialize_with = "deserialize_bool", rename = "FLOAT")] + pub float: bool, + #[serde(default, deserialize_with = "deserialize_opt_string", rename = "WIDTH")] + pub width: Option, + #[serde(default, deserialize_with = "deserialize_opt_string", rename = "HEIGHT")] + pub height: Option, +} + +/// A described image import +#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] +pub struct ImageImport { + #[serde(rename = "PATH")] + pub path: PathBuf, +} + +/// Errors that might occur while parsing a GLSL string for an ISF blob. +#[derive(Debug, Error)] +pub enum ParseError { + #[error("failed to find the top comment containing the JSON blob")] + MissingTopComment, + #[error("failed to parse JSON from the top comment: {err}")] + Json { + #[from] + err: serde_json::Error, + }, +} + +impl InputValues { + fn from_opts( + default: Option, + min: Option, + max: Option, + identity: Option, + ) -> Result + where + T: for<'de> Deserialize<'de>, + { + let default = match default { + Some(t) => Some(serde_json::from_value(t)?), + None => None, + }; + let min = match min { + Some(t) => Some(serde_json::from_value(t)?), + None => None, + }; + let max = match max { + Some(t) => Some(serde_json::from_value(t)?), + None => None, + }; + let identity = match identity { + Some(t) => Some(serde_json::from_value(t)?), + None => None, + }; + Ok(InputValues { + default, + min, + max, + identity, + }) + } + + fn write_to_dict(&self, dict: &mut InputDict) + where + T: Clone + Into, + { + dict.default = self.default.as_ref().map(|t| t.clone().into()); + dict.min = self.min.as_ref().map(|t| t.clone().into()); + dict.max = self.max.as_ref().map(|t| t.clone().into()); + dict.identity = self.identity.as_ref().map(|t| t.clone().into()); + } +} + +impl Deref for InputLong { + type Target = InputValues; + fn deref(&self) -> &Self::Target { + &self.input_values + } +} + +impl Serialize for Input { + fn serialize(&self, s: S) -> Result + where + S: Serializer, + { + let Input { name, label, ty } = self; + + let mut dict = InputDict { + name: name.clone(), + label: label.clone(), + ty: String::new(), + default: None, + min: None, + max: None, + identity: None, + values: vec![], + labels: vec![], + }; + + fn pt2_to_json_value([x, y]: [f32; 2]) -> serde_json::Value { + serde_json::Value::Array(vec![x.into(), y.into()]) + } + + match ty { + InputType::Event => { + dict.ty = "event".to_string(); + }, + + InputType::Bool(t) => { + dict.ty = "bool".to_string(); + dict.default = t.default.map(Into::into); + }, + + InputType::Long(t) => { + dict.ty = "long".to_string(); + t.write_to_dict(&mut dict); + dict.values = t.values.clone(); + dict.labels = t.labels.clone(); + }, + + InputType::Float(t) => { + dict.ty = "float".to_string(); + t.write_to_dict(&mut dict); + }, + + InputType::Point2d(t) => { + dict.ty = "point2D".to_string(); + dict.default = t.default.map(pt2_to_json_value); + dict.min = t.min.map(pt2_to_json_value); + dict.max = t.max.map(pt2_to_json_value); + dict.identity = t.identity.map(pt2_to_json_value); + }, + + InputType::Color(t) => { + dict.ty = "color".to_string(); + t.write_to_dict(&mut dict); + }, + + InputType::Image => { + dict.ty = "image".to_string(); + }, + + InputType::Audio(t) => { + dict.ty = "audio".to_string(); + dict.max = t.num_samples.map(Into::into); + }, + + InputType::AudioFft(t) => { + dict.ty = "audioFFT".to_string(); + dict.max = t.num_columns.map(Into::into); + }, + }; + + dict.serialize(s) + } +} + +impl<'de> Deserialize<'de> for Input { + fn deserialize(d: D) -> Result + where + D: Deserializer<'de>, + { + let InputDict { + name, + label, + ty, + default, + min, + max, + identity, + values, + labels, + } = InputDict::deserialize(d)?; + + let ty = match &ty[..] { + "event" => InputType::Event, + + "bool" => InputType::Bool(InputBool { + default: match default { + Some(serde_json::Value::Bool(b)) => Some(b), + Some(serde_json::Value::Number(n)) if n.is_u64() => { + Some(n.as_u64().unwrap() != 0) + } + Some(serde_json::Value::Number(n)) if n.is_f64() => { + Some(n.as_f64().unwrap() as u64 != 0) + } + Some(value) => { + serde_json::from_value(value).map_err(serde::de::Error::custom)? + } + None => None, + }, + }), + + // `int` is not in the spec, but MadMapper and its shaders write it. + "long" | "int" => InputType::Long(InputLong { + input_values: InputValues::from_opts(default, min, max, identity) + .map_err(serde::de::Error::custom)?, + values, + labels, + }), + + "float" => InputType::Float( + InputFloat::from_opts(default, min, max, identity) + .map_err(serde::de::Error::custom)?, + ), + + "point2D" => InputType::Point2d( + InputPoint2d::from_opts(default, min, max, identity) + .map_err(serde::de::Error::custom)?, + ), + + "color" => InputType::Color( + InputColor::from_opts(default, min, max, identity) + .map_err(serde::de::Error::custom)?, + ), + + "image" => InputType::Image, + + "audio" => InputType::Audio(InputAudio { + num_samples: match max { + Some(value) => { + serde_json::from_value(value).map_err(serde::de::Error::custom)? + } + None => None, + }, + }), + + "audioFFT" => InputType::AudioFft(InputAudioFft { + num_columns: match max { + Some(value) => { + serde_json::from_value(value).map_err(serde::de::Error::custom)? + } + None => None, + }, + }), + + other => { + return Err(serde::de::Error::custom(format!( + "unknown input type `{other}`" + ))); + } + }; + + Ok(Input { name, label, ty }) + } +} + +/// Attempt to parse an ISF blob from a GLSL source string. +/// +/// This will not do any GLSL parsing and simply checks the top of the string for a `/* */` comment +/// containing JSON that may be parsed as an ISF blob. +pub fn parse(glsl_src: &str) -> Result { + let comment_contents = top_comment_contents(glsl_src).ok_or(ParseError::MissingTopComment)?; + Ok(serde_json::from_str(comment_contents)?) +} + +/// Find the top `/* */` comment in a GLSL src string and return the contents with whitespace +/// trimmed. +fn top_comment_contents(glsl_src: &str) -> Option<&str> { + let start = glsl_src.find("/*")? + "/*".len(); + let end = start + glsl_src[start..].find("*/")?; + Some(glsl_src[start..end].trim()) +} + +/// Support integers for bool seriallization. +fn deserialize_bool<'de, D>(d: D) -> Result +where + D: Deserializer<'de>, +{ + let b = match serde_json::Value::deserialize(d)? { + serde_json::Value::Bool(b) => b, + serde_json::Value::Number(n) if n.is_u64() => { + n.as_u64().unwrap() != 0 + } + serde_json::Value::Number(n) if n.is_f64() => { + n.as_f64().unwrap() as u64 != 0 + } + value => serde_json::from_value(value).map_err(serde::de::Error::custom)?, + }; + Ok(b) +} + +/// A string deserialization that also supports integers. +fn deserialize_opt_string<'de, D>(d: D) -> Result, D::Error> +where + D: Deserializer<'de>, +{ + let opt: Option = match <_>::deserialize(d)? { + None => None, + Some(serde_json::Value::Null) => None, + Some(serde_json::Value::Number(n)) => Some(n.to_string()), + Some(serde_json::Value::String(s)) => Some(s), + Some(value) => serde_json::from_value(value).map_err(serde::de::Error::custom)?, + }; + Ok(opt) +} diff --git a/crates/rustjay-isf/src/lib.rs b/crates/rustjay-isf/src/lib.rs index 9822f7b5..f7da2713 100644 --- a/crates/rustjay-isf/src/lib.rs +++ b/crates/rustjay-isf/src/lib.rs @@ -15,6 +15,7 @@ pub mod compile; pub mod effect; pub mod header; +pub mod isf; pub mod params; pub use compile::{ diff --git a/crates/rustjay-isf/src/params.rs b/crates/rustjay-isf/src/params.rs index 08e261d8..ef3ac979 100644 --- a/crates/rustjay-isf/src/params.rs +++ b/crates/rustjay-isf/src/params.rs @@ -1,5 +1,6 @@ //! Bridge ISF input declarations to rustjay-core parameter descriptors. +use crate::isf; use std::collections::HashMap; use isf::InputType; diff --git a/crates/rustjay-isf/tests/crt_glass.rs b/crates/rustjay-isf/tests/crt_glass.rs index 27bee026..0db247f8 100644 --- a/crates/rustjay-isf/tests/crt_glass.rs +++ b/crates/rustjay-isf/tests/crt_glass.rs @@ -18,6 +18,6 @@ fn transpiles(name: &str) { .join("shaders") .join(name); let src = std::fs::read_to_string(&path).unwrap_or_else(|_| panic!("read {name}")); - let isf = isf::parse(&src).expect("ISF header parses"); + let isf = rustjay_isf::isf::parse(&src).expect("ISF header parses"); rustjay_isf::generate_wgsl(&isf, &src).unwrap_or_else(|e| panic!("{name} transpile: {e}")); } diff --git a/crates/rustjay-laser/Cargo.toml b/crates/rustjay-laser/Cargo.toml index d9c7c1cf..ff359054 100644 --- a/crates/rustjay-laser/Cargo.toml +++ b/crates/rustjay-laser/Cargo.toml @@ -19,8 +19,8 @@ dac = ["dep:laser-dac"] anyhow = { workspace = true } log = { workspace = true } wgpu = { workspace = true } -rustjay-core = { path = "../rustjay-core" } -rustjay-isf = { path = "../rustjay-isf" } +rustjay-core = { workspace = true } +rustjay-isf = { workspace = true } # Exactly the transports we want, and none of the rest: the crate's default # features add an audio-out backend (cpal) and ASIO, which needs the Steinberg # SDK on Windows. `idn` is the one that matters most for reach — it is the open diff --git a/crates/rustjay-ledmap/Cargo.toml b/crates/rustjay-ledmap/Cargo.toml index 69f44109..923e8db3 100644 --- a/crates/rustjay-ledmap/Cargo.toml +++ b/crates/rustjay-ledmap/Cargo.toml @@ -13,4 +13,4 @@ log = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } anyhow = { workspace = true } -rustjay-lighting = { path = "../rustjay-lighting" } +rustjay-lighting = { workspace = true } diff --git a/crates/rustjay-render/Cargo.toml b/crates/rustjay-render/Cargo.toml index 6c4f1d56..76efeee4 100644 --- a/crates/rustjay-render/Cargo.toml +++ b/crates/rustjay-render/Cargo.toml @@ -16,8 +16,6 @@ anyhow = { workspace = true } wgpu = { workspace = true } winit = { workspace = true } bytemuck = { workspace = true } -image = { workspace = true } -pollster = { workspace = true } [target.'cfg(target_os = "macos")'.dependencies] syphon-core = { workspace = true } @@ -37,3 +35,6 @@ windows = { version = "0.62", features = [ [target.'cfg(target_os = "linux")'.dependencies] v4l = "0.14" + +[dev-dependencies] +pollster = { workspace = true } diff --git a/crates/rustjay-sync/Cargo.toml b/crates/rustjay-sync/Cargo.toml index e7f56a32..3a46fc68 100644 --- a/crates/rustjay-sync/Cargo.toml +++ b/crates/rustjay-sync/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2024" description = "Sync & timing: Ableton Link, ProDJ Link, MTC" license = "MIT" +repository = "https://github.com/BlueJayLouche/rustjay-engine" [features] default = ["link"] @@ -17,4 +18,4 @@ rustjay-core = { path = "../rustjay-core", version = "0.1.0" } log = { workspace = true } rusty_link = { version = "0.4", optional = true } -prodjlink-rs = { git = "https://github.com/BlueJayLouche/prodjlink-rs", rev = "e086a448560cf913bb1f2fdfe1bcc7dbd8af1a9f", optional = true } +prodjlink-rs = { package = "rustjay-prodjlink", version = "0.1.0", git = "https://github.com/BlueJayLouche/prodjlink-rs", rev = "b48000ff8c7a0dd09c65c91c584da5063701a19c", optional = true } diff --git a/examples/decklink/Cargo.toml b/examples/decklink/Cargo.toml index ba4ded45..aefa6849 100644 --- a/examples/decklink/Cargo.toml +++ b/examples/decklink/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "decklink-input" version = "0.1.0" +publish = false edition = "2024" description = "Blackmagic DeckLink input example for rustjay-engine" diff --git a/examples/delta-egui/Cargo.toml b/examples/delta-egui/Cargo.toml index 49b4235d..b83461b7 100644 --- a/examples/delta-egui/Cargo.toml +++ b/examples/delta-egui/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "delta-egui" version = "0.1.0" +publish = false edition = "2024" description = "Delta effect with a professional egui interface" diff --git a/examples/delta/Cargo.toml b/examples/delta/Cargo.toml index 79d4e33b..5d359e7b 100644 --- a/examples/delta/Cargo.toml +++ b/examples/delta/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "delta" version = "0.1.0" +publish = false edition = "2024" description = "RGB delay / motion extraction — proves engine generality" diff --git a/examples/flux/Cargo.toml b/examples/flux/Cargo.toml index 0fe19ffd..d99d412a 100644 --- a/examples/flux/Cargo.toml +++ b/examples/flux/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "flux" version = "0.1.0" +publish = false edition = "2021" description = "Optical-flow warp with motion feedback trails" diff --git a/examples/isf-example/Cargo.toml b/examples/isf-example/Cargo.toml index ee7edc18..9df74184 100644 --- a/examples/isf-example/Cargo.toml +++ b/examples/isf-example/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "isf-example" version = "0.1.0" +publish = false edition = "2024" description = "ISF (Interactive Shader Format) viewer — loads any .fs file via file picker" diff --git a/examples/mixer/Cargo.toml b/examples/mixer/Cargo.toml index 43bfa244..2bde7ba4 100644 --- a/examples/mixer/Cargo.toml +++ b/examples/mixer/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "mixer" version = "0.1.0" +publish = false edition = "2024" description = "2-channel mixer example demonstrating rustjay-mixer" diff --git a/examples/projection/Cargo.toml b/examples/projection/Cargo.toml index fef35f7e..d9273a35 100644 --- a/examples/projection/Cargo.toml +++ b/examples/projection/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "projection" version = "0.1.0" +publish = false edition = "2024" description = "Projection mapping example demonstrating rustjay-projection" diff --git a/examples/sputnik/Cargo.toml b/examples/sputnik/Cargo.toml index 0a67040b..bad5833a 100644 --- a/examples/sputnik/Cargo.toml +++ b/examples/sputnik/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "sputnik" version = "0.1.0" +publish = false edition = "2024" description = "Vertex-shader mesh displacement — proves engine handles indexed mesh geometry" diff --git a/examples/template/Cargo.toml b/examples/template/Cargo.toml index 2c2e72a9..86d828f8 100644 --- a/examples/template/Cargo.toml +++ b/examples/template/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "template" version = "0.1.0" +publish = false edition = "2024" description = "HSB color template — reference example for rustjay-engine" diff --git a/examples/videowall/Cargo.toml b/examples/videowall/Cargo.toml index b41d459c..318b19ab 100644 --- a/examples/videowall/Cargo.toml +++ b/examples/videowall/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "videowall" version = "0.1.0" +publish = false edition = "2024" description = "Video-wall / HDMI-matrix mapper — N projector outputs, each a grid of source→cell mappings with AprilTag auto-calibration" diff --git a/examples/vp404/Cargo.toml b/examples/vp404/Cargo.toml index cabb0c81..93cc65f2 100644 --- a/examples/vp404/Cargo.toml +++ b/examples/vp404/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "vp404" version = "0.1.0" +publish = false edition = "2021" description = "VP-404 — SP-404-style video sampler (port of rustjay-404)." diff --git a/examples/waaaves/Cargo.toml b/examples/waaaves/Cargo.toml index 66cafa72..6d5b56a9 100644 --- a/examples/waaaves/Cargo.toml +++ b/examples/waaaves/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "waaaves" version = "0.1.0" +publish = false edition = "2024" description = "Multi-pass feedback pipeline — proves engine multi-pass rendering" diff --git a/examples/webapp/Cargo.toml b/examples/webapp/Cargo.toml index af3d0ee5..253a65b8 100644 --- a/examples/webapp/Cargo.toml +++ b/examples/webapp/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "webapp" version = "0.1.0" +publish = false edition = "2024" description = "Delta effect in browser — WASM + WebGPU + React" diff --git a/guide/src/installation.md b/guide/src/installation.md index 5034b42c..4d85c51d 100644 --- a/guide/src/installation.md +++ b/guide/src/installation.md @@ -117,7 +117,7 @@ Add rustjay-engine to `Cargo.toml`: ```toml [dependencies] -rustjay-engine = { git = "https://github.com/BlueJayLouche/rustjay-engine" } +rustjay-engine = "0.1" bytemuck = { version = "1.21", features = ["derive"] } serde = { version = "1.0", features = ["derive"] } anyhow = "1.0" @@ -125,6 +125,16 @@ env_logger = "0.11" log = "0.4" ``` +The engine repo carries two runtime fixes that crates.io builds don't get: `wgpu-hal` +(EGL config selection on Raspberry Pi / Mesa vc4) and `nokhwa-bindings-macos` (USB and +Continuity cameras that crash AVFoundation). If you target either, pull them in: + +```toml +[patch.crates-io] +wgpu-hal = { git = "https://github.com/BlueJayLouche/rustjay-engine" } +nokhwa-bindings-macos = { git = "https://github.com/BlueJayLouche/rustjay-engine" } +``` + Build it once to pull dependencies (this takes a few minutes the first time): ```sh diff --git a/vendor/imgui-wgpu/.cargo_vcs_info.json b/vendor/imgui-wgpu/.cargo_vcs_info.json deleted file mode 100644 index ee682b9a..00000000 --- a/vendor/imgui-wgpu/.cargo_vcs_info.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "git": { - "sha1": "2618a3eccd1bf1d7a372dbec2cfdcda4a2a2e494" - }, - "path_in_vcs": "" -} \ No newline at end of file diff --git a/vendor/imgui-wgpu/Cargo.toml b/vendor/imgui-wgpu/Cargo.toml index df73ae03..d114638d 100644 --- a/vendor/imgui-wgpu/Cargo.toml +++ b/vendor/imgui-wgpu/Cargo.toml @@ -12,7 +12,7 @@ [package] edition = "2021" rust-version = "1.87" -name = "imgui-wgpu" +name = "rustjay-imgui-wgpu" version = "0.28.0" authors = [ "Noah Hüsser ", @@ -30,9 +30,9 @@ autobins = false autoexamples = false autotests = false autobenches = false -description = "A wgpu render backend for imgui-rs." +description = "A wgpu render backend for imgui-rs. Upstream imgui-wgpu 0.28 with its unreleased wgpu 30 support; published for rustjay until upstream cuts a release." homepage = "https://github.com/Yatekii/imgui-wgpu-rs" -documentation = "https://docs.rs/imgui-wgpu/" +documentation = "https://docs.rs/rustjay-imgui-wgpu/" readme = "README.md" keywords = [ "gui", @@ -47,7 +47,7 @@ categories = [ "rendering::graphics-api", ] license = "MIT OR Apache-2.0" -repository = "https://github.com/Yatekii/imgui-wgpu-rs" +repository = "https://github.com/BlueJayLouche/rustjay-engine" [package.metadata.docs.rs] all-features = true @@ -56,22 +56,6 @@ all-features = true name = "imgui_wgpu" path = "src/lib.rs" -[[example]] -name = "cube" -path = "examples/cube.rs" - -[[example]] -name = "custom-texture" -path = "examples/custom-texture.rs" - -[[example]] -name = "empty" -path = "examples/empty.rs" - -[[example]] -name = "hello-world" -path = "examples/hello-world.rs" - [dependencies.bytemuck] version = "1" @@ -86,30 +70,3 @@ version = "1" [dependencies.wgpu] version = "30" - -[dev-dependencies.bytemuck] -version = "1.13" -features = ["derive"] - -[dev-dependencies.cgmath] -version = "0.18" - -[dev-dependencies.env_logger] -version = "0.11" - -[dev-dependencies.image] -version = "0.25" -features = ["png"] -default-features = false - -[dev-dependencies.imgui-winit-support] -version = "0.13" - -[dev-dependencies.pollster] -version = "0.4" - -[dev-dependencies.raw-window-handle] -version = "0.6" - -[dev-dependencies.winit] -version = "0.30" diff --git a/vendor/imgui-wgpu/Cargo.toml.orig b/vendor/imgui-wgpu/Cargo.toml.orig deleted file mode 100644 index 518e7a26..00000000 --- a/vendor/imgui-wgpu/Cargo.toml.orig +++ /dev/null @@ -1,40 +0,0 @@ -[package] -name = "imgui-wgpu" -version = "0.28.0" -authors = [ - "Noah Hüsser ", - "Connor Fitzgerald ", - "Steven Wittens ", -] -edition = "2021" -rust-version = "1.87" -description = "A wgpu render backend for imgui-rs." -documentation = "https://docs.rs/imgui-wgpu/" -homepage = "https://github.com/Yatekii/imgui-wgpu-rs" -repository = "https://github.com/Yatekii/imgui-wgpu-rs" -readme = "README.md" -categories = ["gui", "graphics", "rendering", "rendering::graphics-api"] -keywords = ["gui", "graphics", "wgpu", "imgui"] -license = "MIT OR Apache-2.0" - -exclude = [".gitignore", ".github", "resources"] - -[dependencies] -bytemuck = "1" -imgui = "0.12" -log = "0.4" -smallvec = "1" -wgpu = "29" - -[dev-dependencies] -bytemuck = { version = "1.13", features = ["derive"] } -cgmath = "0.18" -env_logger = "0.11" -image = { version = "0.25", default-features = false, features = ["png"] } -imgui-winit-support = "0.13" -pollster = "0.4" -raw-window-handle = "0.6" -winit = "0.30" - -[package.metadata.docs.rs] -all-features = true diff --git a/vendor/imgui-wgpu/examples/cube.rs b/vendor/imgui-wgpu/examples/cube.rs deleted file mode 100644 index 1de955f4..00000000 --- a/vendor/imgui-wgpu/examples/cube.rs +++ /dev/null @@ -1,736 +0,0 @@ -use bytemuck::{Pod, Zeroable}; -use imgui::*; -use imgui_wgpu::{Renderer, RendererConfig, Texture, TextureConfig}; -use imgui_winit_support::WinitPlatform; -use pollster::block_on; -use std::{sync::Arc, time::Instant}; -use wgpu::{include_wgsl, util::DeviceExt, Extent3d}; -use winit::{ - application::ApplicationHandler, - dpi::LogicalSize, - event::{Event, WindowEvent}, - event_loop::{ActiveEventLoop, ControlFlow, EventLoop}, - keyboard::{Key, NamedKey}, - window::Window, -}; - -const OPENGL_TO_WGPU_MATRIX: cgmath::Matrix4 = cgmath::Matrix4::new( - 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5, 1.0, -); - -// Example code modified from https://github.com/gfx-rs/wgpu-rs/tree/master/examples/cube -#[repr(C)] -#[derive(Clone, Copy, Pod, Zeroable)] -struct Vertex { - _pos: [f32; 4], - _tex_coord: [f32; 2], -} - -fn vertex(pos: [i8; 3], tc: [i8; 2]) -> Vertex { - Vertex { - _pos: [pos[0] as f32, pos[1] as f32, pos[2] as f32, 1.0], - _tex_coord: [tc[0] as f32, tc[1] as f32], - } -} - -fn create_vertices() -> (Vec, Vec) { - let vertex_data = [ - // top (0, 0, 1) - vertex([-1, -1, 1], [0, 0]), - vertex([1, -1, 1], [1, 0]), - vertex([1, 1, 1], [1, 1]), - vertex([-1, 1, 1], [0, 1]), - // bottom (0, 0, -1) - vertex([-1, 1, -1], [1, 0]), - vertex([1, 1, -1], [0, 0]), - vertex([1, -1, -1], [0, 1]), - vertex([-1, -1, -1], [1, 1]), - // right (1, 0, 0) - vertex([1, -1, -1], [0, 0]), - vertex([1, 1, -1], [1, 0]), - vertex([1, 1, 1], [1, 1]), - vertex([1, -1, 1], [0, 1]), - // left (-1, 0, 0) - vertex([-1, -1, 1], [1, 0]), - vertex([-1, 1, 1], [0, 0]), - vertex([-1, 1, -1], [0, 1]), - vertex([-1, -1, -1], [1, 1]), - // front (0, 1, 0) - vertex([1, 1, -1], [1, 0]), - vertex([-1, 1, -1], [0, 0]), - vertex([-1, 1, 1], [0, 1]), - vertex([1, 1, 1], [1, 1]), - // back (0, -1, 0) - vertex([1, -1, 1], [0, 0]), - vertex([-1, -1, 1], [1, 0]), - vertex([-1, -1, -1], [1, 1]), - vertex([1, -1, -1], [0, 1]), - ]; - - let index_data: &[u16] = &[ - 0, 1, 2, 2, 3, 0, // top - 4, 5, 6, 6, 7, 4, // bottom - 8, 9, 10, 10, 11, 8, // right - 12, 13, 14, 14, 15, 12, // left - 16, 17, 18, 18, 19, 16, // front - 20, 21, 22, 22, 23, 20, // back - ]; - - (vertex_data.to_vec(), index_data.to_vec()) -} - -fn create_texels(size: usize) -> Vec { - (0..size * size) - .map(|id| { - // get high five for recognizing this ;) - let cx = 3.0 * (id % size) as f32 / (size - 1) as f32 - 2.0; - let cy = 2.0 * (id / size) as f32 / (size - 1) as f32 - 1.0; - let (mut x, mut y, mut count) = (cx, cy, 0); - while count < 0xFF && x * x + y * y < 4.0 { - let old_x = x; - x = x * x - y * y + cx; - y = 2.0 * old_x * y + cy; - count += 1; - } - count - }) - .collect() -} - -struct Example { - vertex_buf: wgpu::Buffer, - index_buf: wgpu::Buffer, - index_count: usize, - bind_group: wgpu::BindGroup, - uniform_buf: wgpu::Buffer, - pipeline: wgpu::RenderPipeline, - time: f32, -} - -impl Example { - fn generate_matrix(aspect_ratio: f32) -> cgmath::Matrix4 { - let mx_projection = cgmath::perspective(cgmath::Deg(45f32), aspect_ratio, 1.0, 10.0); - let mx_view = cgmath::Matrix4::look_at_rh( - cgmath::Point3::new(1.5f32, -5.0, 3.0), - cgmath::Point3::new(0f32, 0.0, 0.0), - cgmath::Vector3::unit_z(), - ); - let mx_correction = OPENGL_TO_WGPU_MATRIX; - mx_correction * mx_projection * mx_view - } -} - -impl Example { - fn init( - config: &wgpu::SurfaceConfiguration, - device: &wgpu::Device, - queue: &wgpu::Queue, - ) -> Self { - use std::mem; - - // Create the vertex and index buffers - let vertex_size = mem::size_of::(); - let (vertex_data, index_data) = create_vertices(); - - let vertex_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { - label: Some("Vertex Buffer"), - contents: bytemuck::cast_slice(&vertex_data), - usage: wgpu::BufferUsages::VERTEX, - }); - - let index_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { - label: Some("Index Buffer"), - contents: bytemuck::cast_slice(&index_data), - usage: wgpu::BufferUsages::INDEX, - }); - - // Create pipeline layout - let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { - label: None, - entries: &[ - wgpu::BindGroupLayoutEntry { - binding: 0, - visibility: wgpu::ShaderStages::VERTEX, - ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Uniform, - has_dynamic_offset: false, - min_binding_size: wgpu::BufferSize::new(64), - }, - count: None, - }, - wgpu::BindGroupLayoutEntry { - binding: 1, - visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Texture { - multisampled: false, - sample_type: wgpu::TextureSampleType::Uint, - view_dimension: wgpu::TextureViewDimension::D2, - }, - count: None, - }, - ], - }); - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[Some(&bind_group_layout)], - immediate_size: 0, - }); - - // Create the texture - let size = 256u32; - let texels = create_texels(size as usize); - let texture_extent = wgpu::Extent3d { - width: size, - height: size, - depth_or_array_layers: 1, - }; - let texture = device.create_texture(&wgpu::TextureDescriptor { - label: None, - size: texture_extent, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::R8Uint, - usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, - view_formats: &[wgpu::TextureFormat::R8Uint], - }); - let texture_view = texture.create_view(&wgpu::TextureViewDescriptor::default()); - queue.write_texture( - texture.as_image_copy(), - &texels, - wgpu::TexelCopyBufferLayout { - offset: 0, - bytes_per_row: Some(size), - rows_per_image: None, - }, - texture_extent, - ); - - // Create other resources - let mx_total = Self::generate_matrix(config.width as f32 / config.height as f32); - let mx_ref: &[f32; 16] = mx_total.as_ref(); - let uniform_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { - label: Some("Uniform Buffer"), - contents: bytemuck::cast_slice(mx_ref), - usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, - }); - - // Create bind group - let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { - layout: &bind_group_layout, - entries: &[ - wgpu::BindGroupEntry { - binding: 0, - resource: uniform_buf.as_entire_binding(), - }, - wgpu::BindGroupEntry { - binding: 1, - resource: wgpu::BindingResource::TextureView(&texture_view), - }, - ], - label: None, - }); - - let shader = device.create_shader_module(include_wgsl!("../resources/cube.wgsl")); - - let vertex_buffers = [wgpu::VertexBufferLayout { - array_stride: vertex_size as wgpu::BufferAddress, - step_mode: wgpu::VertexStepMode::Vertex, - attributes: &[ - wgpu::VertexAttribute { - format: wgpu::VertexFormat::Float32x4, - offset: 0, - shader_location: 0, - }, - wgpu::VertexAttribute { - format: wgpu::VertexFormat::Float32x2, - offset: 4 * 4, - shader_location: 1, - }, - ], - }]; - - let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { - label: None, - layout: Some(&pipeline_layout), - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &vertex_buffers, - }, - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some(config.format.into())], - }), - primitive: wgpu::PrimitiveState { - cull_mode: Some(wgpu::Face::Back), - ..Default::default() - }, - depth_stencil: None, - multisample: wgpu::MultisampleState::default(), - multiview_mask: None, - cache: None, - }); - - // Done - Example { - vertex_buf, - index_buf, - index_count: index_data.len(), - bind_group, - uniform_buf, - pipeline, - time: 0.0, - } - } - - fn update(&mut self, delta_time: f32) { - self.time += delta_time; - } - - fn setup_camera(&mut self, queue: &wgpu::Queue, size: [f32; 2]) { - let mx_total = Self::generate_matrix(size[0] / size[1]); - let mx_ref: &[f32; 16] = mx_total.as_ref(); - queue.write_buffer(&self.uniform_buf, 0, bytemuck::cast_slice(mx_ref)); - } - - fn render(&mut self, view: &wgpu::TextureView, device: &wgpu::Device, queue: &wgpu::Queue) { - let mut encoder = - device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); - { - let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: None, - color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Clear(wgpu::Color { - r: 0.1, - g: 0.2, - b: 0.3, - a: 1.0, - }), - store: wgpu::StoreOp::Store, - }, - depth_slice: None, - })], - depth_stencil_attachment: None, - timestamp_writes: None, - occlusion_query_set: None, - multiview_mask: None, - }); - rpass.push_debug_group("Prepare data for draw."); - rpass.set_pipeline(&self.pipeline); - rpass.set_bind_group(0, &self.bind_group, &[]); - rpass.set_index_buffer(self.index_buf.slice(..), wgpu::IndexFormat::Uint16); - rpass.set_vertex_buffer(0, self.vertex_buf.slice(..)); - rpass.pop_debug_group(); - rpass.insert_debug_marker("Draw!"); - rpass.draw_indexed(0..self.index_count as u32, 0, 0..1); - } - - queue.submit(Some(encoder.finish())); - } -} - -struct ImguiState { - context: imgui::Context, - platform: WinitPlatform, - renderer: Renderer, - example: Example, - example_size: [f32; 2], - example_texture_id: TextureId, - last_frame: Instant, - last_cursor: Option, -} - -struct AppWindow { - device: wgpu::Device, - queue: wgpu::Queue, - window: Arc, - surface_desc: wgpu::SurfaceConfiguration, - surface: wgpu::Surface<'static>, - hidpi_factor: f64, - imgui: Option, -} - -#[derive(Default)] -struct App { - window: Option, -} - -impl AppWindow { - fn setup_gpu(event_loop: &ActiveEventLoop) -> Self { - let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - backends: wgpu::Backends::PRIMARY, - ..wgpu::InstanceDescriptor::new_with_display_handle(Box::new( - event_loop.owned_display_handle(), - )) - }); - - let window = { - let version = env!("CARGO_PKG_VERSION"); - - let size = LogicalSize::new(1280.0, 720.0); - - let attributes = Window::default_attributes() - .with_inner_size(size) - .with_title(format!("imgui-wgpu {version}")); - Arc::new(event_loop.create_window(attributes).unwrap()) - }; - - let size = window.inner_size(); - let hidpi_factor = window.scale_factor(); - let surface = instance.create_surface(window.clone()).unwrap(); - - let adapter = block_on(instance.request_adapter(&wgpu::RequestAdapterOptions { - power_preference: wgpu::PowerPreference::HighPerformance, - compatible_surface: Some(&surface), - force_fallback_adapter: false, - })) - .unwrap(); - - let (device, queue) = - block_on(adapter.request_device(&wgpu::DeviceDescriptor::default())).unwrap(); - - // Set up swap chain - let surface_desc = wgpu::SurfaceConfiguration { - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - format: wgpu::TextureFormat::Bgra8UnormSrgb, - width: size.width, - height: size.height, - present_mode: wgpu::PresentMode::Fifo, - desired_maximum_frame_latency: 2, - alpha_mode: wgpu::CompositeAlphaMode::Auto, - view_formats: vec![wgpu::TextureFormat::Bgra8Unorm], - }; - - surface.configure(&device, &surface_desc); - - let imgui = None; - Self { - device, - queue, - window, - surface_desc, - surface, - hidpi_factor, - imgui, - } - } - - fn setup_imgui(&mut self) { - let mut context = imgui::Context::create(); - let mut platform = imgui_winit_support::WinitPlatform::new(&mut context); - platform.attach_window( - context.io_mut(), - &self.window, - imgui_winit_support::HiDpiMode::Default, - ); - context.set_ini_filename(None); - - let font_size = (13.0 * self.hidpi_factor) as f32; - context.io_mut().font_global_scale = (1.0 / self.hidpi_factor) as f32; - - context.fonts().add_font(&[FontSource::DefaultFontData { - config: Some(imgui::FontConfig { - size_pixels: font_size, - ..Default::default() - }), - }]); - - // - // Set up dear imgui wgpu renderer - // - // let clear_color = wgpu::Color { - // r: 0.1, - // g: 0.2, - // b: 0.3, - // a: 1.0, - // }; - - let renderer_config = RendererConfig { - texture_format: self.surface_desc.format, - ..Default::default() - }; - - let mut renderer = Renderer::new(&mut context, &self.device, &self.queue, renderer_config); - - let last_frame = Instant::now(); - let last_cursor = None; - let example_size: [f32; 2] = [640.0, 480.0]; - let example = Example::init(&self.surface_desc, &self.device, &self.queue); - - // Stores a texture for displaying with imgui::Image(), - // also as a texture view for rendering into it - let texture_config = TextureConfig { - size: wgpu::Extent3d { - width: example_size[0] as u32, - height: example_size[1] as u32, - ..Default::default() - }, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING, - ..Default::default() - }; - - let texture = Texture::new(&self.device, &renderer, texture_config); - let example_texture_id = renderer.textures.insert(texture); - - self.imgui = Some(ImguiState { - context, - platform, - renderer, - example, - example_size, - example_texture_id, - last_frame, - last_cursor, - }) - } - - fn new(event_loop: &ActiveEventLoop) -> Self { - let mut window = Self::setup_gpu(event_loop); - window.setup_imgui(); - window - } -} - -impl ApplicationHandler for App { - fn resumed(&mut self, event_loop: &ActiveEventLoop) { - self.window = Some(AppWindow::new(event_loop)); - } - - fn window_event( - &mut self, - event_loop: &ActiveEventLoop, - window_id: winit::window::WindowId, - event: WindowEvent, - ) { - let window = self.window.as_mut().unwrap(); - let imgui = window.imgui.as_mut().unwrap(); - - match &event { - WindowEvent::Resized(size) => { - window.surface_desc.width = size.width; - window.surface_desc.height = size.height; - window - .surface - .configure(&window.device, &window.surface_desc); - } - WindowEvent::ScaleFactorChanged { scale_factor, .. } => { - window.hidpi_factor = *scale_factor; - let font_size = (13.0 * window.hidpi_factor) as f32; - imgui.context.fonts().clear(); - imgui - .context - .fonts() - .add_font(&[FontSource::DefaultFontData { - config: Some(imgui::FontConfig { - oversample_h: 1, - pixel_snap_h: true, - size_pixels: font_size, - ..Default::default() - }), - }]); - imgui.renderer.reload_font_texture( - &mut imgui.context, - &window.device, - &window.queue, - ); - } - WindowEvent::CloseRequested => event_loop.exit(), - WindowEvent::KeyboardInput { event, .. } => { - if let Key::Named(NamedKey::Escape) = event.logical_key { - if event.state.is_pressed() { - event_loop.exit(); - } - } - } - WindowEvent::RedrawRequested => { - let now = Instant::now(); - imgui - .context - .io_mut() - .update_delta_time(now - imgui.last_frame); - imgui.last_frame = now; - - let frame = match window.surface.get_current_texture() { - wgpu::CurrentSurfaceTexture::Success(frame) => frame, - // Suboptimal is fine to render with — likely an - // upcoming resize will reconfigure the surface. - wgpu::CurrentSurfaceTexture::Suboptimal(frame) => frame, - wgpu::CurrentSurfaceTexture::Timeout - | wgpu::CurrentSurfaceTexture::Occluded => return, - wgpu::CurrentSurfaceTexture::Outdated | wgpu::CurrentSurfaceTexture::Lost => { - window - .surface - .configure(&window.device, &window.surface_desc); - return; - } - other => { - eprintln!("get_current_texture error: {other:?}"); - return; - } - }; - imgui - .platform - .prepare_frame(imgui.context.io_mut(), &window.window) - .expect("Failed to prepare frame"); - let ui = imgui.context.frame(); - - let view = frame - .texture - .create_view(&wgpu::TextureViewDescriptor::default()); - - // Render example normally at background - imgui.example.update(ui.io().delta_time); - imgui - .example - .setup_camera(&window.queue, ui.io().display_size); - imgui.example.render(&view, &window.device, &window.queue); - - // Store the new size of Image() or None to indicate that the window is collapsed. - let mut new_example_size: Option<[f32; 2]> = None; - - ui.window("Cube") - .size([512.0, 512.0], Condition::FirstUseEver) - .build(|| { - new_example_size = Some(ui.content_region_avail()); - imgui::Image::new(imgui.example_texture_id, new_example_size.unwrap()) - .build(ui); - }); - - if let Some(size) = new_example_size { - // Resize render target, which is optional - if size != imgui.example_size && size[0] >= 1.0 && size[1] >= 1.0 { - imgui.example_size = size; - let scale = &ui.io().display_framebuffer_scale; - let texture_config = TextureConfig { - size: Extent3d { - width: (imgui.example_size[0] * scale[0]) as u32, - height: (imgui.example_size[1] * scale[1]) as u32, - ..Default::default() - }, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT - | wgpu::TextureUsages::TEXTURE_BINDING, - ..Default::default() - }; - imgui.renderer.textures.replace( - imgui.example_texture_id, - Texture::new(&window.device, &imgui.renderer, texture_config), - ); - } - - // Only render example to example_texture if the window is not collapsed - imgui.example.setup_camera(&window.queue, size); - imgui.example.render( - imgui - .renderer - .textures - .get(imgui.example_texture_id) - .unwrap() - .view(), - &window.device, - &window.queue, - ); - } - - let mut encoder: wgpu::CommandEncoder = window - .device - .create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); - - if imgui.last_cursor != ui.mouse_cursor() { - imgui.last_cursor = ui.mouse_cursor(); - imgui.platform.prepare_render(ui, &window.window); - } - - let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: None, - color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view: &view, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Load, // Do not clear - // load: wgpu::LoadOp::Clear(clear_color), - store: wgpu::StoreOp::Store, - }, - depth_slice: None, - })], - depth_stencil_attachment: None, - timestamp_writes: None, - occlusion_query_set: None, - multiview_mask: None, - }); - - imgui - .renderer - .render( - imgui.context.render(), - &window.queue, - &window.device, - &mut rpass, - ) - .expect("Rendering failed"); - - drop(rpass); - - window.queue.submit(Some(encoder.finish())); - frame.present(); - } - _ => (), - } - - imgui.platform.handle_event::<()>( - imgui.context.io_mut(), - &window.window, - &Event::WindowEvent { window_id, event }, - ); - } - - fn user_event(&mut self, _event_loop: &ActiveEventLoop, event: ()) { - let window = self.window.as_mut().unwrap(); - let imgui = window.imgui.as_mut().unwrap(); - imgui.platform.handle_event::<()>( - imgui.context.io_mut(), - &window.window, - &Event::UserEvent(event), - ); - } - - fn device_event( - &mut self, - _event_loop: &ActiveEventLoop, - device_id: winit::event::DeviceId, - event: winit::event::DeviceEvent, - ) { - let window = self.window.as_mut().unwrap(); - let imgui = window.imgui.as_mut().unwrap(); - imgui.platform.handle_event::<()>( - imgui.context.io_mut(), - &window.window, - &Event::DeviceEvent { device_id, event }, - ); - } - - fn about_to_wait(&mut self, _event_loop: &ActiveEventLoop) { - let window = self.window.as_mut().unwrap(); - let imgui = window.imgui.as_mut().unwrap(); - window.window.request_redraw(); - imgui.platform.handle_event::<()>( - imgui.context.io_mut(), - &window.window, - &Event::AboutToWait, - ); - } -} - -fn main() { - env_logger::init(); - - let event_loop = EventLoop::new().unwrap(); - event_loop.set_control_flow(ControlFlow::Poll); - event_loop.run_app(&mut App::default()).unwrap(); -} diff --git a/vendor/imgui-wgpu/examples/custom-texture.rs b/vendor/imgui-wgpu/examples/custom-texture.rs deleted file mode 100644 index 6dae926f..00000000 --- a/vendor/imgui-wgpu/examples/custom-texture.rs +++ /dev/null @@ -1,379 +0,0 @@ -use image::ImageFormat; -use imgui::*; -use imgui_wgpu::{Renderer, RendererConfig, Texture, TextureConfig}; -use imgui_winit_support::WinitPlatform; -use pollster::block_on; -use std::{sync::Arc, time::Instant}; -use wgpu::Extent3d; -use winit::{ - application::ApplicationHandler, - dpi::LogicalSize, - event::{Event, WindowEvent}, - event_loop::{ActiveEventLoop, ControlFlow, EventLoop}, - keyboard::{Key, NamedKey}, - window::Window, -}; - -struct ImguiState { - context: imgui::Context, - platform: WinitPlatform, - renderer: Renderer, - clear_color: wgpu::Color, - width: u32, - height: u32, - checker_texture_id: TextureId, - last_frame: Instant, - last_cursor: Option, -} - -struct AppWindow { - device: wgpu::Device, - queue: wgpu::Queue, - window: Arc, - surface_desc: wgpu::SurfaceConfiguration, - surface: wgpu::Surface<'static>, - hidpi_factor: f64, - imgui: Option, -} - -#[derive(Default)] -struct App { - window: Option, -} - -impl AppWindow { - fn setup_gpu(event_loop: &ActiveEventLoop) -> Self { - let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - backends: wgpu::Backends::PRIMARY, - ..wgpu::InstanceDescriptor::new_with_display_handle(Box::new( - event_loop.owned_display_handle(), - )) - }); - - let window = { - let version = env!("CARGO_PKG_VERSION"); - - let size = LogicalSize::new(1280.0, 720.0); - - let attributes = Window::default_attributes() - .with_inner_size(size) - .with_title(format!("imgui-wgpu {version}")); - Arc::new(event_loop.create_window(attributes).unwrap()) - }; - - let size = window.inner_size(); - let hidpi_factor = window.scale_factor(); - let surface = instance.create_surface(window.clone()).unwrap(); - - let adapter = block_on(instance.request_adapter(&wgpu::RequestAdapterOptions { - power_preference: wgpu::PowerPreference::HighPerformance, - compatible_surface: Some(&surface), - force_fallback_adapter: false, - })) - .unwrap(); - - let (device, queue) = - block_on(adapter.request_device(&wgpu::DeviceDescriptor::default())).unwrap(); - - // Set up swap chain - let surface_desc = wgpu::SurfaceConfiguration { - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - format: wgpu::TextureFormat::Bgra8UnormSrgb, - width: size.width, - height: size.height, - present_mode: wgpu::PresentMode::Fifo, - desired_maximum_frame_latency: 2, - alpha_mode: wgpu::CompositeAlphaMode::Auto, - view_formats: vec![wgpu::TextureFormat::Bgra8Unorm], - }; - - surface.configure(&device, &surface_desc); - - let imgui = None; - Self { - device, - queue, - window, - surface_desc, - surface, - hidpi_factor, - imgui, - } - } - - fn setup_imgui(&mut self) { - let mut context = imgui::Context::create(); - let mut platform = imgui_winit_support::WinitPlatform::new(&mut context); - platform.attach_window( - context.io_mut(), - &self.window, - imgui_winit_support::HiDpiMode::Default, - ); - context.set_ini_filename(None); - - let font_size = (13.0 * self.hidpi_factor) as f32; - context.io_mut().font_global_scale = (1.0 / self.hidpi_factor) as f32; - - context.fonts().add_font(&[FontSource::DefaultFontData { - config: Some(imgui::FontConfig { - size_pixels: font_size, - ..Default::default() - }), - }]); - - // - // Set up dear imgui wgpu renderer - // - let clear_color = wgpu::Color { - r: 0.1, - g: 0.2, - b: 0.3, - a: 1.0, - }; - - let renderer_config = RendererConfig { - texture_format: self.surface_desc.format, - ..Default::default() - }; - - let mut renderer = Renderer::new(&mut context, &self.device, &self.queue, renderer_config); - - let last_frame = Instant::now(); - let last_cursor = None; - - let checker_bytes = include_bytes!("../resources/checker.png"); - let image = image::load_from_memory_with_format(checker_bytes, ImageFormat::Png) - .expect("invalid image"); - let image = image.to_rgba8(); - let (width, height) = image.dimensions(); - let raw_data = image.into_raw(); - - let texture_config = TextureConfig { - size: Extent3d { - width, - height, - ..Default::default() - }, - label: Some("checker texture"), - format: Some(wgpu::TextureFormat::Rgba8Unorm), - ..Default::default() - }; - - let texture = Texture::new(&self.device, &renderer, texture_config); - - texture.write(&self.queue, &raw_data, width, height); - let checker_texture_id = renderer.textures.insert(texture); - - self.imgui = Some(ImguiState { - context, - platform, - renderer, - clear_color, - width, - height, - checker_texture_id, - last_frame, - last_cursor, - }) - } - - fn new(event_loop: &ActiveEventLoop) -> Self { - let mut window = Self::setup_gpu(event_loop); - window.setup_imgui(); - window - } -} - -impl ApplicationHandler for App { - fn resumed(&mut self, event_loop: &ActiveEventLoop) { - self.window = Some(AppWindow::new(event_loop)); - } - - fn window_event( - &mut self, - event_loop: &ActiveEventLoop, - window_id: winit::window::WindowId, - event: WindowEvent, - ) { - let window = self.window.as_mut().unwrap(); - let imgui = window.imgui.as_mut().unwrap(); - - match &event { - WindowEvent::Resized(size) => { - window.surface_desc.width = size.width; - window.surface_desc.height = size.height; - window - .surface - .configure(&window.device, &window.surface_desc); - } - WindowEvent::ScaleFactorChanged { scale_factor, .. } => { - window.hidpi_factor = *scale_factor; - let font_size = (13.0 * window.hidpi_factor) as f32; - imgui.context.fonts().clear(); - imgui - .context - .fonts() - .add_font(&[FontSource::DefaultFontData { - config: Some(imgui::FontConfig { - oversample_h: 1, - pixel_snap_h: true, - size_pixels: font_size, - ..Default::default() - }), - }]); - imgui.renderer.reload_font_texture( - &mut imgui.context, - &window.device, - &window.queue, - ); - } - WindowEvent::CloseRequested => event_loop.exit(), - WindowEvent::KeyboardInput { event, .. } => { - if let Key::Named(NamedKey::Escape) = event.logical_key { - if event.state.is_pressed() { - event_loop.exit(); - } - } - } - WindowEvent::RedrawRequested => { - let now = Instant::now(); - imgui - .context - .io_mut() - .update_delta_time(now - imgui.last_frame); - imgui.last_frame = now; - - let frame = match window.surface.get_current_texture() { - wgpu::CurrentSurfaceTexture::Success(frame) => frame, - // Suboptimal is fine to render with — likely an - // upcoming resize will reconfigure the surface. - wgpu::CurrentSurfaceTexture::Suboptimal(frame) => frame, - wgpu::CurrentSurfaceTexture::Timeout - | wgpu::CurrentSurfaceTexture::Occluded => return, - wgpu::CurrentSurfaceTexture::Outdated | wgpu::CurrentSurfaceTexture::Lost => { - window - .surface - .configure(&window.device, &window.surface_desc); - return; - } - other => { - eprintln!("get_current_texture error: {other:?}"); - return; - } - }; - imgui - .platform - .prepare_frame(imgui.context.io_mut(), &window.window) - .expect("Failed to prepare frame"); - let ui = imgui.context.frame(); - - { - let size = [imgui.width as f32, imgui.height as f32]; - let window = ui.window("Hello world"); - window - .size([400.0, 600.0], Condition::FirstUseEver) - .build(|| { - ui.text("Hello textures!"); - ui.text("Say hello to checker.png"); - Image::new(imgui.checker_texture_id, size).build(ui); - }); - } - - let mut encoder: wgpu::CommandEncoder = window - .device - .create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); - - if imgui.last_cursor != ui.mouse_cursor() { - imgui.last_cursor = ui.mouse_cursor(); - imgui.platform.prepare_render(ui, &window.window); - } - - let view = frame - .texture - .create_view(&wgpu::TextureViewDescriptor::default()); - let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: None, - color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view: &view, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Clear(imgui.clear_color), - store: wgpu::StoreOp::Store, - }, - depth_slice: None, - })], - depth_stencil_attachment: None, - timestamp_writes: None, - occlusion_query_set: None, - multiview_mask: None, - }); - - imgui - .renderer - .render( - imgui.context.render(), - &window.queue, - &window.device, - &mut rpass, - ) - .expect("Rendering failed"); - - drop(rpass); - - window.queue.submit(Some(encoder.finish())); - frame.present(); - } - _ => (), - } - - imgui.platform.handle_event::<()>( - imgui.context.io_mut(), - &window.window, - &Event::WindowEvent { window_id, event }, - ); - } - - fn user_event(&mut self, _event_loop: &ActiveEventLoop, event: ()) { - let window = self.window.as_mut().unwrap(); - let imgui = window.imgui.as_mut().unwrap(); - imgui.platform.handle_event::<()>( - imgui.context.io_mut(), - &window.window, - &Event::UserEvent(event), - ); - } - - fn device_event( - &mut self, - _event_loop: &ActiveEventLoop, - device_id: winit::event::DeviceId, - event: winit::event::DeviceEvent, - ) { - let window = self.window.as_mut().unwrap(); - let imgui = window.imgui.as_mut().unwrap(); - imgui.platform.handle_event::<()>( - imgui.context.io_mut(), - &window.window, - &Event::DeviceEvent { device_id, event }, - ); - } - - fn about_to_wait(&mut self, _event_loop: &ActiveEventLoop) { - let window = self.window.as_mut().unwrap(); - let imgui = window.imgui.as_mut().unwrap(); - window.window.request_redraw(); - imgui.platform.handle_event::<()>( - imgui.context.io_mut(), - &window.window, - &Event::AboutToWait, - ); - } -} - -fn main() { - env_logger::init(); - - let event_loop = EventLoop::new().unwrap(); - event_loop.set_control_flow(ControlFlow::Poll); - event_loop.run_app(&mut App::default()).unwrap(); -} diff --git a/vendor/imgui-wgpu/examples/empty.rs b/vendor/imgui-wgpu/examples/empty.rs deleted file mode 100644 index d2e17a4b..00000000 --- a/vendor/imgui-wgpu/examples/empty.rs +++ /dev/null @@ -1,339 +0,0 @@ -use imgui::*; -use imgui_wgpu::{Renderer, RendererConfig}; -use imgui_winit_support::WinitPlatform; -use pollster::block_on; -use std::{sync::Arc, time::Instant}; -use winit::{ - application::ApplicationHandler, - dpi::LogicalSize, - event::{Event, WindowEvent}, - event_loop::{ActiveEventLoop, ControlFlow, EventLoop}, - keyboard::{Key, NamedKey}, - window::Window, -}; - -struct ImguiState { - context: imgui::Context, - platform: WinitPlatform, - renderer: Renderer, - clear_color: wgpu::Color, - last_frame: Instant, - last_cursor: Option, -} - -struct AppWindow { - device: wgpu::Device, - queue: wgpu::Queue, - window: Arc, - surface_desc: wgpu::SurfaceConfiguration, - surface: wgpu::Surface<'static>, - hidpi_factor: f64, - imgui: Option, -} - -#[derive(Default)] -struct App { - window: Option, -} - -impl AppWindow { - fn setup_gpu(event_loop: &ActiveEventLoop) -> Self { - let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - backends: wgpu::Backends::PRIMARY, - ..wgpu::InstanceDescriptor::new_with_display_handle(Box::new( - event_loop.owned_display_handle(), - )) - }); - - let window = { - let version = env!("CARGO_PKG_VERSION"); - - let size = LogicalSize::new(1280.0, 720.0); - - let attributes = Window::default_attributes() - .with_inner_size(size) - .with_title(format!("imgui-wgpu {version}")); - Arc::new(event_loop.create_window(attributes).unwrap()) - }; - - let size = window.inner_size(); - let hidpi_factor = window.scale_factor(); - let surface = instance.create_surface(window.clone()).unwrap(); - - let adapter = block_on(instance.request_adapter(&wgpu::RequestAdapterOptions { - power_preference: wgpu::PowerPreference::HighPerformance, - compatible_surface: Some(&surface), - force_fallback_adapter: false, - })) - .unwrap(); - - let (device, queue) = - block_on(adapter.request_device(&wgpu::DeviceDescriptor::default())).unwrap(); - - // Set up swap chain - let surface_desc = wgpu::SurfaceConfiguration { - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - format: wgpu::TextureFormat::Bgra8UnormSrgb, - width: size.width, - height: size.height, - present_mode: wgpu::PresentMode::Fifo, - desired_maximum_frame_latency: 2, - alpha_mode: wgpu::CompositeAlphaMode::Auto, - view_formats: vec![wgpu::TextureFormat::Bgra8Unorm], - }; - - surface.configure(&device, &surface_desc); - - let imgui = None; - Self { - device, - queue, - window, - surface_desc, - surface, - hidpi_factor, - imgui, - } - } - - fn setup_imgui(&mut self) { - let mut context = imgui::Context::create(); - let mut platform = imgui_winit_support::WinitPlatform::new(&mut context); - platform.attach_window( - context.io_mut(), - &self.window, - imgui_winit_support::HiDpiMode::Default, - ); - context.set_ini_filename(None); - - let font_size = (13.0 * self.hidpi_factor) as f32; - context.io_mut().font_global_scale = (1.0 / self.hidpi_factor) as f32; - - context.fonts().add_font(&[FontSource::DefaultFontData { - config: Some(imgui::FontConfig { - size_pixels: font_size, - ..Default::default() - }), - }]); - - // - // Set up dear imgui wgpu renderer - // - let clear_color = wgpu::Color { - r: 0.1, - g: 0.2, - b: 0.3, - a: 1.0, - }; - - let renderer_config = RendererConfig { - texture_format: self.surface_desc.format, - ..Default::default() - }; - - let renderer = Renderer::new(&mut context, &self.device, &self.queue, renderer_config); - let last_frame = Instant::now(); - let last_cursor = None; - - self.imgui = Some(ImguiState { - context, - platform, - renderer, - clear_color, - last_frame, - last_cursor, - }) - } - - fn new(event_loop: &ActiveEventLoop) -> Self { - let mut window = Self::setup_gpu(event_loop); - window.setup_imgui(); - window - } -} - -impl ApplicationHandler for App { - fn resumed(&mut self, event_loop: &ActiveEventLoop) { - self.window = Some(AppWindow::new(event_loop)); - } - - fn window_event( - &mut self, - event_loop: &ActiveEventLoop, - window_id: winit::window::WindowId, - event: WindowEvent, - ) { - let window = self.window.as_mut().unwrap(); - let imgui = window.imgui.as_mut().unwrap(); - - match &event { - WindowEvent::Resized(size) => { - window.surface_desc.width = size.width; - window.surface_desc.height = size.height; - window - .surface - .configure(&window.device, &window.surface_desc); - } - WindowEvent::ScaleFactorChanged { scale_factor, .. } => { - window.hidpi_factor = *scale_factor; - let font_size = (13.0 * window.hidpi_factor) as f32; - imgui.context.fonts().clear(); - imgui - .context - .fonts() - .add_font(&[FontSource::DefaultFontData { - config: Some(imgui::FontConfig { - oversample_h: 1, - pixel_snap_h: true, - size_pixels: font_size, - ..Default::default() - }), - }]); - imgui.renderer.reload_font_texture( - &mut imgui.context, - &window.device, - &window.queue, - ); - } - WindowEvent::CloseRequested => event_loop.exit(), - WindowEvent::KeyboardInput { event, .. } => { - if let Key::Named(NamedKey::Escape) = event.logical_key { - if event.state.is_pressed() { - event_loop.exit(); - } - } - } - WindowEvent::RedrawRequested => { - let now = Instant::now(); - imgui - .context - .io_mut() - .update_delta_time(now - imgui.last_frame); - imgui.last_frame = now; - - let frame = match window.surface.get_current_texture() { - wgpu::CurrentSurfaceTexture::Success(frame) => frame, - // Suboptimal is fine to render with — likely an - // upcoming resize will reconfigure the surface. - wgpu::CurrentSurfaceTexture::Suboptimal(frame) => frame, - wgpu::CurrentSurfaceTexture::Timeout - | wgpu::CurrentSurfaceTexture::Occluded => return, - wgpu::CurrentSurfaceTexture::Outdated | wgpu::CurrentSurfaceTexture::Lost => { - window - .surface - .configure(&window.device, &window.surface_desc); - return; - } - other => { - eprintln!("get_current_texture error: {other:?}"); - return; - } - }; - imgui - .platform - .prepare_frame(imgui.context.io_mut(), &window.window) - .expect("Failed to prepare frame"); - let ui = imgui.context.frame(); - - // Deliberately do not submit anything such that the draw buffer is empty. - // The renderer should cope gracefully with this. - - let mut encoder: wgpu::CommandEncoder = window - .device - .create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); - - if imgui.last_cursor != ui.mouse_cursor() { - imgui.last_cursor = ui.mouse_cursor(); - imgui.platform.prepare_render(ui, &window.window); - } - - let view = frame - .texture - .create_view(&wgpu::TextureViewDescriptor::default()); - let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: None, - color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view: &view, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Clear(imgui.clear_color), - store: wgpu::StoreOp::Store, - }, - depth_slice: None, - })], - depth_stencil_attachment: None, - timestamp_writes: None, - occlusion_query_set: None, - multiview_mask: None, - }); - - imgui - .renderer - .render( - imgui.context.render(), - &window.queue, - &window.device, - &mut rpass, - ) - .expect("Rendering failed"); - - drop(rpass); - - window.queue.submit(Some(encoder.finish())); - - frame.present(); - } - _ => (), - } - - imgui.platform.handle_event::<()>( - imgui.context.io_mut(), - &window.window, - &Event::WindowEvent { window_id, event }, - ); - } - - fn user_event(&mut self, _event_loop: &ActiveEventLoop, event: ()) { - let window = self.window.as_mut().unwrap(); - let imgui = window.imgui.as_mut().unwrap(); - imgui.platform.handle_event::<()>( - imgui.context.io_mut(), - &window.window, - &Event::UserEvent(event), - ); - } - - fn device_event( - &mut self, - _event_loop: &ActiveEventLoop, - device_id: winit::event::DeviceId, - event: winit::event::DeviceEvent, - ) { - let window = self.window.as_mut().unwrap(); - let imgui = window.imgui.as_mut().unwrap(); - imgui.platform.handle_event::<()>( - imgui.context.io_mut(), - &window.window, - &Event::DeviceEvent { device_id, event }, - ); - } - - fn about_to_wait(&mut self, _event_loop: &ActiveEventLoop) { - let window = self.window.as_mut().unwrap(); - let imgui = window.imgui.as_mut().unwrap(); - window.window.request_redraw(); - imgui.platform.handle_event::<()>( - imgui.context.io_mut(), - &window.window, - &Event::AboutToWait, - ); - } -} - -fn main() { - env_logger::init(); - - let event_loop = EventLoop::new().unwrap(); - event_loop.set_control_flow(ControlFlow::Poll); - event_loop.run_app(&mut App::default()).unwrap(); -} diff --git a/vendor/imgui-wgpu/examples/hello-world.rs b/vendor/imgui-wgpu/examples/hello-world.rs deleted file mode 100644 index ce2f17ac..00000000 --- a/vendor/imgui-wgpu/examples/hello-world.rs +++ /dev/null @@ -1,366 +0,0 @@ -use imgui::*; -use imgui_wgpu::{Renderer, RendererConfig}; -use imgui_winit_support::WinitPlatform; -use pollster::block_on; -use std::{sync::Arc, time::Instant}; -use winit::{ - application::ApplicationHandler, - dpi::LogicalSize, - event::{Event, WindowEvent}, - event_loop::{ActiveEventLoop, ControlFlow, EventLoop}, - keyboard::{Key, NamedKey}, - window::Window, -}; - -struct ImguiState { - context: imgui::Context, - platform: WinitPlatform, - renderer: Renderer, - clear_color: wgpu::Color, - demo_open: bool, - last_frame: Instant, - last_cursor: Option, -} - -struct AppWindow { - device: wgpu::Device, - queue: wgpu::Queue, - window: Arc, - surface_desc: wgpu::SurfaceConfiguration, - surface: wgpu::Surface<'static>, - hidpi_factor: f64, - imgui: Option, -} - -#[derive(Default)] -struct App { - window: Option, -} - -impl AppWindow { - fn setup_gpu(event_loop: &ActiveEventLoop) -> Self { - let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - backends: wgpu::Backends::PRIMARY, - ..wgpu::InstanceDescriptor::new_with_display_handle(Box::new( - event_loop.owned_display_handle(), - )) - }); - - let window = { - let version = env!("CARGO_PKG_VERSION"); - - let size = LogicalSize::new(1280.0, 720.0); - - let attributes = Window::default_attributes() - .with_inner_size(size) - .with_title(format!("imgui-wgpu {version}")); - Arc::new(event_loop.create_window(attributes).unwrap()) - }; - - let size = window.inner_size(); - let hidpi_factor = window.scale_factor(); - let surface = instance.create_surface(window.clone()).unwrap(); - - let adapter = block_on(instance.request_adapter(&wgpu::RequestAdapterOptions { - power_preference: wgpu::PowerPreference::HighPerformance, - compatible_surface: Some(&surface), - force_fallback_adapter: false, - })) - .unwrap(); - - let (device, queue) = - block_on(adapter.request_device(&wgpu::DeviceDescriptor::default())).unwrap(); - - // Set up swap chain - let surface_desc = wgpu::SurfaceConfiguration { - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - format: wgpu::TextureFormat::Bgra8UnormSrgb, - width: size.width, - height: size.height, - present_mode: wgpu::PresentMode::Fifo, - desired_maximum_frame_latency: 2, - alpha_mode: wgpu::CompositeAlphaMode::Auto, - view_formats: vec![wgpu::TextureFormat::Bgra8Unorm], - }; - - surface.configure(&device, &surface_desc); - - let imgui = None; - Self { - device, - queue, - window, - surface_desc, - surface, - hidpi_factor, - imgui, - } - } - - fn setup_imgui(&mut self) { - let mut context = imgui::Context::create(); - let mut platform = imgui_winit_support::WinitPlatform::new(&mut context); - platform.attach_window( - context.io_mut(), - &self.window, - imgui_winit_support::HiDpiMode::Default, - ); - context.set_ini_filename(None); - - let font_size = (13.0 * self.hidpi_factor) as f32; - context.io_mut().font_global_scale = (1.0 / self.hidpi_factor) as f32; - - context.fonts().add_font(&[FontSource::DefaultFontData { - config: Some(imgui::FontConfig { - size_pixels: font_size, - ..Default::default() - }), - }]); - - // - // Set up dear imgui wgpu renderer - // - let clear_color = wgpu::Color { - r: 0.1, - g: 0.2, - b: 0.3, - a: 1.0, - }; - - let renderer_config = RendererConfig { - texture_format: self.surface_desc.format, - ..Default::default() - }; - - let renderer = Renderer::new(&mut context, &self.device, &self.queue, renderer_config); - let last_frame = Instant::now(); - let last_cursor = None; - let demo_open = true; - - self.imgui = Some(ImguiState { - context, - platform, - renderer, - clear_color, - demo_open, - last_frame, - last_cursor, - }) - } - - fn new(event_loop: &ActiveEventLoop) -> Self { - let mut window = Self::setup_gpu(event_loop); - window.setup_imgui(); - window - } -} - -impl ApplicationHandler for App { - fn resumed(&mut self, event_loop: &ActiveEventLoop) { - self.window = Some(AppWindow::new(event_loop)); - } - - fn window_event( - &mut self, - event_loop: &ActiveEventLoop, - window_id: winit::window::WindowId, - event: WindowEvent, - ) { - let window = self.window.as_mut().unwrap(); - let imgui = window.imgui.as_mut().unwrap(); - - match &event { - WindowEvent::Resized(size) => { - window.surface_desc.width = size.width; - window.surface_desc.height = size.height; - window - .surface - .configure(&window.device, &window.surface_desc); - } - WindowEvent::ScaleFactorChanged { scale_factor, .. } => { - window.hidpi_factor = *scale_factor; - let font_size = (13.0 * window.hidpi_factor) as f32; - imgui.context.fonts().clear(); - imgui - .context - .fonts() - .add_font(&[FontSource::DefaultFontData { - config: Some(imgui::FontConfig { - oversample_h: 1, - pixel_snap_h: true, - size_pixels: font_size, - ..Default::default() - }), - }]); - imgui.renderer.reload_font_texture( - &mut imgui.context, - &window.device, - &window.queue, - ); - } - WindowEvent::CloseRequested => event_loop.exit(), - WindowEvent::KeyboardInput { event, .. } => { - if let Key::Named(NamedKey::Escape) = event.logical_key { - if event.state.is_pressed() { - event_loop.exit(); - } - } - } - WindowEvent::RedrawRequested => { - let delta_s = imgui.last_frame.elapsed(); - let now = Instant::now(); - imgui - .context - .io_mut() - .update_delta_time(now - imgui.last_frame); - imgui.last_frame = now; - - let frame = match window.surface.get_current_texture() { - wgpu::CurrentSurfaceTexture::Success(frame) => frame, - // Suboptimal is fine to render with — likely an - // upcoming resize will reconfigure the surface. - wgpu::CurrentSurfaceTexture::Suboptimal(frame) => frame, - wgpu::CurrentSurfaceTexture::Timeout - | wgpu::CurrentSurfaceTexture::Occluded => return, - wgpu::CurrentSurfaceTexture::Outdated | wgpu::CurrentSurfaceTexture::Lost => { - window - .surface - .configure(&window.device, &window.surface_desc); - return; - } - other => { - eprintln!("get_current_texture error: {other:?}"); - return; - } - }; - imgui - .platform - .prepare_frame(imgui.context.io_mut(), &window.window) - .expect("Failed to prepare frame"); - let ui = imgui.context.frame(); - - { - let window = ui.window("Hello world"); - window - .size([300.0, 100.0], Condition::FirstUseEver) - .build(|| { - ui.text("Hello world!"); - ui.text("This...is...imgui-rs on WGPU!"); - ui.separator(); - let mouse_pos = ui.io().mouse_pos; - ui.text(format!( - "Mouse Position: ({:.1},{:.1})", - mouse_pos[0], mouse_pos[1] - )); - }); - - let window = ui.window("Hello too"); - window - .size([400.0, 200.0], Condition::FirstUseEver) - .position([400.0, 200.0], Condition::FirstUseEver) - .build(|| { - ui.text(format!("Frametime: {delta_s:?}")); - }); - - ui.show_demo_window(&mut imgui.demo_open); - } - - let mut encoder: wgpu::CommandEncoder = window - .device - .create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); - - if imgui.last_cursor != ui.mouse_cursor() { - imgui.last_cursor = ui.mouse_cursor(); - imgui.platform.prepare_render(ui, &window.window); - } - - let view = frame - .texture - .create_view(&wgpu::TextureViewDescriptor::default()); - let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: None, - color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view: &view, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Clear(imgui.clear_color), - store: wgpu::StoreOp::Store, - }, - depth_slice: None, - })], - depth_stencil_attachment: None, - timestamp_writes: None, - occlusion_query_set: None, - multiview_mask: None, - }); - - imgui - .renderer - .render( - imgui.context.render(), - &window.queue, - &window.device, - &mut rpass, - ) - .expect("Rendering failed"); - - drop(rpass); - - window.queue.submit(Some(encoder.finish())); - - frame.present(); - } - _ => (), - } - - imgui.platform.handle_event::<()>( - imgui.context.io_mut(), - &window.window, - &Event::WindowEvent { window_id, event }, - ); - } - - fn user_event(&mut self, _event_loop: &ActiveEventLoop, event: ()) { - let window = self.window.as_mut().unwrap(); - let imgui = window.imgui.as_mut().unwrap(); - imgui.platform.handle_event::<()>( - imgui.context.io_mut(), - &window.window, - &Event::UserEvent(event), - ); - } - - fn device_event( - &mut self, - _event_loop: &ActiveEventLoop, - device_id: winit::event::DeviceId, - event: winit::event::DeviceEvent, - ) { - let window = self.window.as_mut().unwrap(); - let imgui = window.imgui.as_mut().unwrap(); - imgui.platform.handle_event::<()>( - imgui.context.io_mut(), - &window.window, - &Event::DeviceEvent { device_id, event }, - ); - } - - fn about_to_wait(&mut self, _event_loop: &ActiveEventLoop) { - let window = self.window.as_mut().unwrap(); - let imgui = window.imgui.as_mut().unwrap(); - window.window.request_redraw(); - imgui.platform.handle_event::<()>( - imgui.context.io_mut(), - &window.window, - &Event::AboutToWait, - ); - } -} - -fn main() { - env_logger::init(); - - let event_loop = EventLoop::new().unwrap(); - event_loop.set_control_flow(ControlFlow::Poll); - event_loop.run_app(&mut App::default()).unwrap(); -}