diff --git a/Cargo.lock b/Cargo.lock index 66b7375..157f89d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -909,6 +909,17 @@ dependencies = [ "unicode-width 0.1.14", ] +[[package]] +name = "codespan-reporting" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe6d2e5af09e8c8ad56c969f2157a3d4238cebc7c55f0a517728c38f7b200f81" +dependencies = [ + "serde", + "termcolor", + "unicode-width 0.2.0", +] + [[package]] name = "color" version = "0.3.1" @@ -1020,6 +1031,29 @@ dependencies = [ "libc", ] +[[package]] +name = "cosmic-text" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da46a9d5a8905cc538a4a5bceb6a4510de7a51049c5588c0114efce102bcbbe8" +dependencies = [ + "bitflags 2.9.0", + "fontdb", + "log", + "rangemap", + "rustc-hash 1.1.0", + "rustybuzz", + "self_cell", + "smol_str", + "swash", + "sys-locale", + "ttf-parser 0.21.1", + "unicode-bidi", + "unicode-linebreak", + "unicode-script", + "unicode-segmentation", +] + [[package]] name = "cpufeatures" version = "0.2.17" @@ -1195,6 +1229,12 @@ version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" +[[package]] +name = "crunchy" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43da5946c66ffcc7745f48db692ffbb10a83bfe0afd96235c5c2a4fb23994929" + [[package]] name = "crypto-bigint" version = "0.5.5" @@ -2354,8 +2394,8 @@ dependencies = [ "serde_json", "thiserror 2.0.12", "tokio", - "wgpu-core", - "wgpu-types", + "wgpu-core 24.0.2", + "wgpu-types 24.0.0", ] [[package]] @@ -2819,6 +2859,25 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "31ae425815400e5ed474178a7a22e275a9687086a12ca63ec793ff292d8fdae8" +[[package]] +name = "etagere" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc89bf99e5dc15954a60f707c1e09d7540e5cd9af85fa75caa0b510bc08c5342" +dependencies = [ + "euclid", + "svg_fmt", +] + +[[package]] +name = "euclid" +version = "0.22.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad9cdb4b747e485a12abb0e6566612956c7a1bafa3bdb8d682c5b6d403589e48" +dependencies = [ + "num-traits", +] + [[package]] name = "fallible-iterator" version = "0.3.0" @@ -2951,6 +3010,38 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" +[[package]] +name = "font-types" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02a596f5713680923a2080d86de50fe472fb290693cf0f701187a1c8b36996b7" +dependencies = [ + "bytemuck", +] + +[[package]] +name = "fontconfig-parser" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbc773e24e02d4ddd8395fd30dc147524273a83e54e0f312d986ea30de5f5646" +dependencies = [ + "roxmltree", +] + +[[package]] +name = "fontdb" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0299020c3ef3f60f526a4f64ab4a3d4ce116b1acbf24cdd22da0068e5d81dc3" +dependencies = [ + "fontconfig-parser", + "log", + "memmap2", + "slotmap", + "tinyvec", + "ttf-parser 0.20.0", +] + [[package]] name = "foreign-types" version = "0.5.0" @@ -3262,6 +3353,19 @@ dependencies = [ "gl_generator", ] +[[package]] +name = "glyphon" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c6a289ad2a23656ccf4306fc818cef6776471a136d909123fd26c0f2ecb44ba" +dependencies = [ + "cosmic-text", + "etagere", + "lru", + "rustc-hash 2.1.1", + "wgpu", +] + [[package]] name = "gpu-alloc" version = "0.6.0" @@ -3377,6 +3481,17 @@ dependencies = [ "tracing", ] +[[package]] +name = "half" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "459196ed295495a68f7d7fe1d84f6c4b7ff0e21fe3017b2f283c6fac3ad803c9" +dependencies = [ + "cfg-if", + "crunchy", + "num-traits", +] + [[package]] name = "halfbrown" version = "0.2.5" @@ -4399,6 +4514,12 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "lru" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" + [[package]] name = "malloc_buf" version = "0.0.6" @@ -4586,7 +4707,7 @@ dependencies = [ "bit-set 0.8.0", "bitflags 2.9.0", "cfg_aliases", - "codespan-reporting", + "codespan-reporting 0.11.1", "hexf-parse", "indexmap 2.8.0", "log", @@ -4599,6 +4720,31 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "naga" +version = "25.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b977c445f26e49757f9aca3631c3b8b836942cb278d69a92e7b80d3b24da632" +dependencies = [ + "arrayvec", + "bit-set 0.8.0", + "bitflags 2.9.0", + "cfg_aliases", + "codespan-reporting 0.12.0", + "half", + "hashbrown 0.15.2", + "hexf-parse", + "indexmap 2.8.0", + "log", + "num-traits", + "once_cell", + "rustc-hash 1.1.0", + "spirv", + "strum 0.26.3", + "thiserror 2.0.12", + "unicode-ident", +] + [[package]] name = "napi_sym" version = "0.124.0" @@ -5125,9 +5271,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.21.1" +version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d75b0bedcc4fe52caa0e03d9f1151a323e4aa5e2d78ba3580400cd3c9e2bc4bc" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "opaque-debug" @@ -5290,7 +5436,7 @@ version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22ec719bbf3b2a81c109a4e20b1f129b5566b7dce654bc3872f6a05abf82b2c4" dependencies = [ - "ttf-parser", + "ttf-parser 0.25.1", ] [[package]] @@ -5888,6 +6034,12 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3d6831663a5098ea164f89cff59c6284e95f4e3c76ce9848d4529f5ccca9bde" +[[package]] +name = "rangemap" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f60fcc7d6849342eff22c4350c8b9a989ee8ceabc4b481253e8946b9fe83d684" + [[package]] name = "raw-window-handle" version = "0.6.2" @@ -5922,6 +6074,7 @@ dependencies = [ "color", "deno_core", "deno_error", + "glyphon", "notify 8.0.0", "pollster", "rustyscript", @@ -5933,6 +6086,16 @@ dependencies = [ "winit", ] +[[package]] +name = "read-fonts" +version = "0.29.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f96bfbb7df43d34a2b7b8582fcbcb676ba02a763265cb90bc8aabfd62b57d64" +dependencies = [ + "bytemuck", + "font-types", +] + [[package]] name = "redox_syscall" version = "0.4.1" @@ -6132,6 +6295,12 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "roxmltree" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c20b6793b5c2fa6553b250154b78d6d0db37e72700ae35fad9387a46f487c97" + [[package]] name = "rsa" version = "0.9.8" @@ -6323,6 +6492,23 @@ version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" +[[package]] +name = "rustybuzz" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfb9cf8877777222e4a3bc7eb247e398b56baba500c38c1c46842431adc8b55c" +dependencies = [ + "bitflags 2.9.0", + "bytemuck", + "libm", + "smallvec", + "ttf-parser 0.21.1", + "unicode-bidi-mirroring", + "unicode-ccc", + "unicode-properties", + "unicode-script", +] + [[package]] name = "rustyline" version = "13.0.0" @@ -6528,6 +6714,12 @@ dependencies = [ "libc", ] +[[package]] +name = "self_cell" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f7d95a54511e0c7be3f51e8867aa8cf35148d7b9445d44de2f943e2b206e749" + [[package]] name = "semver" version = "0.9.0" @@ -6761,6 +6953,16 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" +[[package]] +name = "skrifa" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbeb4ca4399663735553a09dd17ce7e49a0a0203f03b706b39628c4d913a8607" +dependencies = [ + "bytemuck", + "read-fonts", +] + [[package]] name = "slab" version = "0.4.9" @@ -7026,6 +7228,23 @@ version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" +[[package]] +name = "svg_fmt" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0193cc4331cfd2f3d2011ef287590868599a2f33c3e69bc22c1a3d3acf9e02fb" + +[[package]] +name = "swash" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f745de914febc7c9ab4388dfaf94bbc87e69f57bb41133a9b0c84d4be49856f3" +dependencies = [ + "skrifa", + "yazi", + "zeno", +] + [[package]] name = "swc_allocator" version = "4.0.0" @@ -7480,6 +7699,15 @@ dependencies = [ "syn 2.0.100", ] +[[package]] +name = "sys-locale" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eab9a99a024a169fe8a903cf9d4a3b3601109bcc13bd9e3c6fff259138626c4" +dependencies = [ + "libc", +] + [[package]] name = "sys_traits" version = "0.1.8" @@ -7974,6 +8202,18 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "ttf-parser" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17f77d76d837a7830fe1d4f12b7b4ba4192c1888001c7164257e4bc6d21d96b4" + +[[package]] +name = "ttf-parser" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c591d83f69777866b9126b24c6dd9a18351f177e49d625920d19f989fd31cf8" + [[package]] name = "ttf-parser" version = "0.25.1" @@ -8044,6 +8284,24 @@ dependencies = [ "unic-common", ] +[[package]] +name = "unicode-bidi" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c1cb5db39152898a79168971543b1cb5020dff7fe43c8dc468b0885f5e29df5" + +[[package]] +name = "unicode-bidi-mirroring" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23cb788ffebc92c5948d0e997106233eeb1d8b9512f93f41651f52b6c5f5af86" + +[[package]] +name = "unicode-ccc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1df77b101bcc4ea3d78dafc5ad7e4f58ceffe0b2b16bf446aeb50b6cb4157656" + [[package]] name = "unicode-id" version = "0.3.5" @@ -8062,6 +8320,24 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +[[package]] +name = "unicode-linebreak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b09c83c3c29d37506a3e260c08c03743a6bb66a9cd432c6934ab501a190571f" + +[[package]] +name = "unicode-properties" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e70f2a8b45122e719eb623c01822704c4e0907e7e426a05927e1a1cfff5b75d0" + +[[package]] +name = "unicode-script" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb421b350c9aff471779e262955939f565ec18b86c15364e6bdf0d662ca7c1f" + [[package]] name = "unicode-segmentation" version = "1.12.0" @@ -8510,18 +8786,20 @@ dependencies = [ [[package]] name = "wgpu" -version = "24.0.3" +version = "25.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35904fb00ba2d2e0a4d002fcbbb6e1b89b574d272a50e5fc95f6e81cf281c245" +checksum = "ec8fb398f119472be4d80bc3647339f56eb63b2a331f6a3d16e25d8144197dd9" dependencies = [ "arrayvec", "bitflags 2.9.0", "cfg_aliases", "document-features", + "hashbrown 0.15.2", "js-sys", "log", - "naga", + "naga 25.0.1", "parking_lot", + "portable-atomic", "profiling", "raw-window-handle", "smallvec", @@ -8529,9 +8807,9 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "wgpu-core", - "wgpu-hal", - "wgpu-types", + "wgpu-core 25.0.2", + "wgpu-hal 25.0.2", + "wgpu-types 25.0.0", ] [[package]] @@ -8547,7 +8825,7 @@ dependencies = [ "document-features", "indexmap 2.8.0", "log", - "naga", + "naga 24.0.0", "once_cell", "parking_lot", "profiling", @@ -8557,8 +8835,66 @@ dependencies = [ "serde", "smallvec", "thiserror 2.0.12", - "wgpu-hal", - "wgpu-types", + "wgpu-hal 24.0.2", + "wgpu-types 24.0.0", +] + +[[package]] +name = "wgpu-core" +version = "25.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7b882196f8368511d613c6aeec80655160db6646aebddf8328879a88d54e500" +dependencies = [ + "arrayvec", + "bit-set 0.8.0", + "bit-vec 0.8.0", + "bitflags 2.9.0", + "cfg_aliases", + "document-features", + "hashbrown 0.15.2", + "indexmap 2.8.0", + "log", + "naga 25.0.1", + "once_cell", + "parking_lot", + "portable-atomic", + "profiling", + "raw-window-handle", + "rustc-hash 1.1.0", + "smallvec", + "thiserror 2.0.12", + "wgpu-core-deps-apple", + "wgpu-core-deps-emscripten", + "wgpu-core-deps-windows-linux-android", + "wgpu-hal 25.0.2", + "wgpu-types 25.0.0", +] + +[[package]] +name = "wgpu-core-deps-apple" +version = "25.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfd488b3239b6b7b185c3b045c39ca6bf8af34467a4c5de4e0b1a564135d093d" +dependencies = [ + "wgpu-hal 25.0.2", +] + +[[package]] +name = "wgpu-core-deps-emscripten" +version = "25.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f09ad7aceb3818e52539acc679f049d3475775586f3f4e311c30165cf2c00445" +dependencies = [ + "wgpu-hal 25.0.2", +] + +[[package]] +name = "wgpu-core-deps-windows-linux-android" +version = "25.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cba5fb5f7f9c98baa7c889d444f63ace25574833df56f5b817985f641af58e46" +dependencies = [ + "wgpu-hal 25.0.2", ] [[package]] @@ -8587,7 +8923,7 @@ dependencies = [ "libloading 0.8.6", "log", "metal", - "naga", + "naga 24.0.0", "ndk-sys 0.5.0+25.2.9519653", "objc", "once_cell", @@ -8596,13 +8932,59 @@ dependencies = [ "profiling", "range-alloc", "raw-window-handle", - "renderdoc-sys", "rustc-hash 1.1.0", "smallvec", "thiserror 2.0.12", "wasm-bindgen", "web-sys", - "wgpu-types", + "wgpu-types 24.0.0", + "windows 0.58.0", + "windows-core 0.58.0", +] + +[[package]] +name = "wgpu-hal" +version = "25.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f968767fe4d3d33747bbd1473ccd55bf0f6451f55d733b5597e67b5deab4ad17" +dependencies = [ + "android_system_properties", + "arrayvec", + "ash", + "bit-set 0.8.0", + "bitflags 2.9.0", + "block", + "bytemuck", + "cfg-if", + "cfg_aliases", + "core-graphics-types", + "glow", + "glutin_wgl_sys", + "gpu-alloc", + "gpu-allocator", + "gpu-descriptor", + "hashbrown 0.15.2", + "js-sys", + "khronos-egl", + "libc", + "libloading 0.8.6", + "log", + "metal", + "naga 25.0.1", + "ndk-sys 0.5.0+25.2.9519653", + "objc", + "ordered-float 4.6.0", + "parking_lot", + "portable-atomic", + "profiling", + "range-alloc", + "raw-window-handle", + "renderdoc-sys", + "smallvec", + "thiserror 2.0.12", + "wasm-bindgen", + "web-sys", + "wgpu-types 25.0.0", "windows 0.58.0", "windows-core 0.58.0", ] @@ -8620,6 +9002,20 @@ dependencies = [ "web-sys", ] +[[package]] +name = "wgpu-types" +version = "25.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2aa49460c2a8ee8edba3fca54325540d904dd85b2e086ada762767e17d06e8bc" +dependencies = [ + "bitflags 2.9.0", + "bytemuck", + "js-sys", + "log", + "thiserror 2.0.12", + "web-sys", +] + [[package]] name = "which" version = "6.0.3" @@ -9193,6 +9589,12 @@ version = "0.8.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c5b940ebc25896e71dd073bad2dbaa2abfe97b0a391415e22ad1326d9c54e3c4" +[[package]] +name = "yazi" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01738255b5a16e78bbb83e7fbba0a1e7dd506905cfc53f4622d89015a03fbb5" + [[package]] name = "yoke" version = "0.7.5" @@ -9217,6 +9619,12 @@ dependencies = [ "synstructure 0.13.1", ] +[[package]] +name = "zeno" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6df3dc4292935e51816d896edcd52aa30bc297907c26167fec31e2b0c6a32524" + [[package]] name = "zerocopy" version = "0.7.35" diff --git a/Cargo.toml b/Cargo.toml index 1b67207..5a798c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,10 @@ rustyscript = { path = "../rustyscript", features = ["all_extensions", "node_exp deno_core = "0.340.0" serde = { version = "1.0.218", features = ["derive"] } sys_traits = "0.1.8" -wgpu = { version = "24.0.1" } +wgpu = { version = "25.0.0" } winit = { version = "0.30.9" } notify = "8.0.0" taffy = { version = "0.7.7", features = ["serde"]} slotmap = "1.0.7" color = "0.3.1" +glyphon = "0.9.0" diff --git a/src/app.rs b/src/app.rs index 87df86e..3557057 100644 --- a/src/app.rs +++ b/src/app.rs @@ -59,6 +59,10 @@ impl<'window> ApplicationHandler for App<'window> { gui.compute_layout(size.width, size.height); gpu.update_instance_buffer(gui.into_instances()); + + // Render text areas + let text_areas = gui.into_text_areas(); + gpu.prepare_text_areas(text_areas); window.request_redraw(); } @@ -78,6 +82,10 @@ impl<'window> ApplicationHandler for App<'window> { if let Ok(mut gui) = self.gui.lock() { gui.compute_layout(size.width, size.height); gpu.update_instance_buffer(gui.into_instances()); + + // Render text areas + let text_areas = gui.into_text_areas(); + gpu.prepare_text_areas(text_areas); gpu.set_size(size.width, size.height); } diff --git a/src/gpu.rs b/src/gpu.rs index 89ac5e5..788c675 100644 --- a/src/gpu.rs +++ b/src/gpu.rs @@ -2,6 +2,10 @@ use bytemuck::bytes_of; use bytemuck::cast_slice; use bytemuck::Pod; use bytemuck::Zeroable; +use glyphon::{ + Attrs, Buffer, Cache, Color, Family, FontSystem, Metrics, Shaping, SwashCache, TextArea, + TextAtlas, TextBounds, TextRenderer, Viewport, Weight, +}; use std::borrow::Cow; use std::sync::Arc; use wgpu::util::DeviceExt; @@ -45,6 +49,14 @@ pub struct Gpu<'window> { instance_buffer: wgpu::Buffer, instance_count: u32, viewport: [f32; 2], + scale_factor: f64, + // Text rendering components + font_system: FontSystem, + swash_cache: SwashCache, + cache: Cache, + text_atlas: TextAtlas, + text_renderer: TextRenderer, + text_buffers: Vec<(Buffer, f32, f32)>, // Buffer with x, y position } impl<'window> Gpu<'window> { @@ -58,6 +70,7 @@ impl<'window> Gpu<'window> { */ let size = window.inner_size(); + let scale_factor = window.scale_factor(); let width = size.width.max(1); let height = size.height.max(1); let viewport = [width as f32, height as f32]; @@ -104,18 +117,16 @@ impl<'window> Gpu<'window> { .expect("Failed to find an appropriate adapter"); let (device, queue) = adapter - .request_device( - &wgpu::DeviceDescriptor { - label: None, - required_features: wgpu::Features::PUSH_CONSTANTS, - required_limits: wgpu::Limits { - max_push_constant_size: push_const_size, - ..Default::default() - }, - memory_hints: Performance, + .request_device(&wgpu::DeviceDescriptor { + label: None, + required_features: wgpu::Features::PUSH_CONSTANTS, + required_limits: wgpu::Limits { + max_push_constant_size: push_const_size, + ..Default::default() }, - None, - ) + memory_hints: Performance, + trace: Default::default(), + }) .await .expect("Failed to create device"); @@ -217,6 +228,18 @@ impl<'window> Gpu<'window> { cache: None, }); + // Initialize text rendering components + let font_system = FontSystem::new(); + let swash_cache = SwashCache::new(); + let cache = Cache::new(&device); + let mut text_atlas = + TextAtlas::new(&device, &queue, &cache, wgpu::TextureFormat::Bgra8UnormSrgb); + let text_renderer = TextRenderer::new( + &mut text_atlas, + &device, + wgpu::MultisampleState::default(), + None, + ); Gpu { surface, config, @@ -226,6 +249,13 @@ impl<'window> Gpu<'window> { instance_buffer, instance_count, viewport, + scale_factor, + font_system, + swash_cache, + cache, + text_atlas, + text_renderer, + text_buffers: Vec::new(), } } @@ -240,7 +270,7 @@ impl<'window> Gpu<'window> { } pub fn draw(&mut self) { - self.device.poll(wgpu::Maintain::Wait); + let _ = self.device.poll(wgpu::MaintainBase::Wait); if self.instance_count == 0 { return; @@ -261,6 +291,7 @@ impl<'window> Gpu<'window> { label: Some("Draw Encoder"), }); + // Render background rectangles { let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: None, @@ -286,6 +317,68 @@ impl<'window> Gpu<'window> { } } + // Render text on top of rectangles + if !self.text_buffers.is_empty() { + // Prepare text areas for rendering + let text_areas: Vec