From d67acaadfa69c2390a9ed484cdeeca5a15a26750 Mon Sep 17 00:00:00 2001 From: Chance Date: Thu, 17 Apr 2025 20:33:28 -0400 Subject: [PATCH] feat(rendering): rendering textures with camera Co-authored-by: BitSyndicate --- Cargo.lock | 863 ++++++++++++++++++++++++++++---------- Cargo.toml | 5 +- shaders/shader.frag | 8 +- shaders/shader.vert | 13 +- src/camera.rs | 53 +++ src/main.rs | 307 ++++++++++---- src/model.rs | 14 + src/texture.rs | 87 ++++ subcrates/zlog/src/lib.rs | 16 +- 9 files changed, 1037 insertions(+), 329 deletions(-) create mode 100644 src/camera.rs create mode 100644 src/model.rs create mode 100644 src/texture.rs diff --git a/Cargo.lock b/Cargo.lock index 7dd62a9..4dd8a95 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,6 +18,12 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046" +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + [[package]] name = "ahash" version = "0.8.11" @@ -28,16 +34,7 @@ dependencies = [ "getrandom 0.2.15", "once_cell", "version_check", - "zerocopy", -] - -[[package]] -name = "aho-corasick" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca972c2ea5f742bfce5687b9aef75506a764f61d37f8f649047846a9686ddb66" -dependencies = [ - "memchr 0.1.11", + "zerocopy 0.7.35", ] [[package]] @@ -46,9 +43,15 @@ version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ - "memchr 2.7.4", + "memchr", ] +[[package]] +name = "aligned-vec" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4aa90d7ce82d4be67b64039a3d588d38dbcc6736577de4a847025ce5b0c468d1" + [[package]] name = "allocator-api2" version = "0.2.21" @@ -68,7 +71,7 @@ dependencies = [ "jni", "jni-sys", "libc", - "log 0.4.27", + "log", "ndk", "ndk-context", "ndk-sys 0.6.0+11769913", @@ -91,6 +94,38 @@ dependencies = [ "libc", ] +[[package]] +name = "anyhow" +version = "1.0.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" + +[[package]] +name = "approx" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f2a05fd1bd10b2527e20a2cd32d8873d115b8b39fe219ee25f42a8aca6ba278" +dependencies = [ + "num-traits", +] + +[[package]] +name = "arbitrary" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dde20b3d026af13f561bdd0f15edf01fc734f0dafcedbaf42bba506a9517f223" + +[[package]] +name = "arg_enum_proc_macro" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ae92a5119aa49cdbcf6b9f893fe4e1d98b04ccbf82ee0584ad948a44a734dea" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "arrayref" version = "0.3.9" @@ -250,6 +285,29 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "av1-grain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6678909d8c5d46a42abcf571271e15fdbc0a225e3646cf23762cd415046c78bf" +dependencies = [ + "anyhow", + "arrayvec", + "log", + "nom", + "num-rational", + "v_frame", +] + +[[package]] +name = "avif-serialize" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98922d6a4cfbcb08820c69d8eeccc05bb1f29bfa06b4f5b1dbfe9a868bd7608e" +dependencies = [ + "arrayvec", +] + [[package]] name = "bit-set" version = "0.8.0" @@ -265,6 +323,12 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" +[[package]] +name = "bit_field" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" + [[package]] name = "bitflags" version = "1.3.2" @@ -280,6 +344,12 @@ dependencies = [ "serde", ] +[[package]] +name = "bitstream-io" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6099cdc01846bc367c4e7dd630dc5966dccf36b652fae7a74e17b640411a91b2" + [[package]] name = "block" version = "0.1.6" @@ -308,6 +378,12 @@ dependencies = [ "piper", ] +[[package]] +name = "built" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56ed6191a7e78c36abdb16ab65341eefd73d64d303fffccdbb00d51e4205967b" + [[package]] name = "bumpalo" version = "3.17.0" @@ -334,6 +410,12 @@ dependencies = [ "syn", ] +[[package]] +name = "byteorder-lite" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495" + [[package]] name = "bytes" version = "1.10.1" @@ -347,7 +429,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b99da2f8558ca23c71f4fd15dc57c906239752dd27ff3c00a1d56b685b7cbfec" dependencies = [ "bitflags 2.9.0", - "log 0.4.27", + "log", "polling", "rustix", "slab", @@ -383,6 +465,16 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" +[[package]] +name = "cfg-expr" +version = "0.15.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d067ad48b8650848b989a59a86c6c36a995d02d2bf778d45c3c5d57bc2718f02" +dependencies = [ + "smallvec", + "target-lexicon", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -395,6 +487,16 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "cgmath" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a98d30140e3296250832bbaaff83b27dcd6fa3cc70fb6f1f3e5c9c0023b5317" +dependencies = [ + "approx", + "num-traits", +] + [[package]] name = "codespan-reporting" version = "0.12.0" @@ -406,6 +508,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "color_quant" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" + [[package]] name = "combine" version = "4.6.7" @@ -413,7 +521,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba5a308b75df32fe02788e748662718f03fde005016435c444eea572398219fd" dependencies = [ "bytes", - "memchr 2.7.4", + "memchr", ] [[package]] @@ -465,6 +573,34 @@ dependencies = [ "libc", ] +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-queue" version = "0.3.12" @@ -535,14 +671,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f25c0e292a7ca6d6498557ff1df68f32c99850012b6ea401cf8daf771f22ff53" [[package]] -name = "env_logger" -version = "0.3.5" +name = "either" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15abd780e45b3ea4f76b4e9a26ff4843258dd8a3eed2775a0e7368c2e7936c2f" -dependencies = [ - "log 0.3.9", - "regex 0.1.80", -] +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" [[package]] name = "equivalent" @@ -581,18 +713,52 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "exr" +version = "1.73.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83197f59927b46c04a183a619b7c29df34e63e63c7869320862268c0ef687e0" +dependencies = [ + "bit_field", + "half", + "lebe", + "miniz_oxide", + "rayon-core", + "smallvec", + "zune-inflate", +] + [[package]] name = "fastrand" version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +[[package]] +name = "fdeflate" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c" +dependencies = [ + "simd-adler32", +] + [[package]] name = "fixedbitset" version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" +[[package]] +name = "flate2" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ced92e76e966ca2fd84c8f7aa01a4aea65b0eb6648d72f7c8f3e2764a67fece" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "foldhash" version = "0.1.5" @@ -626,12 +792,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "futures-core" version = "0.3.31" @@ -690,6 +850,16 @@ dependencies = [ "wasi 0.14.2+wasi-0.2.4", ] +[[package]] +name = "gif" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb2d69b19215e18bb912fa30f7ce15846e301408695e44e0ef719f1da9e19f2" +dependencies = [ + "color_quant", + "weezl", +] + [[package]] name = "gl_generator" version = "0.14.0" @@ -697,21 +867,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a95dfc23a2b4a9a2f5ab41d194f8bfda3cabec42af4e39f08c339eb2a0c124d" dependencies = [ "khronos_api", - "log 0.4.27", + "log", "xml-rs", ] -[[package]] -name = "glm" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c702ce44565c0a09122e1c1d806bffef6528ff5de7bd0bcf636776a32953c7a" -dependencies = [ - "num", - "quickcheck", - "rand 0.3.23", -] - [[package]] name = "glow" version = "0.16.0" @@ -758,7 +917,7 @@ version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c151a2a5ef800297b4e79efa4f4bec035c5f51d5ae587287c9b952bdf734cacd" dependencies = [ - "log 0.4.27", + "log", "presser", "thiserror 1.0.69", "windows", @@ -831,6 +990,45 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" +[[package]] +name = "image" +version = "0.25.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db35664ce6b9810857a38a906215e75a9c879f0696556a39f59c62829710251a" +dependencies = [ + "bytemuck", + "byteorder-lite", + "color_quant", + "exr", + "gif", + "image-webp", + "num-traits", + "png", + "qoi", + "ravif", + "rayon", + "rgb", + "tiff", + "zune-core", + "zune-jpeg", +] + +[[package]] +name = "image-webp" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b77d01e822461baa8409e156015a1d91735549f0f2c17691bd2d996bef238f7f" +dependencies = [ + "byteorder-lite", + "quick-error", +] + +[[package]] +name = "imgref" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0263a3d970d5c054ed9312c0057b4f3bde9c0b33836d3637361d4a9e6e7a408" + [[package]] name = "indexmap" version = "2.9.0" @@ -841,6 +1039,26 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "interpolate_name" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34819042dc3d3971c46c2190835914dfbe0c3c13f61449b2997f4e9722dfa60" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "itertools" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.15" @@ -857,7 +1075,7 @@ dependencies = [ "cfg-if", "combine", "jni-sys", - "log 0.4.27", + "log", "thiserror 1.0.69", "walkdir", "windows-sys 0.45.0", @@ -879,6 +1097,12 @@ dependencies = [ "libc", ] +[[package]] +name = "jpeg-decoder" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0" + [[package]] name = "js-sys" version = "0.3.77" @@ -889,16 +1113,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] - [[package]] name = "khronos-egl" version = "6.0.0" @@ -922,12 +1136,28 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +[[package]] +name = "lebe" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" + [[package]] name = "libc" version = "0.2.171" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6" +[[package]] +name = "libfuzzer-sys" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf78f52d400cf2d84a3a973a78a592b4adc535739e0a5597a0da6f0c357adc75" +dependencies = [ + "arbitrary", + "cc", +] + [[package]] name = "libloading" version = "0.8.6" @@ -977,21 +1207,21 @@ dependencies = [ "scopeguard", ] -[[package]] -name = "log" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -dependencies = [ - "log 0.4.27", -] - [[package]] name = "log" version = "0.4.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" +[[package]] +name = "loop9" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fae87c125b03c1d2c0150c90365d7d6bcc53fb73a9acaef207d2d065860f062" +dependencies = [ + "imgref", +] + [[package]] name = "malloc_buf" version = "0.0.6" @@ -1011,12 +1241,13 @@ dependencies = [ ] [[package]] -name = "memchr" -version = "0.1.11" +name = "maybe-rayon" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20" +checksum = "8ea1f30cedd69f0a2954655f7188c6a834246d2bcf1e315e2ac40c4b24dc9519" dependencies = [ - "libc", + "cfg-if", + "rayon", ] [[package]] @@ -1044,7 +1275,7 @@ dependencies = [ "block", "core-graphics-types", "foreign-types", - "log 0.4.27", + "log", "objc", "paste", ] @@ -1055,6 +1286,16 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +[[package]] +name = "miniz_oxide" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a" +dependencies = [ + "adler2", + "simd-adler32", +] + [[package]] name = "naga" version = "25.0.1" @@ -1070,7 +1311,7 @@ dependencies = [ "hashbrown", "hexf-parse", "indexmap", - "log 0.4.27", + "log", "num-traits", "once_cell", "petgraph", @@ -1089,7 +1330,7 @@ checksum = "c3f42e7bbe13d351b6bead8286a43aac9534b82bd3cc43e47037f012ebfd62d4" dependencies = [ "bitflags 2.9.0", "jni-sys", - "log 0.4.27", + "log", "ndk-sys 0.6.0+11769913", "num_enum", "raw-window-handle", @@ -1120,16 +1361,28 @@ dependencies = [ "jni-sys", ] +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + [[package]] name = "nom" version = "7.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" dependencies = [ - "memchr 2.7.4", + "memchr", "minimal-lexical", ] +[[package]] +name = "noop_proc_macro" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8" + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -1137,45 +1390,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" dependencies = [ "overload", - "winapi 0.3.9", -] - -[[package]] -name = "num" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9bdb1fb680e609c2e0930c1866cafdd0be7e7c7a1ecf92aec71ed8d99d3e133" -dependencies = [ - "num-bigint", - "num-complex", - "num-integer", - "num-iter", - "num-rational", - "num-traits", + "winapi", ] [[package]] name = "num-bigint" -version = "0.1.45" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1357c02fa1d647dd0769ef5bc2bf86281f064231c09c192a46c71246e3ec9258" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ - "autocfg", "num-integer", "num-traits", - "rand 0.4.6", - "rustc-serialize", ] [[package]] -name = "num-complex" -version = "0.1.44" +name = "num-derive" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17cf384bef067563c44d41028840dbecc7f06f2aa5d7881a81dfb0fc7c72f202" +checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ - "autocfg", - "num-traits", - "rustc-serialize", + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -1187,28 +1423,15 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-iter" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - [[package]] name = "num-rational" -version = "0.1.43" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbfff0773e8a07fb033d726b9ff1327466709820788e5298afce4d752965ff1e" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" dependencies = [ - "autocfg", "num-bigint", "num-integer", "num-traits", - "rustc-serialize", ] [[package]] @@ -1643,6 +1866,19 @@ version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" +[[package]] +name = "png" +version = "0.17.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82151a2fc869e011c153adc57cf2789ccb8d9906ce52c0b39a6b5697749d7526" +dependencies = [ + "bitflags 1.3.2", + "crc32fast", + "fdeflate", + "flate2", + "miniz_oxide", +] + [[package]] name = "polling" version = "3.7.4" @@ -1664,6 +1900,15 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e" +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy 0.8.24", +] + [[package]] name = "presser" version = "0.3.1" @@ -1703,6 +1948,34 @@ name = "profiling" version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "afbdc74edc00b6f6a218ca6a5364d6226a259d4b8ea1af4a0ea063f27e179f4d" +dependencies = [ + "profiling-procmacros", +] + +[[package]] +name = "profiling-procmacros" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a65f2e60fbf1063868558d69c6beacf412dc755f9fc020f514b7955fc914fe30" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "qoi" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001" +dependencies = [ + "bytemuck", +] + +[[package]] +name = "quick-error" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" [[package]] name = "quick-xml" @@ -1710,18 +1983,7 @@ version = "0.37.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4ce8c88de324ff838700f36fb6ab86c96df0e3c4ab6ef3a9b2044465cce1369" dependencies = [ - "memchr 2.7.4", -] - -[[package]] -name = "quickcheck" -version = "0.2.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d086a75fc7bdfbadd649f7c1fa524f39be4979b15506f621b3742b752f5364ed" -dependencies = [ - "env_logger", - "log 0.3.9", - "rand 0.3.23", + "memchr", ] [[package]] @@ -1741,41 +2003,33 @@ checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5" [[package]] name = "rand" -version = "0.3.23" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand 0.4.6", + "rand_chacha", + "rand_core", ] [[package]] -name = "rand" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" -dependencies = [ - "fuchsia-cprng", - "libc", - "rand_core 0.3.1", - "rdrand", - "winapi 0.3.9", -] - -[[package]] -name = "rand_core" +name = "rand_chacha" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ - "rand_core 0.4.2", + "ppv-lite86", + "rand_core", ] [[package]] name = "rand_core" -version = "0.4.2" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.15", +] [[package]] name = "range-alloc" @@ -1783,6 +2037,56 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3d6831663a5098ea164f89cff59c6284e95f4e3c76ce9848d4529f5ccca9bde" +[[package]] +name = "rav1e" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd87ce80a7665b1cce111f8a16c1f3929f6547ce91ade6addf4ec86a8dda5ce9" +dependencies = [ + "arbitrary", + "arg_enum_proc_macro", + "arrayvec", + "av1-grain", + "bitstream-io", + "built", + "cfg-if", + "interpolate_name", + "itertools", + "libc", + "libfuzzer-sys", + "log", + "maybe-rayon", + "new_debug_unreachable", + "noop_proc_macro", + "num-derive", + "num-traits", + "once_cell", + "paste", + "profiling", + "rand", + "rand_chacha", + "simd_helpers", + "system-deps", + "thiserror 1.0.69", + "v_frame", + "wasm-bindgen", +] + +[[package]] +name = "ravif" +version = "0.11.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6a5f31fcf7500f9401fea858ea4ab5525c99f2322cfcee732c0e6c74208c0c6" +dependencies = [ + "avif-serialize", + "imgref", + "loop9", + "quick-error", + "rav1e", + "rayon", + "rgb", +] + [[package]] name = "raw-window-handle" version = "0.6.2" @@ -1802,12 +2106,23 @@ dependencies = [ ] [[package]] -name = "rdrand" -version = "0.4.0" +name = "rayon" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" dependencies = [ - "rand_core 0.3.1", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", ] [[package]] @@ -1828,27 +2143,14 @@ dependencies = [ "bitflags 2.9.0", ] -[[package]] -name = "regex" -version = "0.1.80" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fd4ace6a8cf7860714a2c2280d6c1f7e6a413486c13298bbc86fd3da019402f" -dependencies = [ - "aho-corasick 0.5.3", - "memchr 0.1.11", - "regex-syntax 0.3.9", - "thread_local 0.2.7", - "utf8-ranges", -] - [[package]] name = "regex" version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ - "aho-corasick 1.1.3", - "memchr 2.7.4", + "aho-corasick", + "memchr", "regex-automata 0.4.9", "regex-syntax 0.8.5", ] @@ -1868,17 +2170,11 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ - "aho-corasick 1.1.3", - "memchr 2.7.4", + "aho-corasick", + "memchr", "regex-syntax 0.8.5", ] -[[package]] -name = "regex-syntax" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957" - [[package]] name = "regex-syntax" version = "0.6.29" @@ -1901,18 +2197,18 @@ checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832" name = "renderer" version = "0.1.0" +[[package]] +name = "rgb" +version = "0.8.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57397d16646700483b67d2dd6511d79318f9d057fdbd21a4066aeac8b41d310a" + [[package]] name = "rustc-hash" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustc-serialize" -version = "0.3.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe834bc780604f4674073badbad26d7219cadfb4a2275802db12cbae17498401" - [[package]] name = "rustix" version = "0.38.44" @@ -1966,7 +2262,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6277f0217056f77f1d8f49f2950ac6c278c0d607c45f5ee99328d792ede24ec" dependencies = [ "ab_glyph", - "log 0.4.27", + "log", "memmap2", "smithay-client-toolkit", "tiny-skia", @@ -1999,11 +2295,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" dependencies = [ "itoa", - "memchr 2.7.4", + "memchr", "ryu", "serde", ] +[[package]] +name = "serde_spanned" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" +dependencies = [ + "serde", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -2028,6 +2333,21 @@ dependencies = [ "libc", ] +[[package]] +name = "simd-adler32" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" + +[[package]] +name = "simd_helpers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95890f873bec569a0362c235787f3aca6e1e887302ba4840839bcc6459c42da6" +dependencies = [ + "quote", +] + [[package]] name = "slab" version = "0.4.9" @@ -2069,7 +2389,7 @@ dependencies = [ "calloop-wayland-source", "cursor-icon", "libc", - "log 0.4.27", + "log", "memmap2", "rustix", "thiserror 1.0.69", @@ -2163,6 +2483,25 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "system-deps" +version = "6.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e535eb8dded36d55ec13eddacd30dec501792ff23a0b1682c38601b8cf2349" +dependencies = [ + "cfg-expr", + "heck 0.5.0", + "pkg-config", + "toml", + "version-compare", +] + +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + [[package]] name = "termcolor" version = "1.4.1" @@ -2218,25 +2557,6 @@ dependencies = [ "syn", ] -[[package]] -name = "thread-id" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03" -dependencies = [ - "kernel32-sys", - "libc", -] - -[[package]] -name = "thread_local" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8576dbbfcaef9641452d5cf0df9b0e7eeab7694956dd33bb61515fb8f18cfdd5" -dependencies = [ - "thread-id", -] - [[package]] name = "thread_local" version = "1.1.8" @@ -2247,6 +2567,17 @@ dependencies = [ "once_cell", ] +[[package]] +name = "tiff" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba1310fcea54c6a9a4fd1aad794ecc02c31682f6bfbecdf460bf19533eed1e3e" +dependencies = [ + "flate2", + "jpeg-decoder", + "weezl", +] + [[package]] name = "tiny-skia" version = "0.11.4" @@ -2257,7 +2588,7 @@ dependencies = [ "arrayvec", "bytemuck", "cfg-if", - "log 0.4.27", + "log", "tiny-skia-path", ] @@ -2272,11 +2603,35 @@ dependencies = [ "strict-num", ] +[[package]] +name = "tobj" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04aca6092e5978e708ee784e8ab9b5cf3cdb598b28f99a2f257446e7081a7025" +dependencies = [ + "ahash", +] + +[[package]] +name = "toml" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd87a5cdd6ffab733b2f74bc4fd7ee5fff6634124999ac278c35fc78c6120148" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + [[package]] name = "toml_datetime" version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] [[package]] name = "toml_edit" @@ -2285,6 +2640,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474" dependencies = [ "indexmap", + "serde", + "serde_spanned", "toml_datetime", "winnow", ] @@ -2327,7 +2684,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" dependencies = [ - "log 0.4.27", + "log", "once_cell", "tracing-core", ] @@ -2341,10 +2698,10 @@ dependencies = [ "matchers", "nu-ansi-term", "once_cell", - "regex 1.11.1", + "regex", "sharded-slab", "smallvec", - "thread_local 1.1.8", + "thread_local", "tracing", "tracing-core", "tracing-log", @@ -2375,10 +2732,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" [[package]] -name = "utf8-ranges" -version = "0.1.3" +name = "v_frame" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f" +checksum = "d6f32aaa24bacd11e488aa9ba66369c7cd514885742c9fe08cfe85884db3e92b" +dependencies = [ + "aligned-vec", + "num-traits", + "wasm-bindgen", +] [[package]] name = "valuable" @@ -2386,6 +2748,12 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" +[[package]] +name = "version-compare" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b" + [[package]] name = "version_check" version = "0.9.5" @@ -2426,7 +2794,7 @@ dependencies = [ "serde_json", "slabbin", "smallvec", - "thread_local 1.1.8", + "thread_local", "vk-parse", "vulkano-macros", "x11-dl", @@ -2489,7 +2857,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" dependencies = [ "bumpalo", - "log 0.4.27", + "log", "proc-macro2", "quote", "syn", @@ -2645,7 +3013,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbcebb399c77d5aa9fa5db874806ee7b4eba4e73650948e8f93963f128896615" dependencies = [ "dlib", - "log 0.4.27", + "log", "once_cell", "pkg-config", ] @@ -2670,6 +3038,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "weezl" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" + [[package]] name = "wgpu" version = "25.0.0" @@ -2682,7 +3056,7 @@ dependencies = [ "document-features", "hashbrown", "js-sys", - "log 0.4.27", + "log", "naga", "parking_lot", "portable-atomic", @@ -2713,7 +3087,7 @@ dependencies = [ "document-features", "hashbrown", "indexmap", - "log 0.4.27", + "log", "naga", "once_cell", "parking_lot", @@ -2783,7 +3157,7 @@ dependencies = [ "khronos-egl", "libc", "libloading", - "log 0.4.27", + "log", "metal", "naga", "ndk-sys 0.5.0+25.2.9519653", @@ -2813,17 +3187,11 @@ dependencies = [ "bitflags 2.9.0", "bytemuck", "js-sys", - "log 0.4.27", + "log", "thiserror 2.0.12", "web-sys", ] -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" - [[package]] name = "winapi" version = "0.3.9" @@ -2834,12 +3202,6 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu", ] -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -3188,7 +3550,7 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63d3fcd9bba44b03821e7d699eeee959f3126dcc4aa8e4ae18ec617c2a5cea10" dependencies = [ - "memchr 2.7.4", + "memchr", ] [[package]] @@ -3246,7 +3608,7 @@ checksum = "d039de8032a9a8856a6be89cea3e5d12fdd82306ab7c94d74e6deab2460651c5" dependencies = [ "bitflags 2.9.0", "dlib", - "log 0.4.27", + "log", "once_cell", "xkeysym", ] @@ -3273,10 +3635,13 @@ checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" name = "zenyx" version = "0.1.0" dependencies = [ - "glm", + "bytemuck", + "cgmath", + "image", "smol", "terminator", "thiserror 2.0.12", + "tobj", "tracing", "tracing-subscriber", "vulkano", @@ -3291,7 +3656,16 @@ version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ - "zerocopy-derive", + "zerocopy-derive 0.7.35", +] + +[[package]] +name = "zerocopy" +version = "0.8.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2586fea28e186957ef732a5f8b3be2da217d65c5969d4b1e17f973ebbe876879" +dependencies = [ + "zerocopy-derive 0.8.24", ] [[package]] @@ -3305,6 +3679,17 @@ dependencies = [ "syn", ] +[[package]] +name = "zerocopy-derive" +version = "0.8.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a996a8f63c5c4448cd959ac1bab0aaa3306ccfd060472f85943ee0750f0169be" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "zlog" version = "0.1.0" @@ -3313,3 +3698,27 @@ dependencies = [ "tracing", "tracing-subscriber", ] + +[[package]] +name = "zune-core" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f423a2c17029964870cfaabb1f13dfab7d092a62a29a89264f4d36990ca414a" + +[[package]] +name = "zune-inflate" +version = "0.2.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73ab332fe2f6680068f3582b16a24f90ad7096d5d39b974d1c0aff0125116f02" +dependencies = [ + "simd-adler32", +] + +[[package]] +name = "zune-jpeg" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99a5bab8d7dedf81405c4bb1f2b83ea057643d9cb28778cea9eecddeedd2e028" +dependencies = [ + "zune-core", +] diff --git a/Cargo.toml b/Cargo.toml index 5990c93..76f6f84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,11 +37,14 @@ incremental = false panic = "abort" [dependencies] -glm = "0.2.3" +bytemuck = "1.22.0" +cgmath = "0.18.0" +image = "0.25.6" smol = "2.0.2" terminator = "0.3.2" thiserror = "2.0.12" +tobj = "4.0.3" tracing = "0.1.41" tracing-subscriber = { version = "0.3.19", features = ["env-filter"] } vulkano = "0.35.1" diff --git a/shaders/shader.frag b/shaders/shader.frag index 3b53533..a669570 100644 --- a/shaders/shader.frag +++ b/shaders/shader.frag @@ -1,8 +1,10 @@ #version 450 -layout(location = 0) in vec3 color; +layout(location = 0) in vec2 tex_coords; +layout(set = 0, binding = 0) uniform texture2D t_diffuse; +layout(set = 0, binding = 1) uniform sampler s_diffuse; layout(location = 0) out vec4 out_color; - +// layout(group = 0, binding = 0) out texture2D; void main() { - out_color = vec4(color, 1.0); + out_color = texture(sampler2D(t_diffuse, s_diffuse), tex_coords); } diff --git a/shaders/shader.vert b/shaders/shader.vert index c293ef5..300db84 100644 --- a/shaders/shader.vert +++ b/shaders/shader.vert @@ -2,9 +2,14 @@ layout(location = 0) in vec3 position; layout(location = 1) in vec3 color; -layout(location = 0) out vec3 out_color; - +layout(location = 3) in vec2 tex_coords; +layout(location = 0) out vec2 tex_coord; +layout(set = 1, binding = 0) uniform UniformBufferObject { + mat4x4 projection; +} view; void main() { - gl_Position = vec4(position, 1.0); - out_color = color; + gl_Position = view.projection * vec4(position, 1.0); + tex_coord = tex_coords; + // gl_Position + // out_color = color; } diff --git a/src/camera.rs b/src/camera.rs new file mode 100644 index 0000000..33a64a0 --- /dev/null +++ b/src/camera.rs @@ -0,0 +1,53 @@ +pub struct Camera { + pub eye: cgmath::Point3, + pub target: cgmath::Point3, + pub up: cgmath::Vector3, + pub aspect: f32, + pub fovy: f32, + pub znear: f32, + pub zfar: f32, +} + +impl Camera { + fn build_view_projection_matrix(&self) -> cgmath::Matrix4 { + let view = cgmath::Matrix4::look_at_rh(self.eye, self.target, self.up); + + let proj = cgmath::perspective(cgmath::Deg(self.fovy), self.aspect, self.znear, self.zfar); + + OPENGL_TO_WGPU_MATRIX * proj * view + } + + pub fn update_aspect(&mut self, aspect: f32) { + self.aspect = aspect; + } +} + +#[rustfmt::skip] +pub 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.5, + 0.0, 0.0, 0.0, 1.0, +); + +unsafe impl bytemuck::Pod for CameraUniform {} +unsafe impl bytemuck::Zeroable for CameraUniform {} + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct CameraUniform { + view_proj: cgmath::Matrix4, +} +impl Default for CameraUniform { + fn default() -> CameraUniform { + use cgmath::SquareMatrix; + Self { + view_proj: cgmath::Matrix4::identity(), + } + } +} +impl CameraUniform { + pub fn update_view_proj(&mut self, camera: &Camera) { + self.view_proj = camera.build_view_projection_matrix(); + } +} diff --git a/src/main.rs b/src/main.rs index 1caac30..dffe4bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,20 +1,22 @@ use std::collections::BTreeMap; -use std::sync::LazyLock; -use std::{collections::HashMap, sync::Arc}; +use std::sync::Arc; -use terminator::Terminator; -use vulkano::buffer::BufferUsage; -use wgpu::util::{DeviceExt, RenderEncoder}; +use bytemuck::bytes_of; +use tracing::info; +use wgpu::util::DeviceExt; use wgpu::{ - Backends, BufferSlice, BufferUsages, FragmentState, IndexFormat, Instance, InstanceDescriptor, - PipelineCompilationOptions, Surface, + Backends, BufferUsages, FragmentState, IndexFormat, Instance, InstanceDescriptor, + PipelineCompilationOptions, }; use winit::application::ApplicationHandler; use winit::event::{ElementState, MouseButton}; use winit::event_loop::{ActiveEventLoop, EventLoop}; use winit::window::{Window, WindowAttributes, WindowId}; use zlog::LogLevel; -use zlog::{config::LoggerConfig, query::LogQuery}; +use zlog::config::LoggerConfig; +pub mod camera; +pub mod model; +pub mod texture; struct WindowContext<'window> { window: Arc, renderer: WgpuRenderer<'window>, @@ -33,10 +35,52 @@ struct WgpuRenderer<'surface> { surface: wgpu::Surface<'surface>, surface_config: wgpu::SurfaceConfiguration, render_pipeline: wgpu::RenderPipeline, + vertex_buffer: wgpu::Buffer, + index_buffer: wgpu::Buffer, + diffuse_bind_group: wgpu::BindGroup, + camera: camera::Camera, + camera_uniform: camera::CameraUniform, + camera_buffer: wgpu::Buffer, + camera_bind_group: wgpu::BindGroup, +} + +impl WgpuRenderer<'_> { + pub fn draw(&mut self) { + let surface_texture = self.surface.get_current_texture().unwrap(); + let view = surface_texture.texture.create_view(&Default::default()); + let mut encoder = + self.device + .create_command_encoder(&wgpu::wgt::CommandEncoderDescriptor { + label: Some("Render encoder"), + }); + { + let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("Render"), + color_attachments: &[Some(wgpu::RenderPassColorAttachment { + view: &view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color::BLACK), + store: wgpu::StoreOp::Store, + }, + })], + depth_stencil_attachment: None, + timestamp_writes: None, + occlusion_query_set: None, + }); + rpass.set_pipeline(&self.render_pipeline); + rpass.set_bind_group(0, &self.diffuse_bind_group, &[]); + + rpass.set_bind_group(1, &self.camera_bind_group, &[]); + rpass.set_vertex_buffer(0, self.vertex_buffer.slice(..)); + rpass.set_index_buffer(self.index_buffer.slice(..), IndexFormat::Uint32); + rpass.draw_indexed(0..INDICIES.len() as u32, 0, 0..1); + } + self.queue.submit(Some(encoder.finish())); + surface_texture.present() + } } -// impl WgpuRenderer { -// pub fn new(window: Arc) {} struct App<'window> { state: WgpuState, windows: BTreeMap>, @@ -49,6 +93,7 @@ impl App<'_> { windows: BTreeMap::new(), } } + pub fn spawn_window(&mut self, event_loop: &ActiveEventLoop) { let attr = WindowAttributes::default() .with_title("Zenyx - SubWindow") @@ -69,14 +114,20 @@ impl App<'_> { struct WgpuState { instance: wgpu::Instance, } +unsafe impl bytemuck::Pod for Vertex {} +unsafe impl bytemuck::Zeroable for Vertex {} + +#[derive(Copy, Clone, Debug)] #[repr(C)] struct Vertex { - position: glm::Vec3, - color: glm::Vec3, + position: cgmath::Vector3, + color: cgmath::Vector3, + normal: cgmath::Vector3, + tex_coords: cgmath::Vector2, } impl Vertex { - const ATTRIBS: [wgpu::VertexAttribute; 2] = [ + const ATTRIBS: [wgpu::VertexAttribute; 4] = [ wgpu::VertexAttribute { offset: 0, shader_location: 0, @@ -87,6 +138,16 @@ impl Vertex { shader_location: 1, format: wgpu::VertexFormat::Float32x3, }, + wgpu::VertexAttribute { + offset: std::mem::offset_of!(Vertex, normal) as u64, + shader_location: 2, + format: wgpu::VertexFormat::Float32x3, + }, + wgpu::VertexAttribute { + offset: std::mem::offset_of!(Vertex, tex_coords) as u64, + shader_location: 3, + format: wgpu::VertexFormat::Float32x2, + }, ]; const fn desc<'a>() -> wgpu::VertexBufferLayout<'a> { @@ -97,7 +158,7 @@ impl Vertex { } } } - +static ICON: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/assets/Badge.png")); impl WgpuState { fn new() -> Self { let backends = Backends::PRIMARY; @@ -126,31 +187,69 @@ impl WgpuState { let size = window.inner_size(); let width = size.width.max(1); let height = size.height.max(1); + let texture_bind_group_layout = + device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + entries: &[ + wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::FRAGMENT, + ty: wgpu::BindingType::Texture { + multisampled: false, + view_dimension: wgpu::TextureViewDimension::D2, + sample_type: wgpu::TextureSampleType::Float { filterable: true }, + }, + count: None, + }, + wgpu::BindGroupLayoutEntry { + binding: 1, + visibility: wgpu::ShaderStages::FRAGMENT, + // This should match the filterable field of the + // corresponding Texture entry above. + ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering), + count: None, + }, + ], + label: Some("texture_bind_group_layout"), + }); + let camera_bind_group_layout = + device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { + entries: &[wgpu::BindGroupLayoutEntry { + binding: 0, + visibility: wgpu::ShaderStages::VERTEX, + ty: wgpu::BindingType::Buffer { + ty: wgpu::BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: None, + }, + count: None, + }], + label: Some("Camera Bind group layout"), + }); #[repr(align(4))] struct ShaderCode([u8; N]); let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { label: Some("Pipeline Layout"), - bind_group_layouts: &[], + bind_group_layouts: &[&texture_bind_group_layout, &camera_bind_group_layout], push_constant_ranges: &[], }); let vert_shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("Vertex Shader"), source: unsafe { - static shader_code: &[u8] = + static SHADER_CODE: &[u8] = &ShaderCode(*include_bytes!(concat!(env!("OUT_DIR"), "/vert.spv"))).0; // assert!(bytes.len() % 4 == 0); - let shader = shader_code.align_to::().1; + let shader = SHADER_CODE.align_to::().1; wgpu::ShaderSource::SpirV(std::borrow::Cow::Borrowed(shader)) }, }); let frag_shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: Some("Fragment Shader"), source: unsafe { - static shader_code: &[u8] = + static SHADER_CODE: &[u8] = &ShaderCode(*include_bytes!(concat!(env!("OUT_DIR"), "/frag.spv"))).0; - // assert!(bytes.len() % 4 == 0); - let shader = shader_code.align_to::().1; + debug_assert!(SHADER_CODE.len() % 4 == 0); + let shader = SHADER_CODE.align_to::().1; wgpu::ShaderSource::SpirV(std::borrow::Cow::Borrowed(shader)) }, }); @@ -202,7 +301,6 @@ impl WgpuState { } else { wgpu::PresentMode::Fifo }; - let surface_config = wgpu::SurfaceConfiguration { width, height, @@ -215,36 +313,114 @@ impl WgpuState { }; surface.configure(&device, &surface_config); + let diffuse_texture = + texture::Texture::from_bytes(&device, &queue, ICON, "zenyx-icon").unwrap(); + let vertex_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Vertex buffer"), + contents: bytemuck::cast_slice(VERTICES.as_ref()), + usage: BufferUsages::VERTEX, + }); + let index_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Index buffer"), + contents: bytemuck::cast_slice(&INDICIES), + usage: BufferUsages::INDEX, + }); + + let diffuse_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + layout: &texture_bind_group_layout, + entries: &[ + wgpu::BindGroupEntry { + binding: 0, + resource: wgpu::BindingResource::TextureView(&diffuse_texture.view), + }, + wgpu::BindGroupEntry { + binding: 1, + resource: wgpu::BindingResource::Sampler(&diffuse_texture.sampler), + }, + ], + label: Some("diffuse_bind_group"), + }); + let camera = camera::Camera { + // position the camera 1 unit up and 2 units back + // +z is out of the screen + eye: (0.0, 0.0, 2.0).into(), + // have it look at the origin + target: (0.0, 0.0, 0.0).into(), + // which way is "up" + up: cgmath::Vector3::unit_y(), + aspect: surface_config.width as f32 / surface_config.height as f32, + fovy: 45.0, + znear: 0.1, + zfar: 100.0, + }; + + let mut camera_uniform = camera::CameraUniform::default(); + camera_uniform.update_view_proj(&camera); + + let camera_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { + label: Some("Camera Buffer"), + contents: bytemuck::cast_slice(&[camera_uniform]), + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, + }); + + let camera_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { + layout: &camera_bind_group_layout, + entries: &[wgpu::BindGroupEntry { + binding: 0, + resource: camera_buffer.as_entire_binding(), + }], + label: Some("Camera Bind Group"), + }); + let render_pipeline = device.create_render_pipeline(&pipeline_descriptor); WgpuRenderer { surface, surface_config, + diffuse_bind_group, render_pipeline, device, + vertex_buffer, + index_buffer, + camera, queue, + camera_uniform, + camera_buffer, + camera_bind_group, } } } -static VERTICES: LazyLock<[Vertex; 3]> = std::sync::LazyLock::new(|| { +static VERTICES: [Vertex; 4] = { [ Vertex { - position: glm::vec3(-0.6, -0.5, 0.0), - color: glm::vec3(1.0, 0.0, 0.0), + position: cgmath::vec3(-0.5, -0.5, 0.0), + color: cgmath::vec3(1.0, 0.0, 0.0), + normal: cgmath::vec3(0.0, 0.0, 0.0), + tex_coords: cgmath::vec2(1.0, 0.0), }, Vertex { - position: glm::vec3(0.6, -0.5, 0.0), - color: glm::vec3(0.0, 1.0, 0.0), + position: cgmath::vec3(0.5, -0.5, 0.0), + color: cgmath::vec3(0.0, 1.0, 0.0), + normal: cgmath::vec3(0.0, 0.0, 0.0), + tex_coords: cgmath::vec2(0.0, 0.0), }, Vertex { - position: glm::vec3(0.0, 0.5, 0.0), - color: glm::vec3(0.0, 0.0, 1.0), + position: cgmath::vec3(0.5, 0.5, 0.0), + color: cgmath::vec3(0.0, 0.0, 1.0), + normal: cgmath::vec3(0.0, 0.0, 0.0), + tex_coords: cgmath::vec2(0.0, 1.0), + }, + Vertex { + position: cgmath::vec3(-0.5, 0.5, 0.0), + color: cgmath::vec3(0.0, 0.0, 1.0), + normal: cgmath::vec3(0.0, 0.0, 0.0), + tex_coords: cgmath::vec2(1.0, 1.0), }, ] -}); +}; -static INDICIES: [u32; 3] = [0, 1, 2]; +static INDICIES: [u32; 6] = [0, 1, 2, 2, 3, 0]; -impl<'window> ApplicationHandler for App<'window> { +impl ApplicationHandler for App<'_> { fn window_event( &mut self, event_loop: &winit::event_loop::ActiveEventLoop, @@ -253,50 +429,8 @@ impl<'window> ApplicationHandler for App<'window> { ) { match event { winit::event::WindowEvent::RedrawRequested => { - let window_ctx = self.windows.get(&window_id).unwrap(); - let surface_texture = window_ctx.renderer.surface.get_current_texture().unwrap(); - let view = surface_texture.texture.create_view(&Default::default()); - let mut encoder = window_ctx.renderer.device.create_command_encoder( - &wgpu::wgt::CommandEncoderDescriptor { - label: Some("Render encoder"), - }, - ); - { - let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: Some("Render"), - color_attachments: &[Some(wgpu::RenderPassColorAttachment { - view: &view, - resolve_target: None, - ops: wgpu::Operations { - load: wgpu::LoadOp::Clear(wgpu::Color::BLACK), - store: wgpu::StoreOp::Store, - }, - })], - depth_stencil_attachment: None, - timestamp_writes: None, - occlusion_query_set: None, - }); - rpass.set_pipeline(&window_ctx.renderer.render_pipeline); - let vertex_buffer = window_ctx.renderer.device.create_buffer_init( - &wgpu::util::BufferInitDescriptor { - label: Some("Vertex buffer"), - contents: unsafe { VERTICES.align_to::().1 }, - usage: BufferUsages::VERTEX, - }, - ); - let index_buffer = window_ctx.renderer.device.create_buffer_init( - &wgpu::util::BufferInitDescriptor { - label: Some("Index buffer"), - contents: unsafe { INDICIES.align_to::().1 }, - usage: BufferUsages::INDEX, - }, - ); - rpass.set_vertex_buffer(0, vertex_buffer.slice(..)); - rpass.set_index_buffer(index_buffer.slice(..), IndexFormat::Uint32); - rpass.draw_indexed(0..INDICIES.len() as u32, 0, 0..1); - } - window_ctx.renderer.queue.submit(Some(encoder.finish())); - surface_texture.present() + let window_ctx = self.windows.get_mut(&window_id).unwrap(); + window_ctx.renderer.draw() } winit::event::WindowEvent::CloseRequested => { let _ = self.windows.remove(&window_id); @@ -304,23 +438,33 @@ impl<'window> ApplicationHandler for App<'window> { event_loop.exit(); } } - winit::event::WindowEvent::MouseInput { - device_id, - state, - button, - } => { + winit::event::WindowEvent::MouseInput { state, button, .. } => { if button == MouseButton::Left && state == ElementState::Pressed { self.spawn_window(event_loop); } } winit::event::WindowEvent::Resized(size) => { - if let Some(window_ctx) = self.windows.get(&window_id) { + if let Some(window_ctx) = self.windows.get_mut(&window_id) { if size.width == 0 || size.height == 0 { return; } + window_ctx + .renderer + .camera + .update_aspect(size.width as f32 / size.height as f32); + window_ctx + .renderer + .camera_uniform + .update_view_proj(&window_ctx.renderer.camera); + window_ctx.renderer.queue.write_buffer( + &window_ctx.renderer.camera_buffer, + 0, + bytes_of(&window_ctx.renderer.camera_uniform), + ); let mut new_config = window_ctx.renderer.surface_config.clone(); new_config.width = size.width; new_config.height = size.height; + window_ctx .renderer .surface @@ -364,5 +508,6 @@ fn main() -> Result<(), terminator::Terminator> { let mut app = App::new(); event_loop.run_app(&mut app)?; + info!("Exiting..."); Ok(()) } diff --git a/src/model.rs b/src/model.rs new file mode 100644 index 0000000..542b391 --- /dev/null +++ b/src/model.rs @@ -0,0 +1,14 @@ +use crate::texture::Texture; +pub struct Material { + pub name: String, + pub diffuse_texture: Texture, + pub bind_group: wgpu::BindGroup, +} + +pub struct Mesh { + pub name: String, + pub vertex_buffer: wgpu::Buffer, + pub index_buffer: wgpu::Buffer, + pub num_elements: u32, + pub material: usize, +} diff --git a/src/texture.rs b/src/texture.rs new file mode 100644 index 0000000..42fda6e --- /dev/null +++ b/src/texture.rs @@ -0,0 +1,87 @@ +use image::GenericImageView; +use thiserror::Error; +#[derive(Debug, Error)] +pub enum TextureError { + #[error("Failed to load image")] + ImageError( + #[from] + #[source] + image::ImageError, + ), +} +pub struct Texture { + #[allow(unused)] + pub texture: wgpu::Texture, + pub view: wgpu::TextureView, + pub sampler: wgpu::Sampler, +} +impl Texture { + pub fn from_bytes( + device: &wgpu::Device, + queue: &wgpu::Queue, + bytes: &[u8], + label: &str, + ) -> Result { + let img = image::load_from_memory(bytes)?; + Self::from_image(device, queue, &img, Some(label)) + } + + pub fn from_image( + device: &wgpu::Device, + queue: &wgpu::Queue, + img: &image::DynamicImage, + label: Option<&str>, + ) -> Result { + let rgba = img.to_rgba8(); + let dimensions = img.dimensions(); + + let size = wgpu::Extent3d { + width: dimensions.0, + height: dimensions.1, + depth_or_array_layers: 1, + }; + let texture = device.create_texture(&wgpu::TextureDescriptor { + label, + size, + mip_level_count: 1, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: wgpu::TextureFormat::Rgba8UnormSrgb, + usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, + view_formats: &[], + }); + + queue.write_texture( + wgpu::TexelCopyTextureInfo { + aspect: wgpu::TextureAspect::All, + texture: &texture, + mip_level: 0, + origin: wgpu::Origin3d::ZERO, + }, + &rgba, + wgpu::TexelCopyBufferLayout { + offset: 0, + bytes_per_row: Some(4 * dimensions.0), + rows_per_image: Some(dimensions.1), + }, + size, + ); + + let view = texture.create_view(&wgpu::TextureViewDescriptor::default()); + let sampler = device.create_sampler(&wgpu::SamplerDescriptor { + address_mode_u: wgpu::AddressMode::ClampToEdge, + address_mode_v: wgpu::AddressMode::ClampToEdge, + address_mode_w: wgpu::AddressMode::ClampToEdge, + mag_filter: wgpu::FilterMode::Linear, + min_filter: wgpu::FilterMode::Nearest, + mipmap_filter: wgpu::FilterMode::Nearest, + ..Default::default() + }); + + Ok(Self { + texture, + view, + sampler, + }) + } +} diff --git a/subcrates/zlog/src/lib.rs b/subcrates/zlog/src/lib.rs index f81212f..c069b34 100644 --- a/subcrates/zlog/src/lib.rs +++ b/subcrates/zlog/src/lib.rs @@ -20,7 +20,6 @@ use config::LoggerConfig; use query::LogQuery; use tracing::{Event, Level, Subscriber, level_filters::LevelFilter, subscriber::DefaultGuard}; use tracing_subscriber::{ - fmt::writer::WithFilter, layer::{Context, Layer, SubscriberExt}, registry::LookupSpan, util::SubscriberInitExt, @@ -76,7 +75,9 @@ impl BufferLayer { impl Drop for BufferLayer { fn drop(&mut self) { for tx in &self.senders { - tx.send(LogEvent::Shutdown).unwrap(); + if let Err(e) = tx.send(LogEvent::Shutdown) { + panic!("{e}") + } } self.senders.clear(); } @@ -143,17 +144,6 @@ pub enum LogLevel { Trace, } -impl From for tracing::Level { - fn from(level: LogLevel) -> Self { - match level { - LogLevel::Error => Level::ERROR, - LogLevel::Info => Level::INFO, - LogLevel::Debug => Level::DEBUG, - LogLevel::Trace => Level::TRACE, - LogLevel::Warn => Level::WARN, - } - } -} impl From for LevelFilter { fn from(level: LogLevel) -> Self { match level {