From 35c498a3c3fc8fce1fa20b3dafaca4843dfd8ca1 Mon Sep 17 00:00:00 2001 From: Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com> Date: Tue, 20 Aug 2024 04:56:51 +0200 Subject: [PATCH 01/12] add formatting config and formatted files --- gloom-rs/.rustfmt.toml | 12 ++ gloom-rs/Cargo.lock | 316 +++++++++++++++++++++++++---------------- gloom-rs/Cargo.toml | 3 +- gloom-rs/src/main.rs | 62 ++++---- gloom-rs/src/shader.rs | 43 +++--- gloom-rs/src/util.rs | 28 ++-- 6 files changed, 276 insertions(+), 188 deletions(-) create mode 100644 gloom-rs/.rustfmt.toml diff --git a/gloom-rs/.rustfmt.toml b/gloom-rs/.rustfmt.toml new file mode 100644 index 0000000..d1e5bd9 --- /dev/null +++ b/gloom-rs/.rustfmt.toml @@ -0,0 +1,12 @@ +edition = "2021" +max_width = 110 +hard_tabs = false +tab_spaces = 4 +newline_style = "Unix" +use_small_heuristics = "Max" +indent_style = "Block" +trailing_comma = "Always" +space_around_ranges = true +reorder_imports = true +max_blank_lines = 1 +spaces_around_comments = true diff --git a/gloom-rs/Cargo.lock b/gloom-rs/Cargo.lock index 2208438..88e911a 100644 --- a/gloom-rs/Cargo.lock +++ b/gloom-rs/Cargo.lock @@ -32,9 +32,9 @@ dependencies = [ [[package]] name = "arrayref" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" +checksum = "9d151e35f61089500b617991b791fc8bfd237ae50cd5950803758a179b41e67a" [[package]] name = "arrayvec" @@ -60,6 +60,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + [[package]] name = "block" version = "0.1.6" @@ -80,9 +86,9 @@ checksum = "17febce684fd15d89027105661fec94afb475cb995fbc59d2865198446ba2eea" [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "calloop" @@ -90,7 +96,7 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52e0d00eb1ea24371a97d2da6201c6747a633dc6dc1988ef503403b4c59504a8" dependencies = [ - "bitflags", + "bitflags 1.3.2", "log", "nix 0.25.1", "slotmap", @@ -124,9 +130,9 @@ dependencies = [ [[package]] name = "cmake" -version = "0.1.50" +version = "0.1.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" +checksum = "fb1e43aa7fd152b1f968787f7dbcdeb306d1867ff373c69955211876c053f91a" dependencies = [ "cc", ] @@ -137,27 +143,42 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f425db7937052c684daec3bd6375c8abe2d146dca4b8b143d6db777c39138f3a" dependencies = [ - "bitflags", + "bitflags 1.3.2", "block", "cocoa-foundation", "core-foundation", - "core-graphics", + "core-graphics 0.22.3", "foreign-types 0.3.2", "libc", "objc", ] +[[package]] +name = "cocoa" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6140449f97a6e97f9511815c5632d84c8aacf8ac271ad77c559218161a1373c" +dependencies = [ + "bitflags 1.3.2", + "block", + "cocoa-foundation", + "core-foundation", + "core-graphics 0.23.2", + "foreign-types 0.5.0", + "libc", + "objc", +] + [[package]] name = "cocoa-foundation" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "931d3837c286f56e3c58423ce4eba12d08db2374461a785c86f672b08b5650d6" +checksum = "8c6234cbb2e4c785b456c0644748b1ac416dd045799740356f8363dfe00c93f7" dependencies = [ - "bitflags", + "bitflags 1.3.2", "block", "core-foundation", "core-graphics-types", - "foreign-types 0.3.2", "libc", "objc", ] @@ -170,9 +191,9 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" [[package]] name = "core-foundation" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" dependencies = [ "core-foundation-sys", "libc", @@ -180,9 +201,9 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.4" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "core-graphics" @@ -190,33 +211,46 @@ version = "0.22.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation", "core-graphics-types", "foreign-types 0.3.2", "libc", ] +[[package]] +name = "core-graphics" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c07782be35f9e1140080c6b96f0d44b739e2278479f64e02fdab4e32dfd8b081" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "core-graphics-types", + "foreign-types 0.5.0", + "libc", +] + [[package]] name = "core-graphics-types" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bb142d41022986c1d8ff29103a1411c8a3dfad3552f87a4f8dc50d61d4f4e33" +checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation", "libc", ] [[package]] name = "core-text" -version = "19.2.0" +version = "20.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99d74ada66e07c1cefa18f8abfba765b486f250de2e4a999e5727fc0dd4b4a25" +checksum = "c9d2790b5c08465d49f8dc05c8bcae9fea467855947db39b0f8145c091aaced5" dependencies = [ "core-foundation", - "core-graphics", - "foreign-types 0.3.2", + "core-graphics 0.23.2", + "foreign-types 0.5.0", "libc", ] @@ -274,14 +308,14 @@ dependencies = [ [[package]] name = "crossfont" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21fd3add36ea31aba1520aa5288714dd63be506106753226d0eb387a93bc9c45" +checksum = "3eb5a3822b594afc99b503cc1859b94686d3c3efdd60507a28587dab80ee1071" dependencies = [ - "cocoa", + "cocoa 0.25.0", "core-foundation", "core-foundation-sys", - "core-graphics", + "core-graphics 0.23.2", "core-text", "dwrote", "foreign-types 0.5.0", @@ -359,9 +393,9 @@ dependencies = [ [[package]] name = "downcast-rs" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" +checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" [[package]] name = "dwrote" @@ -480,7 +514,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn 2.0.32", + "syn 2.0.75", ] [[package]] @@ -501,7 +535,7 @@ version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74eadec9d0a5c28c54bb9882e54787275152a4e36ce206b45d7451384e5bf5fb" dependencies = [ - "bitflags", + "bitflags 1.3.2", "freetype-sys", "libc", ] @@ -544,9 +578,9 @@ dependencies = [ [[package]] name = "gif" -version = "0.12.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80792593675e051cf94a4b111980da2ba60d4a83e43e0048c5693baab3977045" +checksum = "3fb2d69b19215e18bb912fa30f7ce15846e301408695e44e0ef719f1da9e19f2" dependencies = [ "color_quant", "weezl", @@ -592,7 +626,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "444c9ad294fdcaf20ccf6726b78f380b5450275540c9b68ab62f49726ad1c713" dependencies = [ "cgl", - "cocoa", + "cocoa 0.24.1", "core-foundation", "glutin_egl_sys", "glutin_gles2_sys", @@ -679,9 +713,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "image" -version = "0.24.7" +version = "0.24.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f3dfdbdd72063086ff443e297b61695500514b1e41095b6fb9a5ab48a70a711" +checksum = "5690139d2f55868e080017335e4b94cb7414274c74f1669c84fb5feba2c9f69d" dependencies = [ "bytemuck", "byteorder", @@ -689,7 +723,6 @@ dependencies = [ "exr", "gif", "jpeg-decoder", - "num-rational", "num-traits", "png", "qoi", @@ -708,9 +741,9 @@ dependencies = [ [[package]] name = "instant" -version = "0.1.12" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" dependencies = [ "cfg-if", "js-sys", @@ -750,9 +783,9 @@ checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "lebe" @@ -762,9 +795,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" [[package]] name = "libc" -version = "0.2.147" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "libloading" @@ -854,12 +887,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - [[package]] name = "miniz_oxide" version = "0.7.1" @@ -872,9 +899,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.8" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", "log", @@ -924,7 +951,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "451422b7e4718271c8b5b3aadf5adedba43dc76312454b387e98fae0fc951aa0" dependencies = [ - "bitflags", + "bitflags 1.3.2", "jni-sys", "ndk-sys", "num_enum", @@ -982,7 +1009,7 @@ version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if", "libc", "memoffset 0.6.5", @@ -995,22 +1022,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4" dependencies = [ "autocfg", - "bitflags", + "bitflags 1.3.2", "cfg-if", "libc", "memoffset 0.6.5", ] -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - [[package]] name = "num-complex" version = "0.4.4" @@ -1107,9 +1124,9 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", "parking_lot_core", @@ -1117,15 +1134,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.8" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -1136,9 +1153,9 @@ checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] name = "percent-encoding" -version = "2.3.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pin-project" @@ -1157,7 +1174,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.32", + "syn 2.0.75", ] [[package]] @@ -1172,7 +1189,7 @@ version = "0.17.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd75bf2d8dd3702b9707cdbc56a5b9ef42cec752eb8b3bafc01234558442aa64" dependencies = [ - "bitflags", + "bitflags 1.3.2", "crc32fast", "fdeflate", "flate2", @@ -1197,9 +1214,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -1215,9 +1232,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -1297,11 +1314,11 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.3.5" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" dependencies = [ - "bitflags", + "bitflags 2.6.0", ] [[package]] @@ -1348,22 +1365,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.186" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f5db24220c009de9bd45e69fb2938f4b6d2df856aa9304ce377b3180f83b7c1" +checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.186" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ad697f7e0b65af4983a4ce8f56ed5b357e8d3c36651bf6a7e13639c17b8e670" +checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.32", + "syn 2.0.75", ] [[package]] @@ -1418,9 +1435,9 @@ checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" [[package]] name = "slotmap" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1e08e261d0e8f5c43123b7adf3e4ca1690d655377ac93a03b2c9d3e98de1342" +checksum = "dbff4acf519f630b3a3ddcfaea6c06b42174d9a44bc70c620e9ed1649d58b82a" dependencies = [ "version_check", ] @@ -1433,11 +1450,11 @@ checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" [[package]] name = "smithay-client-toolkit" -version = "0.16.0" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f307c47d32d2715eb2e0ece5589057820e0e5e70d07c247d1063e844e107f454" +checksum = "870427e30b8f2cbe64bf43ec4b86e88fe39b0a84b3f15efd9c9c2d020bc86eb9" dependencies = [ - "bitflags", + "bitflags 1.3.2", "calloop", "dlib", "lazy_static", @@ -1478,9 +1495,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.32" +version = "2.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "239814284fd6f1a4ffe4ca893952cdd93c224b6a1571c9a9eadd670295c0c9e2" +checksum = "f6af063034fc1935ede7be0122941bafa9bacb949334d090b77ca98b5817c7d9" dependencies = [ "proc-macro2", "quote", @@ -1504,7 +1521,7 @@ checksum = "6bb623b56e39ab7dcd4b1b98bb6c8f8d907ed255b18de254088016b27a8ee19b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.32", + "syn 2.0.75", ] [[package]] @@ -1554,15 +1571,15 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" [[package]] name = "toml_edit" -version = "0.19.14" +version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8123f27e969974a3dfba720fdb560be359f57b44302d280ba72e76a74480e8a" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ "indexmap", "toml_datetime", @@ -1620,7 +1637,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.32", + "syn 2.0.75", "wasm-bindgen-shared", ] @@ -1642,7 +1659,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.32", + "syn 2.0.75", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1659,7 +1676,7 @@ version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f3b068c05a039c9f755f881dc50f01732214f5685e379829759088967c46715" dependencies = [ - "bitflags", + "bitflags 1.3.2", "downcast-rs", "libc", "nix 0.24.3", @@ -1708,7 +1725,7 @@ version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b950621f9354b322ee817a23474e479b34be96c2e909c14f7bc0100e9a970bc6" dependencies = [ - "bitflags", + "bitflags 1.3.2", "wayland-client", "wayland-commons", "wayland-scanner", @@ -1748,9 +1765,9 @@ dependencies = [ [[package]] name = "weezl" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" +checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" [[package]] name = "wide" @@ -1803,7 +1820,7 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -1812,21 +1829,43 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm", + "windows_aarch64_gnullvm 0.48.5", "windows_aarch64_msvc 0.48.5", "windows_i686_gnu 0.48.5", "windows_i686_msvc 0.48.5", "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm", + "windows_x86_64_gnullvm 0.48.5", "windows_x86_64_msvc 0.48.5", ] +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + [[package]] name = "windows_aarch64_msvc" version = "0.36.1" @@ -1839,6 +1878,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + [[package]] name = "windows_i686_gnu" version = "0.36.1" @@ -1851,6 +1896,18 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + [[package]] name = "windows_i686_msvc" version = "0.36.1" @@ -1863,6 +1920,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + [[package]] name = "windows_x86_64_gnu" version = "0.36.1" @@ -1875,12 +1938,24 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + [[package]] name = "windows_x86_64_msvc" version = "0.36.1" @@ -1893,16 +1968,22 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + [[package]] name = "winit" version = "0.27.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb796d6fbd86b2fd896c9471e6f04d39d750076ebe5680a3958f00f5ab97657c" dependencies = [ - "bitflags", - "cocoa", + "bitflags 1.3.2", + "cocoa 0.24.1", "core-foundation", - "core-graphics", + "core-graphics 0.22.3", "dispatch", "instant", "libc", @@ -1928,9 +2009,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.5.14" +version = "0.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d09770118a7eb1ccaf4a594a221334119a44a814fcb0d31c5b85e83e97227a97" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" dependencies = [ "memchr", ] @@ -1957,12 +2038,9 @@ dependencies = [ [[package]] name = "xcursor" -version = "0.3.4" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "463705a63313cd4301184381c5e8042f0a7e9b4bb63653f216311d4ae74690b7" -dependencies = [ - "nom", -] +checksum = "0ef33da6b1660b4ddbfb3aef0ade110c8b8a781a3b6382fa5f2b5b040fd55f61" [[package]] name = "xml-rs" @@ -1987,7 +2065,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.32", + "syn 2.0.75", ] [[package]] diff --git a/gloom-rs/Cargo.toml b/gloom-rs/Cargo.toml index 29f0ad8..b26857e 100644 --- a/gloom-rs/Cargo.toml +++ b/gloom-rs/Cargo.toml @@ -4,8 +4,9 @@ version = "0.3.0" authors = [ "Peder b. Sundt ", "Michael H. Gimle ", + "Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com>", ] -edition = "2018" # rust edition +edition = "2021" # rust edition # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/gloom-rs/src/main.rs b/gloom-rs/src/main.rs index 8e35230..9e21d4e 100644 --- a/gloom-rs/src/main.rs +++ b/gloom-rs/src/main.rs @@ -8,13 +8,19 @@ #![allow(unused_variables)] */ extern crate nalgebra_glm as glm; -use std::{ mem, ptr, os::raw::c_void }; -use std::sync::{Mutex, Arc, RwLock}; +use std::sync::{Arc, Mutex, RwLock}; +use std::{mem, os::raw::c_void, ptr}; mod shader; mod util; -use glutin::event::{Event, WindowEvent, DeviceEvent, KeyboardInput, ElementState::{Pressed, Released}, VirtualKeyCode::{self, *}}; +use glutin::event::{ + DeviceEvent, + ElementState::{Pressed, Released}, + Event, KeyboardInput, + VirtualKeyCode::{self, *}, + WindowEvent, +}; use glutin::event_loop::ControlFlow; // initial window size @@ -50,7 +56,6 @@ fn offset(n: u32) -> *const c_void { // Get a null pointer (equivalent to an offset of 0) // ptr::null() - // == // Generate your VAO here unsafe fn create_vao(vertices: &Vec, indices: &Vec) -> u32 { // Implement me! @@ -69,7 +74,6 @@ unsafe fn create_vao(vertices: &Vec, indices: &Vec) -> u32 { 0 } - fn main() { // Set up the necessary objects to deal with windows and event handling let el = glutin::event_loop::EventLoop::new(); @@ -77,8 +81,7 @@ fn main() { .with_title("Gloom-rs") .with_resizable(true) .with_inner_size(glutin::dpi::LogicalSize::new(INITIAL_SCREEN_W, INITIAL_SCREEN_H)); - let cb = glutin::ContextBuilder::new() - .with_vsync(true); + let cb = glutin::ContextBuilder::new().with_vsync(true); let windowed_context = cb.build_windowed(wb, &el).unwrap(); // Acquire the OpenGL Context and load the function pointers. let context = unsafe { windowed_context.make_current().unwrap() }; @@ -97,7 +100,6 @@ fn main() { // Set up shared tuple for tracking changes to the window size let arc_window_size = Arc::new(Mutex::new((INITIAL_SCREEN_W, INITIAL_SCREEN_H, false))); - let mut window_aspect_ratio = INITIAL_SCREEN_W as f32 / INITIAL_SCREEN_H as f32; // Set up openGL @@ -135,13 +137,10 @@ fn main() { let first_frame_time = std::time::Instant::now(); let mut previous_frame_time = first_frame_time; - // == // // == // From here on down there are only internals. // == // - - // Start the event loop -- This is where window events are initially handled el.run(move |event, _, control_flow| { *control_flow = ControlFlow::Wait; @@ -157,9 +156,14 @@ fn main() { *control_flow = ControlFlow::Exit; } // Keep track of currently pressed keys to send to the rendering thread - Event::WindowEvent { event: WindowEvent::KeyboardInput { - input: KeyboardInput { state: key_state, virtual_keycode: Some(keycode), .. }, .. }, .. } => { - + Event::WindowEvent { + event: + WindowEvent::KeyboardInput { + input: KeyboardInput { state: key_state, virtual_keycode: Some(keycode), .. }, + .. + }, + .. + } => { if let Ok(mut keys) = arc_pressed_keys.lock() { match key_state { Released => { @@ -167,7 +171,7 @@ fn main() { let i = keys.iter().position(|&k| k == keycode).unwrap(); keys.remove(i); } - }, + } Pressed => { if !keys.contains(&keycode) { keys.push(keycode); @@ -178,9 +182,13 @@ fn main() { // Handle Escape and Q keys separately match keycode { - Escape => { *control_flow = ControlFlow::Exit; } - Q => { *control_flow = ControlFlow::Exit; } - _ => { } + Escape => { + *control_flow = ControlFlow::Exit; + } + Q => { + *control_flow = ControlFlow::Exit; + } + _ => {} } } Event::DeviceEvent { event: DeviceEvent::MouseMotion { delta }, .. } => { @@ -194,7 +202,6 @@ fn main() { let my_vao = unsafe { 1337 }; - // == // Set up your shaders here // Basic usage of shader helper: @@ -212,7 +219,6 @@ fn main() { }; */ - // Used to demonstrate keyboard handling for exercise 2. let mut _arbitrary_number = 0.0; // feel free to remove @@ -228,7 +234,9 @@ fn main() { window_aspect_ratio = new_size.0 as f32 / new_size.1 as f32; (*new_size).2 = false; println!("Window was resized to {}x{}", new_size.0, new_size.1); - unsafe { gl::Viewport(0, 0, new_size.0 as i32, new_size.1 as i32); } + unsafe { + gl::Viewport(0, 0, new_size.0 as i32, new_size.1 as i32); + } } } @@ -238,7 +246,6 @@ fn main() { match key { // The `VirtualKeyCode` enum is defined here: // https://docs.rs/winit/0.25.0/winit/event/enum.VirtualKeyCode.html - VirtualKeyCode::A => { _arbitrary_number += delta_time; } @@ -246,15 +253,13 @@ fn main() { _arbitrary_number -= delta_time; } - // default handler: - _ => { } + _ => {} } } } // Handle mouse movement. delta contains the x and y movement of the mouse since last frame in pixels if let Ok(mut delta) = arc_mouse_delta.lock() { - // == // Optionally access the accumulated mouse movement between // == // frames here with `delta.0` and `delta.1` @@ -263,23 +268,18 @@ fn main() { // == // Please compute camera transforms here (exercise 2 & 3) - unsafe { // Clear the color and depth buffers gl::ClearColor(0.035, 0.046, 0.078, 1.0); // night sky gl::Clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT); - // == // Issue the necessary gl:: commands to draw your scene here - - - } // Display the new color buffer on the display context.swap_buffers().unwrap(); // we use "double buffering" to avoid artifacts } - _ => { } + _ => {} } }); } diff --git a/gloom-rs/src/shader.rs b/gloom-rs/src/shader.rs index 64895d9..4cd5cce 100644 --- a/gloom-rs/src/shader.rs +++ b/gloom-rs/src/shader.rs @@ -1,10 +1,5 @@ use gl; -use std::{ - ptr, - str, - ffi::CString, - path::Path, -}; +use std::{ffi::CString, path::Path, ptr, str}; pub struct Shader { pub program_id: u32, @@ -12,7 +7,7 @@ pub struct Shader { pub struct ShaderBuilder { program_id: u32, - shaders: Vec::, + shaders: Vec, } #[allow(dead_code)] @@ -39,11 +34,11 @@ impl Shader { impl Into for ShaderType { fn into(self) -> gl::types::GLenum { match self { - ShaderType::Vertex => { gl::VERTEX_SHADER }, - ShaderType::Fragment => { gl::FRAGMENT_SHADER }, - ShaderType::TessellationControl => { gl::TESS_CONTROL_SHADER }, - ShaderType::TessellationEvaluation => { gl::TESS_EVALUATION_SHADER } , - ShaderType::Geometry => { gl::GEOMETRY_SHADER }, + ShaderType::Vertex => gl::VERTEX_SHADER, + ShaderType::Fragment => gl::FRAGMENT_SHADER, + ShaderType::TessellationControl => gl::TESS_CONTROL_SHADER, + ShaderType::TessellationEvaluation => gl::TESS_EVALUATION_SHADER, + ShaderType::Geometry => gl::GEOMETRY_SHADER, } } } @@ -51,29 +46,25 @@ impl Into for ShaderType { impl ShaderType { fn from_ext(ext: &std::ffi::OsStr) -> Result { match ext.to_str().expect("Failed to read extension") { - "vert" => { Ok(ShaderType::Vertex) }, - "frag" => { Ok(ShaderType::Fragment) }, - "tcs" => { Ok(ShaderType::TessellationControl) }, - "tes" => { Ok(ShaderType::TessellationEvaluation) }, - "geom" => { Ok(ShaderType::Geometry) }, - e => { Err(e.to_string()) }, + "vert" => Ok(ShaderType::Vertex), + "frag" => Ok(ShaderType::Fragment), + "tcs" => Ok(ShaderType::TessellationControl), + "tes" => Ok(ShaderType::TessellationEvaluation), + "geom" => Ok(ShaderType::Geometry), + e => Err(e.to_string()), } } } impl ShaderBuilder { pub unsafe fn new() -> ShaderBuilder { - ShaderBuilder { - program_id: gl::CreateProgram(), - shaders: vec![], - } + ShaderBuilder { program_id: gl::CreateProgram(), shaders: vec![] } } pub unsafe fn attach_file(self, shader_path: &str) -> ShaderBuilder { let path = Path::new(shader_path); if let Some(extension) = path.extension() { - let shader_type = ShaderType::from_ext(extension) - .expect("Failed to parse file extension."); + let shader_type = ShaderType::from_ext(extension).expect("Failed to parse file extension."); let shader_src = std::fs::read_to_string(path) .expect(&format!("Failed to read shader source. {}", shader_path)); self.compile_shader(&shader_src, shader_type) @@ -147,8 +138,6 @@ impl ShaderBuilder { gl::DeleteShader(shader); } - Shader { - program_id: self.program_id - } + Shader { program_id: self.program_id } } } diff --git a/gloom-rs/src/util.rs b/gloom-rs/src/util.rs index 83938c1..a1e5a40 100644 --- a/gloom-rs/src/util.rs +++ b/gloom-rs/src/util.rs @@ -1,5 +1,5 @@ -use std::ffi::CString; use libc; +use std::ffi::CString; pub unsafe fn get_gl_string(name: gl::types::GLenum) -> String { std::ffi::CStr::from_ptr(gl::GetString(name) as *mut libc::c_char).to_string_lossy().to_string() @@ -7,14 +7,20 @@ pub unsafe fn get_gl_string(name: gl::types::GLenum) -> String { // Debug callback to panic upon encountering any OpenGL error pub extern "system" fn debug_callback( - source: u32, e_type: u32, id: u32, - severity: u32, _length: i32, - msg: *const libc::c_char, _data: *mut std::ffi::c_void + source: u32, + e_type: u32, + id: u32, + severity: u32, + _length: i32, + msg: *const libc::c_char, + _data: *mut std::ffi::c_void, ) { - if e_type != gl::DEBUG_TYPE_ERROR { return } - if severity == gl::DEBUG_SEVERITY_HIGH || - severity == gl::DEBUG_SEVERITY_MEDIUM || - severity == gl::DEBUG_SEVERITY_LOW + if e_type != gl::DEBUG_TYPE_ERROR { + return; + } + if severity == gl::DEBUG_SEVERITY_HIGH + || severity == gl::DEBUG_SEVERITY_MEDIUM + || severity == gl::DEBUG_SEVERITY_LOW { let severity_string = match severity { gl::DEBUG_SEVERITY_HIGH => "high", @@ -25,8 +31,10 @@ pub extern "system" fn debug_callback( unsafe { let string = CString::from_raw(msg as *mut libc::c_char); let error_message = String::from_utf8_lossy(string.as_bytes()).to_string(); - panic!("{}: Error of severity {} raised from {}: {}\n", - id, severity_string, source, error_message); + panic!( + "{}: Error of severity {} raised from {}: {}\n", + id, severity_string, source, error_message + ); } } } From e1b1d394b0e3b2aaa69bf106b3d5d56b35f7e2ee Mon Sep 17 00:00:00 2001 From: Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com> Date: Tue, 20 Aug 2024 05:10:47 +0200 Subject: [PATCH 02/12] updated files and changed tab spaces to 3 (looks better) --- gloom-rs/.rustfmt.toml | 2 +- gloom-rs/Cargo.lock | 542 +++++++++++++++++++++++++++++++++++++++-- gloom-rs/Cargo.toml | 6 +- gloom-rs/src/main.rs | 442 ++++++++++++++++----------------- gloom-rs/src/shader.rs | 238 +++++++++--------- gloom-rs/src/util.rs | 57 ++--- 6 files changed, 894 insertions(+), 393 deletions(-) diff --git a/gloom-rs/.rustfmt.toml b/gloom-rs/.rustfmt.toml index d1e5bd9..a9ef535 100644 --- a/gloom-rs/.rustfmt.toml +++ b/gloom-rs/.rustfmt.toml @@ -1,7 +1,7 @@ edition = "2021" max_width = 110 hard_tabs = false -tab_spaces = 4 +tab_spaces = 3 newline_style = "Unix" use_small_heuristics = "Max" indent_style = "Block" diff --git a/gloom-rs/Cargo.lock b/gloom-rs/Cargo.lock index 88e911a..5ad1655 100644 --- a/gloom-rs/Cargo.lock +++ b/gloom-rs/Cargo.lock @@ -21,6 +21,18 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "aligned-vec" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4aa90d7ce82d4be67b64039a3d588d38dbcc6736577de4a847025ce5b0c468d1" + +[[package]] +name = "anyhow" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" + [[package]] name = "approx" version = "0.5.1" @@ -30,6 +42,23 @@ dependencies = [ "num-traits", ] +[[package]] +name = "arbitrary" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db55d72333851e17d572bec876e390cd3b11eb1ef53ae821dd9f3b653d2b4569" + +[[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 2.0.75", +] + [[package]] name = "arrayref" version = "0.3.8" @@ -42,12 +71,45 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" +dependencies = [ + "serde", +] + [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "av1-grain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6678909d8c5d46a42abcf571271e15fdbc0a225e3646cf23762cd415046c78bf" +dependencies = [ + "anyhow", + "arrayvec 0.7.6", + "log", + "nom", + "num-rational", + "serde", + "v_frame", +] + +[[package]] +name = "avif-serialize" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "876c75a42f6364451a033496a14c44bffe41f5f4a8236f697391f11024e596d2" +dependencies = [ + "arrayvec 0.7.6", +] + [[package]] name = "bit_field" version = "0.10.2" @@ -66,12 +128,27 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "bitstream-io" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e445576659fd04a57b44cbd00aa37aaa815ebefa0aa3cb677a6b5e63d883074f" + [[package]] name = "block" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" +[[package]] +name = "built" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9c056b9ed43aee5e064b683aa1ec783e19c6acec7559e3ae931b7490472fbe" +dependencies = [ + "cargo-lock", +] + [[package]] name = "bumpalo" version = "3.13.0" @@ -85,10 +162,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17febce684fd15d89027105661fec94afb475cb995fbc59d2865198446ba2eea" [[package]] -name = "byteorder" -version = "1.5.0" +name = "byteorder-lite" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495" [[package]] name = "calloop" @@ -104,6 +181,18 @@ dependencies = [ "vec_map", ] +[[package]] +name = "cargo-lock" +version = "8.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031718ddb8f78aa5def78a09e90defe30151d1f6c672f937af4dd916429ed996" +dependencies = [ + "semver", + "serde", + "toml 0.5.11", + "url", +] + [[package]] name = "cc" version = "1.0.83" @@ -113,6 +202,16 @@ dependencies = [ "libc", ] +[[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" @@ -529,6 +628,15 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + [[package]] name = "freetype-rs" version = "0.26.0" @@ -699,6 +807,12 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.3.2" @@ -711,24 +825,55 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "image" -version = "0.24.9" +version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5690139d2f55868e080017335e4b94cb7414274c74f1669c84fb5feba2c9f69d" +checksum = "99314c8a2152b8ddb211f924cdae532d8c5e4c8bb54728e12fff1b0cd5963a10" dependencies = [ "bytemuck", - "byteorder", + "byteorder-lite", "color_quant", "exr", "gif", - "jpeg-decoder", + "image-webp", "num-traits", "png", "qoi", + "ravif", + "rayon", + "rgb", "tiff", + "zune-core", + "zune-jpeg", +] + +[[package]] +name = "image-webp" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f79afb8cbee2ef20f59ccd477a218c12a93943d075b492015ecb1bb81f8ee904" +dependencies = [ + "byteorder-lite", + "quick-error", ] +[[package]] +name = "imgref" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44feda355f4159a7c757171a77de25daf6411e217b4cabd03bd6650690468126" + [[package]] name = "indexmap" version = "2.0.0" @@ -751,6 +896,26 @@ dependencies = [ "web-sys", ] +[[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 2.0.75", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + [[package]] name = "jni-sys" version = "0.3.0" @@ -762,9 +927,6 @@ name = "jpeg-decoder" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e" -dependencies = [ - "rayon", -] [[package]] name = "js-sys" @@ -799,6 +961,16 @@ version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +[[package]] +name = "libfuzzer-sys" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcf184a4b6b274f82a5df6b357da6055d3e82272327bba281c28bbba6f1664ef" +dependencies = [ + "arbitrary", + "cc", +] + [[package]] name = "libloading" version = "0.7.4" @@ -835,6 +1007,15 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +[[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" @@ -854,6 +1035,16 @@ dependencies = [ "rawpointer", ] +[[package]] +name = "maybe-rayon" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea1f30cedd69f0a2954655f7188c6a834246d2bcf1e315e2ac40c4b24dc9519" +dependencies = [ + "cfg-if", + "rayon", +] + [[package]] name = "memchr" version = "2.5.0" @@ -887,6 +1078,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.7.1" @@ -911,9 +1108,9 @@ dependencies = [ [[package]] name = "nalgebra" -version = "0.31.4" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20bd243ab3dbb395b39ee730402d2e5405e448c75133ec49cc977762c4cba3d1" +checksum = "3c4b5f057b303842cf3262c27e465f4c303572e7f6b0648f60e16248ac3397f4" dependencies = [ "approx", "matrixmultiply", @@ -926,9 +1123,9 @@ dependencies = [ [[package]] name = "nalgebra-glm" -version = "0.17.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8e68654c920c582d34a4180c527ce2acf9ec8c695363681ff42acde46239d43" +checksum = "e441f43bccdf40cb6bd4294321e6983c5bc7b9886112d19fd4c9813976b117e4" dependencies = [ "approx", "nalgebra", @@ -1003,6 +1200,12 @@ 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 = "nix" version = "0.24.3" @@ -1028,6 +1231,33 @@ dependencies = [ "memoffset 0.6.5", ] +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "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 = "num-bigint" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-complex" version = "0.4.4" @@ -1037,6 +1267,17 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-derive" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "num-integer" version = "0.1.45" @@ -1054,6 +1295,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" dependencies = [ "autocfg", + "num-bigint", "num-integer", "num-traits", ] @@ -1209,7 +1451,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" dependencies = [ "once_cell", - "toml_edit", + "toml_edit 0.19.15", ] [[package]] @@ -1230,6 +1472,12 @@ dependencies = [ "bytemuck", ] +[[package]] +name = "quick-error" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" + [[package]] name = "quote" version = "1.0.36" @@ -1269,6 +1517,57 @@ dependencies = [ "getrandom", ] +[[package]] +name = "rav1e" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16c383692a5e7abd9f6d1eddb1a5e0269f859392387883361bb09e5555852ec1" +dependencies = [ + "arbitrary", + "arg_enum_proc_macro", + "arrayvec 0.7.6", + "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", + "rand", + "rand_chacha", + "rust_hawktracer", + "rustc_version", + "simd_helpers", + "system-deps", + "thiserror", + "v_frame", + "wasm-bindgen", +] + +[[package]] +name = "ravif" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "badc69028460108fa7e32d4aec2b0c980710d7a31a896864002c8c1fc61516ee" +dependencies = [ + "avif-serialize", + "imgref", + "loop9", + "quick-error", + "rav1e", + "rayon", + "rgb", +] + [[package]] name = "raw-window-handle" version = "0.4.3" @@ -1321,6 +1620,46 @@ dependencies = [ "bitflags 2.6.0", ] +[[package]] +name = "rgb" +version = "0.8.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05aaa8004b64fd573fc9d002f4e632d51ad4f026c2b5ba95fcb6c2f32c2c47d8" +dependencies = [ + "bytemuck", +] + +[[package]] +name = "rust_hawktracer" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3480a29b927f66c6e06527be7f49ef4d291a01d694ec1fe85b0de71d6b02ac1" +dependencies = [ + "rust_hawktracer_normal_macro", + "rust_hawktracer_proc_macro", +] + +[[package]] +name = "rust_hawktracer_normal_macro" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a570059949e1dcdc6f35228fa389f54c2c84dfe0c94c05022baacd56eacd2e9" + +[[package]] +name = "rust_hawktracer_proc_macro" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb626abdbed5e93f031baae60d72032f56bc964e11ac2ff65f2ba3ed98d6d3e1" + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + [[package]] name = "safe_arch" version = "0.5.2" @@ -1363,6 +1702,15 @@ dependencies = [ "tiny-skia", ] +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" +dependencies = [ + "serde", +] + [[package]] name = "serde" version = "1.0.208" @@ -1383,6 +1731,15 @@ dependencies = [ "syn 2.0.75", ] +[[package]] +name = "serde_spanned" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +dependencies = [ + "serde", +] + [[package]] name = "servo-fontconfig" version = "0.5.1" @@ -1416,9 +1773,9 @@ dependencies = [ [[package]] name = "simba" -version = "0.7.3" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f3fd720c48c53cace224ae62bef1bbff363a70c68c4802a78b5cc6159618176" +checksum = "b3a386a501cd104797982c15ae17aafe8b9261315b5d07e3ec803f2ea26be0fa" dependencies = [ "approx", "num-complex", @@ -1433,6 +1790,15 @@ 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 = "slotmap" version = "1.0.7" @@ -1504,6 +1870,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", + "pkg-config", + "toml 0.8.19", + "version-compare", +] + +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + [[package]] name = "thiserror" version = "1.0.47" @@ -1542,7 +1927,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "642680569bb895b16e4b9d181c60be1ed136fa0c9c7f11d004daf053ba89bf82" dependencies = [ "arrayref", - "arrayvec", + "arrayvec 0.5.2", "bytemuck", "cfg-if", "png", @@ -1560,6 +1945,21 @@ dependencies = [ "bytemuck", ] +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "tobj" version = "4.0.2" @@ -1569,11 +1969,35 @@ dependencies = [ "ahash", ] +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "toml" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit 0.22.20", +] + [[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" @@ -1583,7 +2007,20 @@ checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ "indexmap", "toml_datetime", - "winnow", + "winnow 0.5.40", +] + +[[package]] +name = "toml_edit" +version = "0.22.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow 0.6.18", ] [[package]] @@ -1592,18 +2029,61 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + [[package]] name = "unicode-ident" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "v_frame" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6f32aaa24bacd11e488aa9ba66369c7cd514885742c9fe08cfe85884db3e92b" +dependencies = [ + "aligned-vec", + "num-traits", + "wasm-bindgen", +] + [[package]] name = "vec_map" version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +[[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.4" @@ -2016,6 +2496,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "winnow" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +dependencies = [ + "memchr", +] + [[package]] name = "wio" version = "0.2.2" @@ -2068,6 +2557,12 @@ dependencies = [ "syn 2.0.75", ] +[[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" @@ -2076,3 +2571,12 @@ checksum = "73ab332fe2f6680068f3582b16a24f90ad7096d5d39b974d1c0aff0125116f02" dependencies = [ "simd-adler32", ] + +[[package]] +name = "zune-jpeg" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16099418600b4d8f028622f73ff6e3deaabdff330fb9a2a131dea781ee8b0768" +dependencies = [ + "zune-core", +] diff --git a/gloom-rs/Cargo.toml b/gloom-rs/Cargo.toml index b26857e..14e6821 100644 --- a/gloom-rs/Cargo.toml +++ b/gloom-rs/Cargo.toml @@ -13,8 +13,8 @@ edition = "2021" # rust edition [dependencies] glutin = "0.29.1" gl = "0.14.0" -tobj = ">3.1.0" -image = "0.24.3" -nalgebra-glm = "0.17.0" +tobj = "4.0.2" +image = "0.25.2" +nalgebra-glm = "0.19.0" rand = "0.8.4" libc = "0.2.132" diff --git a/gloom-rs/src/main.rs b/gloom-rs/src/main.rs index 9e21d4e..c979d2c 100644 --- a/gloom-rs/src/main.rs +++ b/gloom-rs/src/main.rs @@ -15,11 +15,11 @@ mod shader; mod util; use glutin::event::{ - DeviceEvent, - ElementState::{Pressed, Released}, - Event, KeyboardInput, - VirtualKeyCode::{self, *}, - WindowEvent, + DeviceEvent, + ElementState::{Pressed, Released}, + Event, KeyboardInput, + VirtualKeyCode::{self, *}, + WindowEvent, }; use glutin::event_loop::ControlFlow; @@ -32,25 +32,25 @@ const INITIAL_SCREEN_H: u32 = 600; // Get the size of an arbitrary array of numbers measured in bytes // Example usage: byte_size_of_array(my_array) fn byte_size_of_array(val: &[T]) -> isize { - std::mem::size_of_val(&val[..]) as isize + std::mem::size_of_val(&val[..]) as isize } // Get the OpenGL-compatible pointer to an arbitrary array of numbers // Example usage: pointer_to_array(my_array) fn pointer_to_array(val: &[T]) -> *const c_void { - &val[0] as *const T as *const c_void + &val[0] as *const T as *const c_void } // Get the size of the given type in bytes // Example usage: size_of::() fn size_of() -> i32 { - mem::size_of::() as i32 + mem::size_of::() as i32 } // Get an offset in bytes for n units of type T, represented as a relative pointer // Example usage: offset::(4) fn offset(n: u32) -> *const c_void { - (n * mem::size_of::() as u32) as *const T as *const c_void + (n * mem::size_of::() as u32) as *const T as *const c_void } // Get a null pointer (equivalent to an offset of 0) @@ -58,228 +58,228 @@ fn offset(n: u32) -> *const c_void { // == // Generate your VAO here unsafe fn create_vao(vertices: &Vec, indices: &Vec) -> u32 { - // Implement me! + // Implement me! - // Also, feel free to delete comments :) + // Also, feel free to delete comments :) - // This should: - // * Generate a VAO and bind it - // * Generate a VBO and bind it - // * Fill it with data - // * Configure a VAP for the data and enable it - // * Generate a IBO and bind it - // * Fill it with data - // * Return the ID of the VAO + // This should: + // * Generate a VAO and bind it + // * Generate a VBO and bind it + // * Fill it with data + // * Configure a VAP for the data and enable it + // * Generate a IBO and bind it + // * Fill it with data + // * Return the ID of the VAO - 0 + 0 } fn main() { - // Set up the necessary objects to deal with windows and event handling - let el = glutin::event_loop::EventLoop::new(); - let wb = glutin::window::WindowBuilder::new() - .with_title("Gloom-rs") - .with_resizable(true) - .with_inner_size(glutin::dpi::LogicalSize::new(INITIAL_SCREEN_W, INITIAL_SCREEN_H)); - let cb = glutin::ContextBuilder::new().with_vsync(true); - let windowed_context = cb.build_windowed(wb, &el).unwrap(); - // Acquire the OpenGL Context and load the function pointers. - let context = unsafe { windowed_context.make_current().unwrap() }; - gl::load_with(|symbol| context.get_proc_address(symbol) as *const _); - - // Uncomment these if you want to use the mouse for controls, but want it to be confined to the screen and/or invisible. - // windowed_context.window().set_cursor_grab(true).expect("failed to grab cursor"); - // windowed_context.window().set_cursor_visible(false); - - // Set up a shared vector for keeping track of currently pressed keys - let arc_pressed_keys = Arc::new(Mutex::new(Vec::::with_capacity(10))); - - // Set up shared tuple for tracking mouse movement between frames - let arc_mouse_delta = Arc::new(Mutex::new((0f32, 0f32))); - - // Set up shared tuple for tracking changes to the window size - let arc_window_size = Arc::new(Mutex::new((INITIAL_SCREEN_W, INITIAL_SCREEN_H, false))); - - let mut window_aspect_ratio = INITIAL_SCREEN_W as f32 / INITIAL_SCREEN_H as f32; - - // Set up openGL - unsafe { - gl::Enable(gl::DEPTH_TEST); - gl::DepthFunc(gl::LESS); - gl::Enable(gl::CULL_FACE); - gl::Disable(gl::MULTISAMPLE); - gl::Enable(gl::BLEND); - gl::BlendFunc(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA); - - // Query OpenGL version - let version = util::get_gl_string(gl::VERSION); - let version_major: u32 = version.chars().next().unwrap().to_digit(10).unwrap(); - let version_minor: u32 = version.chars().nth(2).unwrap().to_digit(10).unwrap(); - - // MacOS uses OpenGL 4.1, which doesn't support the debug output functionality introduced in OpenGL 4.3 - if (version_major > 4) || (version_major == 4 && version_minor >= 3) { - gl::Enable(gl::DEBUG_OUTPUT_SYNCHRONOUS); - gl::DebugMessageCallback(Some(util::debug_callback), ptr::null()); - } else { - // Simple error checking - let error = gl::GetError(); - if error != gl::NO_ERROR { - println!("OpenGL Error: {}", error); + // Set up the necessary objects to deal with windows and event handling + let el = glutin::event_loop::EventLoop::new(); + let wb = glutin::window::WindowBuilder::new() + .with_title("Gloom-rs") + .with_resizable(true) + .with_inner_size(glutin::dpi::LogicalSize::new(INITIAL_SCREEN_W, INITIAL_SCREEN_H)); + let cb = glutin::ContextBuilder::new().with_vsync(true); + let windowed_context = cb.build_windowed(wb, &el).unwrap(); + // Acquire the OpenGL Context and load the function pointers. + let context = unsafe { windowed_context.make_current().unwrap() }; + gl::load_with(|symbol| context.get_proc_address(symbol) as *const _); + + // Uncomment these if you want to use the mouse for controls, but want it to be confined to the screen and/or invisible. + // windowed_context.window().set_cursor_grab(true).expect("failed to grab cursor"); + // windowed_context.window().set_cursor_visible(false); + + // Set up a shared vector for keeping track of currently pressed keys + let arc_pressed_keys = Arc::new(Mutex::new(Vec::::with_capacity(10))); + + // Set up shared tuple for tracking mouse movement between frames + let arc_mouse_delta = Arc::new(Mutex::new((0f32, 0f32))); + + // Set up shared tuple for tracking changes to the window size + let arc_window_size = Arc::new(Mutex::new((INITIAL_SCREEN_W, INITIAL_SCREEN_H, false))); + + let mut window_aspect_ratio = INITIAL_SCREEN_W as f32 / INITIAL_SCREEN_H as f32; + + // Set up openGL + unsafe { + gl::Enable(gl::DEPTH_TEST); + gl::DepthFunc(gl::LESS); + gl::Enable(gl::CULL_FACE); + gl::Disable(gl::MULTISAMPLE); + gl::Enable(gl::BLEND); + gl::BlendFunc(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA); + + // Query OpenGL version + let version = util::get_gl_string(gl::VERSION); + let version_major: u32 = version.chars().next().unwrap().to_digit(10).unwrap(); + let version_minor: u32 = version.chars().nth(2).unwrap().to_digit(10).unwrap(); + + // MacOS uses OpenGL 4.1, which doesn't support the debug output functionality introduced in OpenGL 4.3 + if (version_major > 4) || (version_major == 4 && version_minor >= 3) { + gl::Enable(gl::DEBUG_OUTPUT_SYNCHRONOUS); + gl::DebugMessageCallback(Some(util::debug_callback), ptr::null()); + } else { + // Simple error checking + let error = gl::GetError(); + if error != gl::NO_ERROR { + println!("OpenGL Error: {}", error); + } + } + + // Print some diagnostics + println!("{}: {}", util::get_gl_string(gl::VENDOR), util::get_gl_string(gl::RENDERER)); + println!("OpenGL\t: {}", util::get_gl_string(gl::VERSION)); + println!("GLSL\t: {}", util::get_gl_string(gl::SHADING_LANGUAGE_VERSION)); + } + + let first_frame_time = std::time::Instant::now(); + let mut previous_frame_time = first_frame_time; + + // == // + // == // From here on down there are only internals. + // == // + + // Start the event loop -- This is where window events are initially handled + el.run(move |event, _, control_flow| { + *control_flow = ControlFlow::Wait; + + match event { + Event::WindowEvent { event: WindowEvent::Resized(physical_size), .. } => { + println!("New window size received: {}x{}", physical_size.width, physical_size.height); + if let Ok(mut new_size) = arc_window_size.lock() { + *new_size = (physical_size.width, physical_size.height, true); } - } - - // Print some diagnostics - println!("{}: {}", util::get_gl_string(gl::VENDOR), util::get_gl_string(gl::RENDERER)); - println!("OpenGL\t: {}", util::get_gl_string(gl::VERSION)); - println!("GLSL\t: {}", util::get_gl_string(gl::SHADING_LANGUAGE_VERSION)); - } - - let first_frame_time = std::time::Instant::now(); - let mut previous_frame_time = first_frame_time; - - // == // - // == // From here on down there are only internals. - // == // - - // Start the event loop -- This is where window events are initially handled - el.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Wait; - - match event { - Event::WindowEvent { event: WindowEvent::Resized(physical_size), .. } => { - println!("New window size received: {}x{}", physical_size.width, physical_size.height); - if let Ok(mut new_size) = arc_window_size.lock() { - *new_size = (physical_size.width, physical_size.height, true); - } + } + Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { + *control_flow = ControlFlow::Exit; + } + // Keep track of currently pressed keys to send to the rendering thread + Event::WindowEvent { + event: + WindowEvent::KeyboardInput { + input: KeyboardInput { state: key_state, virtual_keycode: Some(keycode), .. }, + .. + }, + .. + } => { + if let Ok(mut keys) = arc_pressed_keys.lock() { + match key_state { + Released => { + if keys.contains(&keycode) { + let i = keys.iter().position(|&k| k == keycode).unwrap(); + keys.remove(i); + } + } + Pressed => { + if !keys.contains(&keycode) { + keys.push(keycode); + } + } + } } - Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { - *control_flow = ControlFlow::Exit; + + // Handle Escape and Q keys separately + match keycode { + Escape => { + *control_flow = ControlFlow::Exit; + } + Q => { + *control_flow = ControlFlow::Exit; + } + _ => {} } - // Keep track of currently pressed keys to send to the rendering thread - Event::WindowEvent { - event: - WindowEvent::KeyboardInput { - input: KeyboardInput { state: key_state, virtual_keycode: Some(keycode), .. }, - .. - }, - .. - } => { - if let Ok(mut keys) = arc_pressed_keys.lock() { - match key_state { - Released => { - if keys.contains(&keycode) { - let i = keys.iter().position(|&k| k == keycode).unwrap(); - keys.remove(i); - } - } - Pressed => { - if !keys.contains(&keycode) { - keys.push(keycode); - } - } - } - } - - // Handle Escape and Q keys separately - match keycode { - Escape => { - *control_flow = ControlFlow::Exit; - } - Q => { - *control_flow = ControlFlow::Exit; - } - _ => {} - } + } + Event::DeviceEvent { event: DeviceEvent::MouseMotion { delta }, .. } => { + // Accumulate mouse movement + if let Ok(mut position) = arc_mouse_delta.lock() { + *position = (position.0 + delta.0 as f32, position.1 + delta.1 as f32); } - Event::DeviceEvent { event: DeviceEvent::MouseMotion { delta }, .. } => { - // Accumulate mouse movement - if let Ok(mut position) = arc_mouse_delta.lock() { - *position = (position.0 + delta.0 as f32, position.1 + delta.1 as f32); - } + } + Event::MainEventsCleared => { + // == // Set up your VAO around here + + let my_vao = unsafe { 1337 }; + + // == // Set up your shaders here + + // Basic usage of shader helper: + // The example code below creates a 'shader' object. + // It which contains the field `.program_id` and the method `.activate()`. + // The `.` in the path is relative to `Cargo.toml`. + // This snippet is not enough to do the exercise, and will need to be modified (outside + // of just using the correct path), but it only needs to be called once + + /* + let simple_shader = unsafe { + shader::ShaderBuilder::new() + .attach_file("./path/to/simple/shader.file") + .link() + }; + */ + + // Used to demonstrate keyboard handling for exercise 2. + let mut _arbitrary_number = 0.0; // feel free to remove + + // Compute time passed since the previous frame and since the start of the program + let now = std::time::Instant::now(); + let elapsed = now.duration_since(first_frame_time).as_secs_f32(); + let delta_time = now.duration_since(previous_frame_time).as_secs_f32(); + previous_frame_time = now; + + if let Ok(mut new_size) = arc_window_size.lock() { + if new_size.2 { + context.resize(glutin::dpi::PhysicalSize::new(new_size.0, new_size.1)); + window_aspect_ratio = new_size.0 as f32 / new_size.1 as f32; + (*new_size).2 = false; + println!("Window was resized to {}x{}", new_size.0, new_size.1); + unsafe { + gl::Viewport(0, 0, new_size.0 as i32, new_size.1 as i32); + } + } } - Event::MainEventsCleared => { - // == // Set up your VAO around here - - let my_vao = unsafe { 1337 }; - - // == // Set up your shaders here - - // Basic usage of shader helper: - // The example code below creates a 'shader' object. - // It which contains the field `.program_id` and the method `.activate()`. - // The `.` in the path is relative to `Cargo.toml`. - // This snippet is not enough to do the exercise, and will need to be modified (outside - // of just using the correct path), but it only needs to be called once - - /* - let simple_shader = unsafe { - shader::ShaderBuilder::new() - .attach_file("./path/to/simple/shader.file") - .link() - }; - */ - - // Used to demonstrate keyboard handling for exercise 2. - let mut _arbitrary_number = 0.0; // feel free to remove - - // Compute time passed since the previous frame and since the start of the program - let now = std::time::Instant::now(); - let elapsed = now.duration_since(first_frame_time).as_secs_f32(); - let delta_time = now.duration_since(previous_frame_time).as_secs_f32(); - previous_frame_time = now; - - if let Ok(mut new_size) = arc_window_size.lock() { - if new_size.2 { - context.resize(glutin::dpi::PhysicalSize::new(new_size.0, new_size.1)); - window_aspect_ratio = new_size.0 as f32 / new_size.1 as f32; - (*new_size).2 = false; - println!("Window was resized to {}x{}", new_size.0, new_size.1); - unsafe { - gl::Viewport(0, 0, new_size.0 as i32, new_size.1 as i32); - } - } - } - - // Handle keyboard input - if let Ok(keys) = arc_pressed_keys.lock() { - for key in keys.iter() { - match key { - // The `VirtualKeyCode` enum is defined here: - // https://docs.rs/winit/0.25.0/winit/event/enum.VirtualKeyCode.html - VirtualKeyCode::A => { - _arbitrary_number += delta_time; - } - VirtualKeyCode::D => { - _arbitrary_number -= delta_time; - } - - // default handler: - _ => {} - } - } - } - // Handle mouse movement. delta contains the x and y movement of the mouse since last frame in pixels - if let Ok(mut delta) = arc_mouse_delta.lock() { - // == // Optionally access the accumulated mouse movement between - // == // frames here with `delta.0` and `delta.1` - - *delta = (0.0, 0.0); // reset when done - } - - // == // Please compute camera transforms here (exercise 2 & 3) - - unsafe { - // Clear the color and depth buffers - gl::ClearColor(0.035, 0.046, 0.078, 1.0); // night sky - gl::Clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT); - - // == // Issue the necessary gl:: commands to draw your scene here - } - - // Display the new color buffer on the display - context.swap_buffers().unwrap(); // we use "double buffering" to avoid artifacts + + // Handle keyboard input + if let Ok(keys) = arc_pressed_keys.lock() { + for key in keys.iter() { + match key { + // The `VirtualKeyCode` enum is defined here: + // https://docs.rs/winit/0.25.0/winit/event/enum.VirtualKeyCode.html + VirtualKeyCode::A => { + _arbitrary_number += delta_time; + } + VirtualKeyCode::D => { + _arbitrary_number -= delta_time; + } + + // default handler: + _ => {} + } + } } - _ => {} - } - }); + // Handle mouse movement. delta contains the x and y movement of the mouse since last frame in pixels + if let Ok(mut delta) = arc_mouse_delta.lock() { + // == // Optionally access the accumulated mouse movement between + // == // frames here with `delta.0` and `delta.1` + + *delta = (0.0, 0.0); // reset when done + } + + // == // Please compute camera transforms here (exercise 2 & 3) + + unsafe { + // Clear the color and depth buffers + gl::ClearColor(0.035, 0.046, 0.078, 1.0); // night sky + gl::Clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT); + + // == // Issue the necessary gl:: commands to draw your scene here + } + + // Display the new color buffer on the display + context.swap_buffers().unwrap(); // we use "double buffering" to avoid artifacts + } + _ => {} + } + }); } diff --git a/gloom-rs/src/shader.rs b/gloom-rs/src/shader.rs index 4cd5cce..0a96ce3 100644 --- a/gloom-rs/src/shader.rs +++ b/gloom-rs/src/shader.rs @@ -2,142 +2,142 @@ use gl; use std::{ffi::CString, path::Path, ptr, str}; pub struct Shader { - pub program_id: u32, + pub program_id: u32, } pub struct ShaderBuilder { - program_id: u32, - shaders: Vec, + program_id: u32, + shaders: Vec, } #[allow(dead_code)] pub enum ShaderType { - Vertex, - Fragment, - TessellationControl, - TessellationEvaluation, - Geometry, + Vertex, + Fragment, + TessellationControl, + TessellationEvaluation, + Geometry, } impl Shader { - // Make sure the shader is active before calling this - pub unsafe fn get_uniform_location(&self, name: &str) -> i32 { - let name_cstr = CString::new(name).expect("CString::new failed"); - gl::GetUniformLocation(self.program_id, name_cstr.as_ptr()) - } - - pub unsafe fn activate(&self) { - gl::UseProgram(self.program_id); - } + // Make sure the shader is active before calling this + pub unsafe fn get_uniform_location(&self, name: &str) -> i32 { + let name_cstr = CString::new(name).expect("CString::new failed"); + gl::GetUniformLocation(self.program_id, name_cstr.as_ptr()) + } + + pub unsafe fn activate(&self) { + gl::UseProgram(self.program_id); + } } impl Into for ShaderType { - fn into(self) -> gl::types::GLenum { - match self { - ShaderType::Vertex => gl::VERTEX_SHADER, - ShaderType::Fragment => gl::FRAGMENT_SHADER, - ShaderType::TessellationControl => gl::TESS_CONTROL_SHADER, - ShaderType::TessellationEvaluation => gl::TESS_EVALUATION_SHADER, - ShaderType::Geometry => gl::GEOMETRY_SHADER, - } - } + fn into(self) -> gl::types::GLenum { + match self { + ShaderType::Vertex => gl::VERTEX_SHADER, + ShaderType::Fragment => gl::FRAGMENT_SHADER, + ShaderType::TessellationControl => gl::TESS_CONTROL_SHADER, + ShaderType::TessellationEvaluation => gl::TESS_EVALUATION_SHADER, + ShaderType::Geometry => gl::GEOMETRY_SHADER, + } + } } impl ShaderType { - fn from_ext(ext: &std::ffi::OsStr) -> Result { - match ext.to_str().expect("Failed to read extension") { - "vert" => Ok(ShaderType::Vertex), - "frag" => Ok(ShaderType::Fragment), - "tcs" => Ok(ShaderType::TessellationControl), - "tes" => Ok(ShaderType::TessellationEvaluation), - "geom" => Ok(ShaderType::Geometry), - e => Err(e.to_string()), - } - } + fn from_ext(ext: &std::ffi::OsStr) -> Result { + match ext.to_str().expect("Failed to read extension") { + "vert" => Ok(ShaderType::Vertex), + "frag" => Ok(ShaderType::Fragment), + "tcs" => Ok(ShaderType::TessellationControl), + "tes" => Ok(ShaderType::TessellationEvaluation), + "geom" => Ok(ShaderType::Geometry), + e => Err(e.to_string()), + } + } } impl ShaderBuilder { - pub unsafe fn new() -> ShaderBuilder { - ShaderBuilder { program_id: gl::CreateProgram(), shaders: vec![] } - } - - pub unsafe fn attach_file(self, shader_path: &str) -> ShaderBuilder { - let path = Path::new(shader_path); - if let Some(extension) = path.extension() { - let shader_type = ShaderType::from_ext(extension).expect("Failed to parse file extension."); - let shader_src = std::fs::read_to_string(path) - .expect(&format!("Failed to read shader source. {}", shader_path)); - self.compile_shader(&shader_src, shader_type) - } else { - panic!("Failed to read extension of file with path: {}", shader_path); - } - } - - pub unsafe fn compile_shader(mut self, shader_src: &str, shader_type: ShaderType) -> ShaderBuilder { - let shader = gl::CreateShader(shader_type.into()); - let c_str_shader = CString::new(shader_src.as_bytes()).unwrap(); - gl::ShaderSource(shader, 1, &c_str_shader.as_ptr(), ptr::null()); - gl::CompileShader(shader); - - if !self.check_shader_errors(shader) { - panic!("Shader failed to compile."); - } - - self.shaders.push(shader); - - self - } - - unsafe fn check_shader_errors(&self, shader_id: u32) -> bool { - let mut success = i32::from(gl::FALSE); - let mut info_log = Vec::with_capacity(512); - info_log.set_len(512 - 1); - gl::GetShaderiv(shader_id, gl::COMPILE_STATUS, &mut success); - if success != i32::from(gl::TRUE) { - gl::GetShaderInfoLog( - shader_id, - 512, - ptr::null_mut(), - info_log.as_mut_ptr() as *mut gl::types::GLchar, - ); - println!("ERROR::Shader Compilation Failed!\n{}", String::from_utf8_lossy(&info_log)); - return false; - } - true - } - - unsafe fn check_linker_errors(&self) -> bool { - let mut success = i32::from(gl::FALSE); - let mut info_log = Vec::with_capacity(512); - info_log.set_len(512 - 1); - gl::GetProgramiv(self.program_id, gl::LINK_STATUS, &mut success); - if success != i32::from(gl::TRUE) { - gl::GetProgramInfoLog( - self.program_id, - 512, - ptr::null_mut(), - info_log.as_mut_ptr() as *mut gl::types::GLchar, - ); - println!("ERROR::SHADER::PROGRAM::COMPILATION_FAILED\n{}", String::from_utf8_lossy(&info_log)); - return false; - } - true - } - - #[must_use = "The shader program is useless if not stored in a variable."] - pub unsafe fn link(self) -> Shader { - for &shader in &self.shaders { - gl::AttachShader(self.program_id, shader); - } - gl::LinkProgram(self.program_id); - - // todo:: use this to make safer abstraction - self.check_linker_errors(); - - for &shader in &self.shaders { - gl::DeleteShader(shader); - } - - Shader { program_id: self.program_id } - } + pub unsafe fn new() -> ShaderBuilder { + ShaderBuilder { program_id: gl::CreateProgram(), shaders: vec![] } + } + + pub unsafe fn attach_file(self, shader_path: &str) -> ShaderBuilder { + let path = Path::new(shader_path); + if let Some(extension) = path.extension() { + let shader_type = ShaderType::from_ext(extension).expect("Failed to parse file extension."); + let shader_src = + std::fs::read_to_string(path).expect(&format!("Failed to read shader source. {}", shader_path)); + self.compile_shader(&shader_src, shader_type) + } else { + panic!("Failed to read extension of file with path: {}", shader_path); + } + } + + pub unsafe fn compile_shader(mut self, shader_src: &str, shader_type: ShaderType) -> ShaderBuilder { + let shader = gl::CreateShader(shader_type.into()); + let c_str_shader = CString::new(shader_src.as_bytes()).unwrap(); + gl::ShaderSource(shader, 1, &c_str_shader.as_ptr(), ptr::null()); + gl::CompileShader(shader); + + if !self.check_shader_errors(shader) { + panic!("Shader failed to compile."); + } + + self.shaders.push(shader); + + self + } + + unsafe fn check_shader_errors(&self, shader_id: u32) -> bool { + let mut success = i32::from(gl::FALSE); + let mut info_log = Vec::with_capacity(512); + info_log.set_len(512 - 1); + gl::GetShaderiv(shader_id, gl::COMPILE_STATUS, &mut success); + if success != i32::from(gl::TRUE) { + gl::GetShaderInfoLog( + shader_id, + 512, + ptr::null_mut(), + info_log.as_mut_ptr() as *mut gl::types::GLchar, + ); + println!("ERROR::Shader Compilation Failed!\n{}", String::from_utf8_lossy(&info_log)); + return false; + } + true + } + + unsafe fn check_linker_errors(&self) -> bool { + let mut success = i32::from(gl::FALSE); + let mut info_log = Vec::with_capacity(512); + info_log.set_len(512 - 1); + gl::GetProgramiv(self.program_id, gl::LINK_STATUS, &mut success); + if success != i32::from(gl::TRUE) { + gl::GetProgramInfoLog( + self.program_id, + 512, + ptr::null_mut(), + info_log.as_mut_ptr() as *mut gl::types::GLchar, + ); + println!("ERROR::SHADER::PROGRAM::COMPILATION_FAILED\n{}", String::from_utf8_lossy(&info_log)); + return false; + } + true + } + + #[must_use = "The shader program is useless if not stored in a variable."] + pub unsafe fn link(self) -> Shader { + for &shader in &self.shaders { + gl::AttachShader(self.program_id, shader); + } + gl::LinkProgram(self.program_id); + + // todo:: use this to make safer abstraction + self.check_linker_errors(); + + for &shader in &self.shaders { + gl::DeleteShader(shader); + } + + Shader { program_id: self.program_id } + } } diff --git a/gloom-rs/src/util.rs b/gloom-rs/src/util.rs index a1e5a40..68c505f 100644 --- a/gloom-rs/src/util.rs +++ b/gloom-rs/src/util.rs @@ -2,39 +2,36 @@ use libc; use std::ffi::CString; pub unsafe fn get_gl_string(name: gl::types::GLenum) -> String { - std::ffi::CStr::from_ptr(gl::GetString(name) as *mut libc::c_char).to_string_lossy().to_string() + std::ffi::CStr::from_ptr(gl::GetString(name) as *mut libc::c_char).to_string_lossy().to_string() } // Debug callback to panic upon encountering any OpenGL error pub extern "system" fn debug_callback( - source: u32, - e_type: u32, - id: u32, - severity: u32, - _length: i32, - msg: *const libc::c_char, - _data: *mut std::ffi::c_void, + source: u32, + e_type: u32, + id: u32, + severity: u32, + _length: i32, + msg: *const libc::c_char, + _data: *mut std::ffi::c_void, ) { - if e_type != gl::DEBUG_TYPE_ERROR { - return; - } - if severity == gl::DEBUG_SEVERITY_HIGH - || severity == gl::DEBUG_SEVERITY_MEDIUM - || severity == gl::DEBUG_SEVERITY_LOW - { - let severity_string = match severity { - gl::DEBUG_SEVERITY_HIGH => "high", - gl::DEBUG_SEVERITY_MEDIUM => "medium", - gl::DEBUG_SEVERITY_LOW => "low", - _ => "unknown", - }; - unsafe { - let string = CString::from_raw(msg as *mut libc::c_char); - let error_message = String::from_utf8_lossy(string.as_bytes()).to_string(); - panic!( - "{}: Error of severity {} raised from {}: {}\n", - id, severity_string, source, error_message - ); - } - } + if e_type != gl::DEBUG_TYPE_ERROR { + return; + } + if severity == gl::DEBUG_SEVERITY_HIGH + || severity == gl::DEBUG_SEVERITY_MEDIUM + || severity == gl::DEBUG_SEVERITY_LOW + { + let severity_string = match severity { + gl::DEBUG_SEVERITY_HIGH => "high", + gl::DEBUG_SEVERITY_MEDIUM => "medium", + gl::DEBUG_SEVERITY_LOW => "low", + _ => "unknown", + }; + unsafe { + let string = CString::from_raw(msg as *mut libc::c_char); + let error_message = String::from_utf8_lossy(string.as_bytes()).to_string(); + panic!("{}: Error of severity {} raised from {}: {}\n", id, severity_string, source, error_message); + } + } } From e28bc39e99ef6b8121d8f3c19cb7c90d2f5d7c42 Mon Sep 17 00:00:00 2001 From: Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com> Date: Tue, 20 Aug 2024 05:26:51 +0200 Subject: [PATCH 03/12] add github action --- .github/workflows/ci.yml | 67 ++++++++++++++++++++++++++++++++++++++++ gloom-rs/src/main.rs | 2 +- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ac0cee6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,67 @@ +name: Rust CI + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build-check: + name: Build Check + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Change directory + run: cd gloom-rs + - name: Setup Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: Build Project + uses: actions-rs/cargo@v1 + with: + command: build + args: --verbose + + format-check: + name: Format Check + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Change directory + run: cd gloom-rs + - name: Setup Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: Check Formatting + uses: actions-rs/cargo@v1 + with: + command: fmt + args: -- --check + + lint-check: + name: Lint Check + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Change directory + run: cd gloom-rs + - name: Setup Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - name: Run Clippy + uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: -- -D warnings diff --git a/gloom-rs/src/main.rs b/gloom-rs/src/main.rs index c979d2c..aabcb68 100644 --- a/gloom-rs/src/main.rs +++ b/gloom-rs/src/main.rs @@ -8,7 +8,7 @@ #![allow(unused_variables)] */ extern crate nalgebra_glm as glm; -use std::sync::{Arc, Mutex, RwLock}; +use std::sync::{Arc, Mutex}; use std::{mem, os::raw::c_void, ptr}; mod shader; From 2c13c3c6429cc698068e0df58ff03d4384986922 Mon Sep 17 00:00:00 2001 From: Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com> Date: Tue, 20 Aug 2024 05:33:25 +0200 Subject: [PATCH 04/12] try fixing github action wdr --- .github/workflows/ci.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac0cee6..5bf1329 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,11 +12,12 @@ jobs: build-check: name: Build Check runs-on: ubuntu-latest + defaults: + run: + working-directory: ./gloom-rs steps: - uses: actions/checkout@v4 - - name: Change directory - run: cd gloom-rs - name: Setup Rust uses: actions-rs/toolchain@v1 with: @@ -31,11 +32,12 @@ jobs: format-check: name: Format Check runs-on: ubuntu-latest + defaults: + run: + working-directory: ./gloom-rs steps: - uses: actions/checkout@v4 - - name: Change directory - run: cd gloom-rs - name: Setup Rust uses: actions-rs/toolchain@v1 with: @@ -50,11 +52,12 @@ jobs: lint-check: name: Lint Check runs-on: ubuntu-latest + defaults: + run: + working-directory: ./gloom-rs steps: - uses: actions/checkout@v4 - - name: Change directory - run: cd gloom-rs - name: Setup Rust uses: actions-rs/toolchain@v1 with: From 5593712de42ed9cbcefa9b5b72f6a21016665b12 Mon Sep 17 00:00:00 2001 From: Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com> Date: Tue, 20 Aug 2024 05:36:56 +0200 Subject: [PATCH 05/12] tried fixing wdr again --- .github/workflows/ci.yml | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5bf1329..f0173cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,13 +8,14 @@ on: branches: - main +defaults: + run: + working-directory: gloom-rs + jobs: build-check: name: Build Check runs-on: ubuntu-latest - defaults: - run: - working-directory: ./gloom-rs steps: - uses: actions/checkout@v4 @@ -32,9 +33,6 @@ jobs: format-check: name: Format Check runs-on: ubuntu-latest - defaults: - run: - working-directory: ./gloom-rs steps: - uses: actions/checkout@v4 @@ -52,9 +50,6 @@ jobs: lint-check: name: Lint Check runs-on: ubuntu-latest - defaults: - run: - working-directory: ./gloom-rs steps: - uses: actions/checkout@v4 From 270662dfecc8e9d2cfe22082f6dcfac2034a4fd6 Mon Sep 17 00:00:00 2001 From: Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com> Date: Tue, 20 Aug 2024 05:45:17 +0200 Subject: [PATCH 06/12] trying path this time --- .github/workflows/ci.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f0173cf..96d137b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,10 +8,6 @@ on: branches: - main -defaults: - run: - working-directory: gloom-rs - jobs: build-check: name: Build Check @@ -19,6 +15,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + path: gloom-rs - name: Setup Rust uses: actions-rs/toolchain@v1 with: @@ -36,6 +34,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + path: gloom-rs - name: Setup Rust uses: actions-rs/toolchain@v1 with: @@ -53,6 +53,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + path: gloom-rs - name: Setup Rust uses: actions-rs/toolchain@v1 with: From 2db8932f27bc61a369fb570d45fb50669fa5311b Mon Sep 17 00:00:00 2001 From: Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com> Date: Tue, 20 Aug 2024 05:54:22 +0200 Subject: [PATCH 07/12] new approach --- .github/workflows/ci.yml | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96d137b..c6b2bcb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,10 @@ on: branches: - main +defaults: + run: + working-directory: ./gloom-rs + jobs: build-check: name: Build Check @@ -15,18 +19,12 @@ jobs: steps: - uses: actions/checkout@v4 - with: - path: gloom-rs - name: Setup Rust - uses: actions-rs/toolchain@v1 + uses: moonrepo/setup-rust@v1 with: - toolchain: stable - override: true + components: rustc, cargo - name: Build Project - uses: actions-rs/cargo@v1 - with: - command: build - args: --verbose + run: cargo build --verbose format-check: name: Format Check @@ -34,18 +32,12 @@ jobs: steps: - uses: actions/checkout@v4 - with: - path: gloom-rs - name: Setup Rust - uses: actions-rs/toolchain@v1 + uses: moonrepo/setup-rust@v1 with: - toolchain: stable - override: true + components: rustfmt - name: Check Formatting - uses: actions-rs/cargo@v1 - with: - command: fmt - args: -- --check + run: cargo fmt -- --check lint-check: name: Lint Check @@ -53,15 +45,9 @@ jobs: steps: - uses: actions/checkout@v4 - with: - path: gloom-rs - name: Setup Rust - uses: actions-rs/toolchain@v1 + uses: moonrepo/setup-rust@v1 with: - toolchain: stable - override: true + components: clippy - name: Run Clippy - uses: actions-rs/clippy-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - args: -- -D warnings + run: cargo clippy --workspace From 46822e71ab200960e63647a1e87ac2079eb5fac1 Mon Sep 17 00:00:00 2001 From: Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com> Date: Tue, 20 Aug 2024 06:13:25 +0200 Subject: [PATCH 08/12] commented out unused stuff to pass the pipeline --- .github/workflows/ci.yml | 2 +- gloom-rs/.rustfmt.toml | 7 -- gloom-rs/src/main.rs | 72 ++++++----- gloom-rs/src/shader.rs | 261 +++++++++++++++++++-------------------- gloom-rs/src/util.rs | 1 - 5 files changed, 169 insertions(+), 174 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6b2bcb..33e6519 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,4 +50,4 @@ jobs: with: components: clippy - name: Run Clippy - run: cargo clippy --workspace + run: cargo clippy --workspace -D warnings diff --git a/gloom-rs/.rustfmt.toml b/gloom-rs/.rustfmt.toml index a9ef535..8a56c54 100644 --- a/gloom-rs/.rustfmt.toml +++ b/gloom-rs/.rustfmt.toml @@ -1,12 +1,5 @@ edition = "2021" max_width = 110 -hard_tabs = false tab_spaces = 3 newline_style = "Unix" use_small_heuristics = "Max" -indent_style = "Block" -trailing_comma = "Always" -space_around_ranges = true -reorder_imports = true -max_blank_lines = 1 -spaces_around_comments = true diff --git a/gloom-rs/src/main.rs b/gloom-rs/src/main.rs index aabcb68..c7a5b7e 100644 --- a/gloom-rs/src/main.rs +++ b/gloom-rs/src/main.rs @@ -9,7 +9,11 @@ */ extern crate nalgebra_glm as glm; use std::sync::{Arc, Mutex}; -use std::{mem, os::raw::c_void, ptr}; +use std::{ + // mem, + // os::raw::c_void, + ptr, +}; mod shader; mod util; @@ -31,48 +35,48 @@ const INITIAL_SCREEN_H: u32 = 600; // Get the size of an arbitrary array of numbers measured in bytes // Example usage: byte_size_of_array(my_array) -fn byte_size_of_array(val: &[T]) -> isize { - std::mem::size_of_val(&val[..]) as isize -} +// fn byte_size_of_array(val: &[T]) -> isize { +// std::mem::size_of_val(&val[..]) as isize +// } // Get the OpenGL-compatible pointer to an arbitrary array of numbers // Example usage: pointer_to_array(my_array) -fn pointer_to_array(val: &[T]) -> *const c_void { - &val[0] as *const T as *const c_void -} +// fn pointer_to_array(val: &[T]) -> *const c_void { +// &val[0] as *const T as *const c_void +// } // Get the size of the given type in bytes // Example usage: size_of::() -fn size_of() -> i32 { - mem::size_of::() as i32 -} +// fn size_of() -> i32 { +// mem::size_of::() as i32 +// } // Get an offset in bytes for n units of type T, represented as a relative pointer // Example usage: offset::(4) -fn offset(n: u32) -> *const c_void { - (n * mem::size_of::() as u32) as *const T as *const c_void -} +// fn offset(n: u32) -> *const c_void { +// (n * mem::size_of::() as u32) as *const T as *const c_void +// } // Get a null pointer (equivalent to an offset of 0) // ptr::null() // == // Generate your VAO here -unsafe fn create_vao(vertices: &Vec, indices: &Vec) -> u32 { - // Implement me! - - // Also, feel free to delete comments :) - - // This should: - // * Generate a VAO and bind it - // * Generate a VBO and bind it - // * Fill it with data - // * Configure a VAP for the data and enable it - // * Generate a IBO and bind it - // * Fill it with data - // * Return the ID of the VAO - - 0 -} +// unsafe fn create_vao(vertices: &Vec, indices: &Vec) -> u32 { +// // Implement me! +// +// // Also, feel free to delete comments :) +// +// // This should: +// // * Generate a VAO and bind it +// // * Generate a VBO and bind it +// // * Fill it with data +// // * Configure a VAP for the data and enable it +// // * Generate a IBO and bind it +// // * Fill it with data +// // * Return the ID of the VAO +// +// 0 +// } fn main() { // Set up the necessary objects to deal with windows and event handling @@ -100,7 +104,7 @@ fn main() { // Set up shared tuple for tracking changes to the window size let arc_window_size = Arc::new(Mutex::new((INITIAL_SCREEN_W, INITIAL_SCREEN_H, false))); - let mut window_aspect_ratio = INITIAL_SCREEN_W as f32 / INITIAL_SCREEN_H as f32; + // let mut window_aspect_ratio = INITIAL_SCREEN_W as f32 / INITIAL_SCREEN_H as f32; // Set up openGL unsafe { @@ -200,7 +204,7 @@ fn main() { Event::MainEventsCleared => { // == // Set up your VAO around here - let my_vao = unsafe { 1337 }; + // let my_vao = unsafe { 1337 }; // == // Set up your shaders here @@ -224,15 +228,15 @@ fn main() { // Compute time passed since the previous frame and since the start of the program let now = std::time::Instant::now(); - let elapsed = now.duration_since(first_frame_time).as_secs_f32(); + // let elapsed = now.duration_since(first_frame_time).as_secs_f32(); let delta_time = now.duration_since(previous_frame_time).as_secs_f32(); previous_frame_time = now; if let Ok(mut new_size) = arc_window_size.lock() { if new_size.2 { context.resize(glutin::dpi::PhysicalSize::new(new_size.0, new_size.1)); - window_aspect_ratio = new_size.0 as f32 / new_size.1 as f32; - (*new_size).2 = false; + // window_aspect_ratio = new_size.0 as f32 / new_size.1 as f32; + new_size.2 = false; println!("Window was resized to {}x{}", new_size.0, new_size.1); unsafe { gl::Viewport(0, 0, new_size.0 as i32, new_size.1 as i32); diff --git a/gloom-rs/src/shader.rs b/gloom-rs/src/shader.rs index 0a96ce3..6797573 100644 --- a/gloom-rs/src/shader.rs +++ b/gloom-rs/src/shader.rs @@ -1,14 +1,13 @@ -use gl; -use std::{ffi::CString, path::Path, ptr, str}; +// use std::{ffi::CString, path::Path, ptr, str}; -pub struct Shader { - pub program_id: u32, -} +// pub struct Shader { +// pub program_id: u32, +// } -pub struct ShaderBuilder { - program_id: u32, - shaders: Vec, -} +// pub struct ShaderBuilder { +// program_id: u32, +// shaders: Vec, +// } #[allow(dead_code)] pub enum ShaderType { @@ -19,125 +18,125 @@ pub enum ShaderType { Geometry, } -impl Shader { - // Make sure the shader is active before calling this - pub unsafe fn get_uniform_location(&self, name: &str) -> i32 { - let name_cstr = CString::new(name).expect("CString::new failed"); - gl::GetUniformLocation(self.program_id, name_cstr.as_ptr()) - } - - pub unsafe fn activate(&self) { - gl::UseProgram(self.program_id); - } -} - -impl Into for ShaderType { - fn into(self) -> gl::types::GLenum { - match self { - ShaderType::Vertex => gl::VERTEX_SHADER, - ShaderType::Fragment => gl::FRAGMENT_SHADER, - ShaderType::TessellationControl => gl::TESS_CONTROL_SHADER, - ShaderType::TessellationEvaluation => gl::TESS_EVALUATION_SHADER, - ShaderType::Geometry => gl::GEOMETRY_SHADER, - } - } -} - -impl ShaderType { - fn from_ext(ext: &std::ffi::OsStr) -> Result { - match ext.to_str().expect("Failed to read extension") { - "vert" => Ok(ShaderType::Vertex), - "frag" => Ok(ShaderType::Fragment), - "tcs" => Ok(ShaderType::TessellationControl), - "tes" => Ok(ShaderType::TessellationEvaluation), - "geom" => Ok(ShaderType::Geometry), - e => Err(e.to_string()), - } - } -} - -impl ShaderBuilder { - pub unsafe fn new() -> ShaderBuilder { - ShaderBuilder { program_id: gl::CreateProgram(), shaders: vec![] } - } - - pub unsafe fn attach_file(self, shader_path: &str) -> ShaderBuilder { - let path = Path::new(shader_path); - if let Some(extension) = path.extension() { - let shader_type = ShaderType::from_ext(extension).expect("Failed to parse file extension."); - let shader_src = - std::fs::read_to_string(path).expect(&format!("Failed to read shader source. {}", shader_path)); - self.compile_shader(&shader_src, shader_type) - } else { - panic!("Failed to read extension of file with path: {}", shader_path); - } - } - - pub unsafe fn compile_shader(mut self, shader_src: &str, shader_type: ShaderType) -> ShaderBuilder { - let shader = gl::CreateShader(shader_type.into()); - let c_str_shader = CString::new(shader_src.as_bytes()).unwrap(); - gl::ShaderSource(shader, 1, &c_str_shader.as_ptr(), ptr::null()); - gl::CompileShader(shader); - - if !self.check_shader_errors(shader) { - panic!("Shader failed to compile."); - } - - self.shaders.push(shader); - - self - } - - unsafe fn check_shader_errors(&self, shader_id: u32) -> bool { - let mut success = i32::from(gl::FALSE); - let mut info_log = Vec::with_capacity(512); - info_log.set_len(512 - 1); - gl::GetShaderiv(shader_id, gl::COMPILE_STATUS, &mut success); - if success != i32::from(gl::TRUE) { - gl::GetShaderInfoLog( - shader_id, - 512, - ptr::null_mut(), - info_log.as_mut_ptr() as *mut gl::types::GLchar, - ); - println!("ERROR::Shader Compilation Failed!\n{}", String::from_utf8_lossy(&info_log)); - return false; - } - true - } - - unsafe fn check_linker_errors(&self) -> bool { - let mut success = i32::from(gl::FALSE); - let mut info_log = Vec::with_capacity(512); - info_log.set_len(512 - 1); - gl::GetProgramiv(self.program_id, gl::LINK_STATUS, &mut success); - if success != i32::from(gl::TRUE) { - gl::GetProgramInfoLog( - self.program_id, - 512, - ptr::null_mut(), - info_log.as_mut_ptr() as *mut gl::types::GLchar, - ); - println!("ERROR::SHADER::PROGRAM::COMPILATION_FAILED\n{}", String::from_utf8_lossy(&info_log)); - return false; - } - true - } - - #[must_use = "The shader program is useless if not stored in a variable."] - pub unsafe fn link(self) -> Shader { - for &shader in &self.shaders { - gl::AttachShader(self.program_id, shader); - } - gl::LinkProgram(self.program_id); - - // todo:: use this to make safer abstraction - self.check_linker_errors(); - - for &shader in &self.shaders { - gl::DeleteShader(shader); - } - - Shader { program_id: self.program_id } - } -} +// impl Shader { +// // Make sure the shader is active before calling this +// pub unsafe fn get_uniform_location(&self, name: &str) -> i32 { +// let name_cstr = CString::new(name).expect("CString::new failed"); +// gl::GetUniformLocation(self.program_id, name_cstr.as_ptr()) +// } +// +// pub unsafe fn activate(&self) { +// gl::UseProgram(self.program_id); +// } +// } + +// impl Into for ShaderType { +// fn into(self) -> gl::types::GLenum { +// match self { +// ShaderType::Vertex => gl::VERTEX_SHADER, +// ShaderType::Fragment => gl::FRAGMENT_SHADER, +// ShaderType::TessellationControl => gl::TESS_CONTROL_SHADER, +// ShaderType::TessellationEvaluation => gl::TESS_EVALUATION_SHADER, +// ShaderType::Geometry => gl::GEOMETRY_SHADER, +// } +// } +// } + +// impl ShaderType { +// fn from_ext(ext: &std::ffi::OsStr) -> Result { +// match ext.to_str().expect("Failed to read extension") { +// "vert" => Ok(ShaderType::Vertex), +// "frag" => Ok(ShaderType::Fragment), +// "tcs" => Ok(ShaderType::TessellationControl), +// "tes" => Ok(ShaderType::TessellationEvaluation), +// "geom" => Ok(ShaderType::Geometry), +// e => Err(e.to_string()), +// } +// } +// } + +// impl ShaderBuilder { +// pub unsafe fn new() -> ShaderBuilder { +// ShaderBuilder { program_id: gl::CreateProgram(), shaders: vec![] } +// } +// +// pub unsafe fn attach_file(self, shader_path: &str) -> ShaderBuilder { +// let path = Path::new(shader_path); +// if let Some(extension) = path.extension() { +// let shader_type = ShaderType::from_ext(extension).expect("Failed to parse file extension."); +// let shader_src = +// std::fs::read_to_string(path).expect(&format!("Failed to read shader source. {}", shader_path)); +// self.compile_shader(&shader_src, shader_type) +// } else { +// panic!("Failed to read extension of file with path: {}", shader_path); +// } +// } +// +// pub unsafe fn compile_shader(mut self, shader_src: &str, shader_type: ShaderType) -> ShaderBuilder { +// let shader = gl::CreateShader(shader_type.into()); +// let c_str_shader = CString::new(shader_src.as_bytes()).unwrap(); +// gl::ShaderSource(shader, 1, &c_str_shader.as_ptr(), ptr::null()); +// gl::CompileShader(shader); +// +// if !self.check_shader_errors(shader) { +// panic!("Shader failed to compile."); +// } +// +// self.shaders.push(shader); +// +// self +// } +// +// unsafe fn check_shader_errors(&self, shader_id: u32) -> bool { +// let mut success = i32::from(gl::FALSE); +// let mut info_log = Vec::with_capacity(512); +// info_log.set_len(512 - 1); +// gl::GetShaderiv(shader_id, gl::COMPILE_STATUS, &mut success); +// if success != i32::from(gl::TRUE) { +// gl::GetShaderInfoLog( +// shader_id, +// 512, +// ptr::null_mut(), +// info_log.as_mut_ptr() as *mut gl::types::GLchar, +// ); +// println!("ERROR::Shader Compilation Failed!\n{}", String::from_utf8_lossy(&info_log)); +// return false; +// } +// true +// } +// +// unsafe fn check_linker_errors(&self) -> bool { +// let mut success = i32::from(gl::FALSE); +// let mut info_log = Vec::with_capacity(512); +// info_log.set_len(512 - 1); +// gl::GetProgramiv(self.program_id, gl::LINK_STATUS, &mut success); +// if success != i32::from(gl::TRUE) { +// gl::GetProgramInfoLog( +// self.program_id, +// 512, +// ptr::null_mut(), +// info_log.as_mut_ptr() as *mut gl::types::GLchar, +// ); +// println!("ERROR::SHADER::PROGRAM::COMPILATION_FAILED\n{}", String::from_utf8_lossy(&info_log)); +// return false; +// } +// true +// } +// +// #[must_use = "The shader program is useless if not stored in a variable."] +// pub unsafe fn link(self) -> Shader { +// for &shader in &self.shaders { +// gl::AttachShader(self.program_id, shader); +// } +// gl::LinkProgram(self.program_id); +// +// // todo:: use this to make safer abstraction +// self.check_linker_errors(); +// +// for &shader in &self.shaders { +// gl::DeleteShader(shader); +// } +// +// Shader { program_id: self.program_id } +// } +// } diff --git a/gloom-rs/src/util.rs b/gloom-rs/src/util.rs index 68c505f..ee4ec15 100644 --- a/gloom-rs/src/util.rs +++ b/gloom-rs/src/util.rs @@ -1,4 +1,3 @@ -use libc; use std::ffi::CString; pub unsafe fn get_gl_string(name: gl::types::GLenum) -> String { From 53e548efdbd5c6fe5b4316362219c06a0e9f6df3 Mon Sep 17 00:00:00 2001 From: Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com> Date: Tue, 20 Aug 2024 06:16:20 +0200 Subject: [PATCH 09/12] fix linting command --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 33e6519..871ba3b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,4 +50,4 @@ jobs: with: components: clippy - name: Run Clippy - run: cargo clippy --workspace -D warnings + run: cargo clippy -- -D warnings From 160171d83141a5211df4f231c54404170e1af202 Mon Sep 17 00:00:00 2001 From: Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:45:45 +0200 Subject: [PATCH 10/12] add thread.rs to be a threaded main entry --- gloom-rs/Cargo.toml | 2 + gloom-rs/src/bin/thread.rs | 310 +++++++++++++++++++++++++++++++++++++ gloom-rs/src/lib.rs | 2 + 3 files changed, 314 insertions(+) create mode 100644 gloom-rs/src/bin/thread.rs create mode 100644 gloom-rs/src/lib.rs diff --git a/gloom-rs/Cargo.toml b/gloom-rs/Cargo.toml index 14e6821..66dfb56 100644 --- a/gloom-rs/Cargo.toml +++ b/gloom-rs/Cargo.toml @@ -1,10 +1,12 @@ [package] name = "gloom-rs" version = "0.3.0" +default-run = "gloom-rs" # or "thread" authors = [ "Peder b. Sundt ", "Michael H. Gimle ", "Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com>", + "Christopher Braathen ", ] edition = "2021" # rust edition diff --git a/gloom-rs/src/bin/thread.rs b/gloom-rs/src/bin/thread.rs new file mode 100644 index 0000000..b842375 --- /dev/null +++ b/gloom-rs/src/bin/thread.rs @@ -0,0 +1,310 @@ +// Uncomment these following global attributes to silence most warnings of "low" interest: +/* +#![allow(dead_code)] +#![allow(non_snake_case)] +#![allow(unreachable_code)] +#![allow(unused_mut)] +#![allow(unused_unsafe)] +#![allow(unused_variables)] +*/ +extern crate nalgebra_glm as glm; +use std::sync::{Arc, Mutex, RwLock}; +use std::thread; +use std::{ + // mem, + // os::raw::c_void, + ptr, +}; + +// use gloom_rs::shader; +use gloom_rs::util; + +use glutin::event::{ + DeviceEvent, + ElementState::{Pressed, Released}, + Event, KeyboardInput, + VirtualKeyCode::{self, *}, + WindowEvent, +}; +use glutin::event_loop::ControlFlow; + +// initial window size +const INITIAL_SCREEN_W: u32 = 800; +const INITIAL_SCREEN_H: u32 = 600; + +// == // Helper functions to make interacting with OpenGL a little bit prettier. You *WILL* need these! // == // + +// Get the size of an arbitrary array of numbers measured in bytes +// Example usage: byte_size_of_array(my_array) +// fn byte_size_of_array(val: &[T]) -> isize { +// std::mem::size_of_val(&val[..]) as isize +// } + +// Get the OpenGL-compatible pointer to an arbitrary array of numbers +// Example usage: pointer_to_array(my_array) +// fn pointer_to_array(val: &[T]) -> *const c_void { +// &val[0] as *const T as *const c_void +// } + +// Get the size of the given type in bytes +// Example usage: size_of::() +// fn size_of() -> i32 { +// mem::size_of::() as i32 +// } + +// Get an offset in bytes for n units of type T, represented as a relative pointer +// Example usage: offset::(4) +// fn offset(n: u32) -> *const c_void { +// (n * mem::size_of::() as u32) as *const T as *const c_void +// } + +// Get a null pointer (equivalent to an offset of 0) +// ptr::null() + +// == // Generate your VAO here +// unsafe fn create_vao(vertices: &Vec, indices: &Vec) -> u32 { +// // Implement me! +// +// // Also, feel free to delete comments :) +// +// // This should: +// // * Generate a VAO and bind it +// // * Generate a VBO and bind it +// // * Fill it with data +// // * Configure a VAP for the data and enable it +// // * Generate a IBO and bind it +// // * Fill it with data +// // * Return the ID of the VAO +// +// 0 +// } + +fn main() { + // Set up the necessary objects to deal with windows and event handling + let el = glutin::event_loop::EventLoop::new(); + let wb = glutin::window::WindowBuilder::new() + .with_title("Gloom-rs") + .with_resizable(true) + .with_inner_size(glutin::dpi::LogicalSize::new(INITIAL_SCREEN_W, INITIAL_SCREEN_H)); + let cb = glutin::ContextBuilder::new().with_vsync(true); + let windowed_context = cb.build_windowed(wb, &el).unwrap(); + // Uncomment these if you want to use the mouse for controls, but want it to be confined to the screen and/or invisible. + // windowed_context.window().set_cursor_grab(true).expect("failed to grab cursor"); + // windowed_context.window().set_cursor_visible(false); + + // Set up a shared vector for keeping track of currently pressed keys + let arc_pressed_keys = Arc::new(Mutex::new(Vec::::with_capacity(10))); + // Make a reference of this vector to send to the render thread + let pressed_keys = Arc::clone(&arc_pressed_keys); + + // Set up shared tuple for tracking mouse movement between frames + let arc_mouse_delta = Arc::new(Mutex::new((0f32, 0f32))); + // Make a reference of this tuple to send to the render thread + let mouse_delta = Arc::clone(&arc_mouse_delta); + + // Set up shared tuple for tracking changes to the window size + let arc_window_size = Arc::new(Mutex::new((INITIAL_SCREEN_W, INITIAL_SCREEN_H, false))); + // Make a reference of this tuple to send to the render thread + let window_size = Arc::clone(&arc_window_size); + + // Spawn a separate thread for rendering, so event handling doesn't block rendering + let render_thread = thread::spawn(move || { + // Acquire the OpenGL Context and load the function pointers. + // This has to be done inside of the rendering thread, because + // an active OpenGL context cannot safely traverse a thread boundary + let context = unsafe { + let c = windowed_context.make_current().unwrap(); + gl::load_with(|symbol| c.get_proc_address(symbol) as *const _); + c + }; + + // let mut window_aspect_ratio = INITIAL_SCREEN_W as f32 / INITIAL_SCREEN_H as f32; + + // Set up openGL + unsafe { + gl::Enable(gl::DEPTH_TEST); + gl::DepthFunc(gl::LESS); + gl::Enable(gl::CULL_FACE); + gl::Disable(gl::MULTISAMPLE); + gl::Enable(gl::BLEND); + gl::BlendFunc(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA); + gl::Enable(gl::DEBUG_OUTPUT_SYNCHRONOUS); + gl::DebugMessageCallback(Some(util::debug_callback), ptr::null()); + + // Print some diagnostics + println!("{}: {}", util::get_gl_string(gl::VENDOR), util::get_gl_string(gl::RENDERER)); + println!("OpenGL\t: {}", util::get_gl_string(gl::VERSION)); + println!("GLSL\t: {}", util::get_gl_string(gl::SHADING_LANGUAGE_VERSION)); + } + + // == // Set up your VAO around here + + // let my_vao = unsafe { 1337 }; + + // == // Set up your shaders here + + // Basic usage of shader helper: + // The example code below creates a 'shader' object. + // It which contains the field `.program_id` and the method `.activate()`. + // The `.` in the path is relative to `Cargo.toml`. + // This snippet is not enough to do the exercise, and will need to be modified (outside + // of just using the correct path), but it only needs to be called once + + /* + let simple_shader = unsafe { + shader::ShaderBuilder::new() + .attach_file("./path/to/simple/shader.file") + .link() + }; + */ + + // Used to demonstrate keyboard handling for exercise 2. + let mut _arbitrary_number = 0.0; // feel free to remove + + // The main rendering loop + let first_frame_time = std::time::Instant::now(); + let mut previous_frame_time = first_frame_time; + loop { + // Compute time passed since the previous frame and since the start of the program + let now = std::time::Instant::now(); + // let elapsed = now.duration_since(first_frame_time).as_secs_f32(); + let delta_time = now.duration_since(previous_frame_time).as_secs_f32(); + previous_frame_time = now; + + // Handle resize events + if let Ok(mut new_size) = window_size.lock() { + if new_size.2 { + context.resize(glutin::dpi::PhysicalSize::new(new_size.0, new_size.1)); + // window_aspect_ratio = new_size.0 as f32 / new_size.1 as f32; + new_size.2 = false; + println!("Window was resized to {}x{}", new_size.0, new_size.1); + unsafe { + gl::Viewport(0, 0, new_size.0 as i32, new_size.1 as i32); + } + } + } + + // Handle keyboard input + if let Ok(keys) = pressed_keys.lock() { + for key in keys.iter() { + match key { + // The `VirtualKeyCode` enum is defined here: + // https://docs.rs/winit/0.25.0/winit/event/enum.VirtualKeyCode.html + VirtualKeyCode::A => { + _arbitrary_number += delta_time; + } + VirtualKeyCode::D => { + _arbitrary_number -= delta_time; + } + + // default handler: + _ => {} + } + } + } + // Handle mouse movement. delta contains the x and y movement of the mouse since last frame in pixels + if let Ok(mut delta) = mouse_delta.lock() { + // == // Optionally access the accumulated mouse movement between + // == // frames here with `delta.0` and `delta.1` + + *delta = (0.0, 0.0); // reset when done + } + + // == // Please compute camera transforms here (exercise 2 & 3) + + unsafe { + // Clear the color and depth buffers + gl::ClearColor(0.035, 0.046, 0.078, 1.0); // night sky + gl::Clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT); + + // == // Issue the necessary gl:: commands to draw your scene here + } + + // Display the new color buffer on the display + context.swap_buffers().unwrap(); // we use "double buffering" to avoid artifacts + } + }); + + // == // + // == // From here on down there are only internals. + // == // + + // Keep track of the health of the rendering thread + let render_thread_healthy = Arc::new(RwLock::new(true)); + let render_thread_watchdog = Arc::clone(&render_thread_healthy); + thread::spawn(move || { + if render_thread.join().is_err() { + if let Ok(mut health) = render_thread_watchdog.write() { + println!("Render thread panicked!"); + *health = false; + } + } + }); + + // Start the event loop -- This is where window events are initially handled + el.run(move |event, _, control_flow| { + *control_flow = ControlFlow::Wait; + + // Terminate program if render thread panics + if let Ok(health) = render_thread_healthy.read() { + if !*health { + *control_flow = ControlFlow::Exit; + } + } + + match event { + Event::WindowEvent { event: WindowEvent::Resized(physical_size), .. } => { + println!("New window size received: {}x{}", physical_size.width, physical_size.height); + if let Ok(mut new_size) = arc_window_size.lock() { + *new_size = (physical_size.width, physical_size.height, true); + } + } + Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => { + *control_flow = ControlFlow::Exit; + } + // Keep track of currently pressed keys to send to the rendering thread + Event::WindowEvent { + event: + WindowEvent::KeyboardInput { + input: KeyboardInput { state: key_state, virtual_keycode: Some(keycode), .. }, + .. + }, + .. + } => { + if let Ok(mut keys) = arc_pressed_keys.lock() { + match key_state { + Released => { + if keys.contains(&keycode) { + let i = keys.iter().position(|&k| k == keycode).unwrap(); + keys.remove(i); + } + } + Pressed => { + if !keys.contains(&keycode) { + keys.push(keycode); + } + } + } + } + + // Handle Escape and Q keys separately + match keycode { + Escape => { + *control_flow = ControlFlow::Exit; + } + Q => { + *control_flow = ControlFlow::Exit; + } + _ => {} + } + } + Event::DeviceEvent { event: DeviceEvent::MouseMotion { delta }, .. } => { + // Accumulate mouse movement + if let Ok(mut position) = arc_mouse_delta.lock() { + *position = (position.0 + delta.0 as f32, position.1 + delta.1 as f32); + } + } + _ => {} + } + }); +} diff --git a/gloom-rs/src/lib.rs b/gloom-rs/src/lib.rs new file mode 100644 index 0000000..2d197e4 --- /dev/null +++ b/gloom-rs/src/lib.rs @@ -0,0 +1,2 @@ +pub mod shader; +pub mod util; From db9e7f5a759fa14607affbd9254cfbb2c92d740c Mon Sep 17 00:00:00 2001 From: Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:51:45 +0200 Subject: [PATCH 11/12] fix lint --- gloom-rs/src/util.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gloom-rs/src/util.rs b/gloom-rs/src/util.rs index ee4ec15..ae76763 100644 --- a/gloom-rs/src/util.rs +++ b/gloom-rs/src/util.rs @@ -1,5 +1,9 @@ use std::ffi::CString; +/// # Safety +/// +/// This function is unsafe because it calls the OpenGL function `gl::GetString`, which returns a pointer to a static string. +/// The caller must ensure that the OpenGL context is correctly set up and that the `name` parameter is a valid enum for `gl::GetString`. pub unsafe fn get_gl_string(name: gl::types::GLenum) -> String { std::ffi::CStr::from_ptr(gl::GetString(name) as *mut libc::c_char).to_string_lossy().to_string() } From 6e82e7ce035e5a38510af3d956fedae534974947 Mon Sep 17 00:00:00 2001 From: Michael Brusegard <56915010+michaelbrusegard@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:56:40 +0200 Subject: [PATCH 12/12] add a readme with basic explaination --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..b6acde4 --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +# Visual Computing Fundamentals + +## Gloom-rs + +This is a simple OpenGL Rust project. + +To get started enter the project directory: + +```bash +cd gloom-rs +``` + +### Requirements + +- Rust +- Cargo + +### Running the Project + +You can run the project using the following command: + +```bash +cargo run +``` + +This will compile and run the project. + +If you want to run the project with rendering on a separate thread, use the following command: + +```bash +cargo run --bin thread +``` + +This will run the project with rendering on a separate thread.