diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..8a0f0f5 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,4 @@ +[build] +rustflags = [ +"--cfg=web_sys_unstable_apis" +] diff --git a/.github/workflows/test-wgpu.yml b/.github/workflows/test-wgpu.yml deleted file mode 100644 index cc2ebef..0000000 --- a/.github/workflows/test-wgpu.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Test for wgpu - -on: - push: - paths: - - "**/*.rs" - - ".github/**" - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - run: rustup update stable && rustup default stable - - name: Setup rustfmt - run: rustup component add rustfmt - - name: Run fmt - run: cargo fmt --all -- --check - - name: Setup clippy - run: rustup component add clippy - - name: Run clippy - run: cargo clippy --all-targets -- -D warnings - - name: Run tests - run: cargo test --verbose - - name: Build - run: cargo build --verbose diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..02f8ea6 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,183 @@ +# Refer https://github.com/gfx-rs/wgpu/blob/757245cdfc97e4d4dce110ef1bb333787a6c25bd/.github/workflows/ci.yml +name: Test + +on: + push: + paths: + - "**/*.rs" + - ".github/**" + +env: + CARGO_INCREMENTAL: false + CARGO_TERM_COLOR: always + RUST_LOG: info + RUST_BACKTRACE: full + MSRV: 1.70 + PKG_CONFIG_ALLOW_CROSS: 1 # allow android to work + RUSTFLAGS: --cfg=web_sys_unstable_apis -D warnings + RUSTDOCFLAGS: -Dwarnings + CACHE_SUFFIX: b # cache busting + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install MSRV toolchain + run: | + rustup update stable + rustup default stable + rustup component add clippy + rustup component add rustfmt + - name: caching + uses: Swatinem/rust-cache@v2 + with: + key: check-${{ env.CACHE_SUFFIX }} + + - name: Run fmt + run: cargo fmt --all -- --check + + - name: Run clippy + run: cargo clippy --all-targets -- -D warnings + + - name: run doctest + run: cargo test --doc + + build: + strategy: + matrix: + include: + # Windows + - name: Windows x86_64 + os: windows-2022 + target: x86_64-pc-windows-msvc + + # MacOS + - name: MacOS x86_64 + os: macos-12 + target: x86_64-apple-darwin + + - name: MacOS aarch64 + os: macos-12 + target: aarch64-apple-darwin + + # IOS + - name: IOS aarch64 + os: macos-12 + target: aarch64-apple-ios + + # Linux + - name: Linux x86_64 + os: ubuntu-22.04 + target: x86_64-unknown-linux-gnu + + - name: Linux aarch64 + os: ubuntu-22.04 + target: aarch64-unknown-linux-gnu + + # Android + # - name: Android aarch64 + # os: ubuntu-22.04 + # target: aarch64-linux-android + + # WebGPU/WebGL + - name: WebAssembly + os: ubuntu-22.04 + target: wasm32-unknown-unknown + + name: Build ${{ matrix.name }} + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v2 + - name: Install MSRV toolchain + run: | + rustup update stable + rustup default stable + rustup target add ${{ matrix.target }} + rustc --version + - name: install aarch64-linux-gnu + if: matrix.target == 'aarch64-unknown-linux-gnu' + run: | + set -e + sudo apt-get update -y -qq + sudo apt-get install g++-aarch64-linux-gnu + + - name: caching + uses: Swatinem/rust-cache@v2 + with: + key: build-${{ matrix.target }}-${{ env.CACHE_SUFFIX }} + + - name: Build + run: cargo build --verbose --target ${{ matrix.target }} + + test: + strategy: + matrix: + include: + # Windows + - name: Windows x86_64 + os: windows-2022 + backends: dx12 + + # MacOS + # - name: MacOS aarch64 + # os: macos-12 + # target: aarch64-apple-darwin + # backends: metal + + # Linux + # - name: Linux x86_64 + # os: ubuntu-22.04 + # backends: vulkan gl + + name: Test ${{ matrix.name }} + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v2 + - name: Install cargo-nextest + uses: taiki-e/install-action@v2 + with: + tool: cargo-nextest + - name: install swiftshader + if: matrix.os == 'ubuntu-22.04' + shell: bash + run: | + set -e + + mkdir -p swiftshader + curl -LsSf https://github.com/gfx-rs/ci-build/releases/latest/download/swiftshader-linux-x86_64.tar.xz | tar -xf - -C swiftshader + + echo "VK_ICD_FILENAMES=$PWD/swiftshader/vk_swiftshader_icd.json" >> $GITHUB_ENV + - name: install llvmpipe, vulkan sdk + if: matrix.os == 'ubuntu-22.04' + shell: bash + run: | + set -e + + sudo apt-get update -y -qq + + # vulkan sdk + wget -qO - https://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo apt-key add - + sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-jammy.list https://packages.lunarg.com/vulkan/lunarg-vulkan-jammy.list + + sudo apt-get update + sudo apt install -y libegl1-mesa libgl1-mesa-dri libxcb-xfixes0-dev vulkan-sdk + + - name: caching + uses: Swatinem/rust-cache@v2 + with: + key: build-${{ matrix.os }}-${{ env.CACHE_SUFFIX }} + + - name: run tests + shell: bash + run: | + set -e + + for backend in ${{ matrix.backends }}; do + echo "======= NATIVE TESTS $backend ======"; + WGPU_BACKEND=$backend cargo nextest run + done \ No newline at end of file diff --git a/README.md b/README.md index 8063d7f..e7d5d20 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ use threerender::{CameraStyle, LightBaseStyle, LightStyle, RendererBuilder, Hemi fn main() { let (width, height) = (2000, 1500); - let mut renderer_builder = RendererBuilder::new(); + let mut renderer_builder = pollster::block_on(RendererBuilder::new()); renderer_builder.set_width(width); renderer_builder.set_height(height); renderer_builder.set_background(RGBA::new(0, 0, 0, 1)); diff --git a/examples/camera/Cargo.toml b/examples/camera/Cargo.toml index 1f80d99..fee6faf 100644 --- a/examples/camera/Cargo.toml +++ b/examples/camera/Cargo.toml @@ -6,6 +6,10 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[[bin]] +name="camera" +path="src/main.rs" + [features] default = ["wgpu"] @@ -15,3 +19,4 @@ examples_common = { path = "../common" } wgpu = { git = "https://github.com/gfx-rs/wgpu", optional = true } winit = "0.27.5" image = "0.24.5" +pollster = "0.2.5" diff --git a/examples/camera/src/main.rs b/examples/camera/src/main.rs index 561eb92..2dcb9ea 100644 --- a/examples/camera/src/main.rs +++ b/examples/camera/src/main.rs @@ -233,8 +233,9 @@ fn main() { #[test] fn test_image() { let renderer_builder = build(); - let mut renderer = - threerender::renderer::Renderer::new::(renderer_builder, None); + let mut renderer = pollster::block_on(threerender::renderer::Renderer::new::< + winit::window::Window, + >(renderer_builder, None)); renderer.render(); let buf = renderer.load_as_image(); let mut file = std::fs::File::create("./test.png").unwrap(); diff --git a/examples/common/Cargo.toml b/examples/common/Cargo.toml index 8243daf..25d0d0b 100644 --- a/examples/common/Cargo.toml +++ b/examples/common/Cargo.toml @@ -6,7 +6,19 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] + [dependencies] threerender = { path = "../../threerender" } env_logger = "0.10.0" winit = "0.27.5" +pollster = "0.2.5" + +[target.'cfg(target_arch = "wasm32")'.dependencies] +console_error_panic_hook = "0.1.7" +console_log = "0.2" +js-sys = "0.3.63" +wasm-bindgen = "0.2.86" +wasm-bindgen-futures = "0.4.34" +wasm-bindgen-test = "0.3" +web-sys = "0.3.61" diff --git a/examples/common/src/lib.rs b/examples/common/src/lib.rs index f130699..ef2b8a9 100644 --- a/examples/common/src/lib.rs +++ b/examples/common/src/lib.rs @@ -24,13 +24,13 @@ pub enum CustomEvent { type StaticUpdater = Box>; -fn run( +async fn run( event_loop: EventLoop<()>, window: Window, renderer_builder: RendererBuilder, mut updater: StaticUpdater, ) { - let mut renderer = Renderer::new(renderer_builder, Some(&window)); + let mut renderer = Renderer::new(renderer_builder, Some(&window)).await; let mut cur_event = CustomEvent::ReDraw; event_loop.run(move |event, _, control_flow| { @@ -122,7 +122,7 @@ pub fn start(renderer_builder: RendererBuilder, updater: StaticUpdater) { { env_logger::init(); // Temporarily avoid srgb formats for the swapchain on the web - run(event_loop, window, renderer_builder, updater); + pollster::block_on(run(event_loop, window, renderer_builder, updater)); } #[cfg(target_arch = "wasm32")] { diff --git a/examples/draw_lines/Cargo.toml b/examples/draw_lines/Cargo.toml index 40a294f..53184ae 100644 --- a/examples/draw_lines/Cargo.toml +++ b/examples/draw_lines/Cargo.toml @@ -6,8 +6,13 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[[bin]] +name="draw_lines" +path="src/main.rs" + [dependencies] threerender = { path = "../../threerender" } examples_common = { path = "../common" } winit = "0.27.5" image = "0.24.5" +pollster = "0.2.5" diff --git a/examples/draw_lines/src/main.rs b/examples/draw_lines/src/main.rs index a4b0504..73ca7b0 100644 --- a/examples/draw_lines/src/main.rs +++ b/examples/draw_lines/src/main.rs @@ -128,8 +128,9 @@ fn main() { #[test] fn test_image() { let renderer_builder = build(); - let mut renderer = - threerender::renderer::Renderer::new::(renderer_builder, None); + let mut renderer = pollster::block_on(threerender::renderer::Renderer::new::< + winit::window::Window, + >(renderer_builder, None)); renderer.render(); let buf = renderer.load_as_image(); let mut file = std::fs::File::create("./test.png").unwrap(); diff --git a/examples/dynamic_entity/Cargo.toml b/examples/dynamic_entity/Cargo.toml index 0803958..9504fb0 100644 --- a/examples/dynamic_entity/Cargo.toml +++ b/examples/dynamic_entity/Cargo.toml @@ -6,6 +6,10 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[[bin]] +name="dynamic_entity" +path="src/main.rs" + [features] default = ["wgpu"] @@ -16,3 +20,4 @@ wgpu = { git = "https://github.com/gfx-rs/wgpu", optional = true } image = "0.24.5" rand = "0.8.5" winit = "0.27.5" +pollster = "0.2.5" diff --git a/examples/dynamic_entity/src/main.rs b/examples/dynamic_entity/src/main.rs index bcf6b08..0f3deb2 100644 --- a/examples/dynamic_entity/src/main.rs +++ b/examples/dynamic_entity/src/main.rs @@ -128,8 +128,9 @@ fn test_image() { sphere, rand: Box::new(Rand { cnt: 0. }), }; - let mut renderer = - threerender::renderer::Renderer::new::(renderer_builder, None); + let mut renderer = pollster::block_on(threerender::renderer::Renderer::new::< + winit::window::Window, + >(renderer_builder, None)); app.update(&mut renderer, CustomEvent::MouseDown); app.update(&mut renderer, CustomEvent::MouseDown); diff --git a/examples/gltf/Cargo.toml b/examples/gltf/Cargo.toml index 7686695..a7146b8 100644 --- a/examples/gltf/Cargo.toml +++ b/examples/gltf/Cargo.toml @@ -6,6 +6,10 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[[bin]] +name="gltf" +path="src/main.rs" + [features] default = ["wgpu", "duck"] duck = [] @@ -20,3 +24,4 @@ wgpu = { git = "https://github.com/gfx-rs/wgpu", optional = true } gltf = { version = "1.1.0" } winit = "0.27.5" image = "0.24.5" +pollster = "0.2.5" diff --git a/examples/gltf/src/main.rs b/examples/gltf/src/main.rs index 8e596f8..daeedde 100644 --- a/examples/gltf/src/main.rs +++ b/examples/gltf/src/main.rs @@ -247,8 +247,9 @@ fn main() { #[test] fn test_image() { let renderer_builder = build(); - let mut renderer = - threerender::renderer::Renderer::new::(renderer_builder, None); + let mut renderer = pollster::block_on(threerender::renderer::Renderer::new::< + winit::window::Window, + >(renderer_builder, None)); renderer.render(); let buf = renderer.load_as_image(); let mut file = std::fs::File::create("./test.png").unwrap(); diff --git a/examples/hello_world/Cargo.toml b/examples/hello_world/Cargo.toml index c88aac2..adffc2d 100644 --- a/examples/hello_world/Cargo.toml +++ b/examples/hello_world/Cargo.toml @@ -6,6 +6,10 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[[bin]] +name="hello_world" +path="src/main.rs" + [features] default = ["wgpu"] @@ -16,3 +20,4 @@ wgpu = { git = "https://github.com/gfx-rs/wgpu", optional = true } glam = "0.22.0" winit = "0.27.5" image = "0.24.5" +pollster = "0.2.5" diff --git a/examples/hello_world/src/main.rs b/examples/hello_world/src/main.rs index f8e44c1..39b9719 100644 --- a/examples/hello_world/src/main.rs +++ b/examples/hello_world/src/main.rs @@ -162,8 +162,9 @@ fn main() { #[test] fn test_image() { let renderer_builder = build(); - let mut renderer = - threerender::renderer::Renderer::new::(renderer_builder, None); + let mut renderer = pollster::block_on(threerender::renderer::Renderer::new::< + winit::window::Window, + >(renderer_builder, None)); renderer.render(); let buf = renderer.load_as_image(); let mut file = std::fs::File::create("./test.png").unwrap(); diff --git a/examples/normal_map/Cargo.toml b/examples/normal_map/Cargo.toml index f9730f8..21a3ea2 100644 --- a/examples/normal_map/Cargo.toml +++ b/examples/normal_map/Cargo.toml @@ -6,6 +6,10 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[[bin]] +name="normal_map" +path="src/main.rs" + [features] default = ["wgpu"] @@ -15,3 +19,4 @@ examples_common = { path = "../common" } wgpu = { git = "https://github.com/gfx-rs/wgpu", optional = true } winit = "0.27.5" image = "0.24.5" +pollster = "0.2.5" diff --git a/examples/normal_map/src/main.rs b/examples/normal_map/src/main.rs index 4314f69..3761f5c 100644 --- a/examples/normal_map/src/main.rs +++ b/examples/normal_map/src/main.rs @@ -241,8 +241,9 @@ fn main() { #[test] fn test_image() { let renderer_builder = build(); - let mut renderer = - threerender::renderer::Renderer::new::(renderer_builder, None); + let mut renderer = pollster::block_on(threerender::renderer::Renderer::new::< + winit::window::Window, + >(renderer_builder, None)); renderer.render(); let buf = renderer.load_as_image(); let mut file = std::fs::File::create("./test.png").unwrap(); diff --git a/examples/renderer_specific/Cargo.toml b/examples/renderer_specific/Cargo.toml index 278483e..113f402 100644 --- a/examples/renderer_specific/Cargo.toml +++ b/examples/renderer_specific/Cargo.toml @@ -6,6 +6,10 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[[bin]] +name="renderer_specific" +path="src/main.rs" + [features] default = ["wgpu"] @@ -16,3 +20,4 @@ wgpu = { git = "https://github.com/gfx-rs/wgpu", optional = true } glam = "0.22.0" winit = "0.27.5" image = "0.24.5" +pollster = "0.2.5" diff --git a/examples/renderer_specific/src/main.rs b/examples/renderer_specific/src/main.rs index 63ec5fb..d4fbc8d 100644 --- a/examples/renderer_specific/src/main.rs +++ b/examples/renderer_specific/src/main.rs @@ -176,8 +176,9 @@ fn main() { #[test] fn test_image() { let renderer_builder = build(); - let mut renderer = - threerender::renderer::Renderer::new::(renderer_builder, None); + let mut renderer = pollster::block_on(threerender::renderer::Renderer::new::< + winit::window::Window, + >(renderer_builder, None)); renderer.render(); let buf = renderer.load_as_image(); let mut file = std::fs::File::create("./test.png").unwrap(); diff --git a/examples/shadow/Cargo.toml b/examples/shadow/Cargo.toml index 695a87c..c3bbcae 100644 --- a/examples/shadow/Cargo.toml +++ b/examples/shadow/Cargo.toml @@ -6,6 +6,10 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[[bin]] +name="shadow" +path="src/main.rs" + [features] default = ["wgpu"] @@ -16,3 +20,4 @@ wgpu = { git = "https://github.com/gfx-rs/wgpu", optional = true } glam = "0.22.0" winit = "0.27.5" image = "0.24.5" +pollster = "0.2.5" diff --git a/examples/shadow/src/main.rs b/examples/shadow/src/main.rs index f9edb95..b9d2053 100644 --- a/examples/shadow/src/main.rs +++ b/examples/shadow/src/main.rs @@ -177,8 +177,9 @@ fn main() { #[test] fn test_image() { let renderer_builder = build(); - let mut renderer = - threerender::renderer::Renderer::new::(renderer_builder, None); + let mut renderer = pollster::block_on(threerender::renderer::Renderer::new::< + winit::window::Window, + >(renderer_builder, None)); renderer.render(); let buf = renderer.load_as_image(); let mut file = std::fs::File::create("./test.png").unwrap(); diff --git a/examples/simple/Cargo.toml b/examples/simple/Cargo.toml index cacdc30..65636e8 100644 --- a/examples/simple/Cargo.toml +++ b/examples/simple/Cargo.toml @@ -6,6 +6,10 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[[bin]] +name="simple" +path="src/main.rs" + [features] default = ["wgpu"] @@ -16,3 +20,8 @@ glam = "0.22.0" env_logger = "0.10.0" winit = "0.27.5" image = "0.24.5" +pollster = "0.2.5" +wasm-bindgen-futures = "0.4.34" + +[target.'cfg(target_arch = "wasm32")'.dependencies] +web-sys = "0.3.61" diff --git a/examples/simple/src/main.rs b/examples/simple/src/main.rs index e29ecb6..3389225 100644 --- a/examples/simple/src/main.rs +++ b/examples/simple/src/main.rs @@ -10,7 +10,7 @@ use threerender::{CameraStyle, LightBaseStyle, LightStyle, RendererBuilder}; const WIDTH: u32 = 2000; const HEIGHT: u32 = 1500; -fn render() -> ( +async fn render() -> ( Renderer, Option, Option>, @@ -90,16 +90,28 @@ fn render() -> ( (Some(window), Some(event_loop)) }; - let renderer = Renderer::new(renderer_builder, window.as_ref()); + let renderer = Renderer::new(renderer_builder, window.as_ref()).await; (renderer, window, event_loop) } -fn main() { - let (mut renderer, window, event_loop) = render(); +async fn run() { + let (mut renderer, window, event_loop) = render().await; + + #[cfg(target_arch = "wasm32")] + { + use winit::platform::web::WindowExtWebSys; + // On wasm, append the canvas to the document body + web_sys::window() + .and_then(|win| win.document()) + .and_then(|doc| doc.body()) + .and_then(|body| { + body.append_child(&web_sys::Element::from(window.as_ref().unwrap().canvas())) + .ok() + }) + .expect("couldn't append canvas to document body"); + } - // TODO: Support wasm - #[cfg(not(target_arch = "wasm32"))] { event_loop .unwrap() @@ -126,9 +138,16 @@ fn main() { } } +fn main() { + #[cfg(not(target_arch = "wasm32"))] + pollster::block_on(run()); + #[cfg(target_arch = "wasm32")] + wasm_bindgen_futures::spawn_local(run()); +} + #[test] fn test_image() { - let (mut renderer, _, _) = render(); + let (mut renderer, _, _) = pollster::block_on(render()); renderer.render(); let buf = renderer.load_as_image(); let mut file = std::fs::File::create("./test.png").unwrap(); diff --git a/examples/texture2d/Cargo.toml b/examples/texture2d/Cargo.toml index 7abe555..d964d9c 100644 --- a/examples/texture2d/Cargo.toml +++ b/examples/texture2d/Cargo.toml @@ -6,6 +6,11 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[[bin]] +name="texture2d" +path="src/main.rs" + + [features] default = ["wgpu"] @@ -15,3 +20,4 @@ examples_common = { path = "../common" } wgpu = { git = "https://github.com/gfx-rs/wgpu", optional = true } image = "0.24.5" winit = "0.27.5" +pollster = "0.2.5" diff --git a/examples/texture2d/src/main.rs b/examples/texture2d/src/main.rs index 02cb7bd..badd4d5 100644 --- a/examples/texture2d/src/main.rs +++ b/examples/texture2d/src/main.rs @@ -141,8 +141,9 @@ fn main() { #[test] fn test_image() { let renderer_builder = build(); - let mut renderer = - threerender::renderer::Renderer::new::(renderer_builder, None); + let mut renderer = pollster::block_on(threerender::renderer::Renderer::new::< + winit::window::Window, + >(renderer_builder, None)); renderer.render(); let buf = renderer.load_as_image(); let mut file = std::fs::File::create("./test.png").unwrap(); diff --git a/shader_processor/Cargo.toml b/shader_processor/Cargo.toml index 3f44ca6..1a56160 100644 --- a/shader_processor/Cargo.toml +++ b/shader_processor/Cargo.toml @@ -5,6 +5,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] + [features] default = ["wgsl"] wgsl = [] diff --git a/threerender/Cargo.toml b/threerender/Cargo.toml index 3bda491..783af20 100644 --- a/threerender/Cargo.toml +++ b/threerender/Cargo.toml @@ -5,6 +5,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] + [features] default = ["wgpu", "wgsl", "entities"] wgsl = ["shader_processor/wgsl"] @@ -13,7 +15,6 @@ entities = ["threerender_entities"] [dependencies] bytemuck = { version = "1.12.3", features = ["derive"]} glam = "0.22.0" -pollster = "0.2.5" raw-window-handle = "0.5.0" wgpu = { git = "https://github.com/gfx-rs/wgpu", optional = true } threerender_traits = { path = "../threerender_traits" } @@ -22,6 +23,7 @@ threerender_color = { path = "../threerender_color" } threerender_entities = { path = "../threerender_entities", optional = true } shader_processor = { path = "../shader_processor", optional = true } getset = "0.1.2" +pollster = "0.2.5" [dev-dependencies] winit = "0.27.5" diff --git a/threerender/src/lib.rs b/threerender/src/lib.rs index 7fcfda3..0b103e7 100644 --- a/threerender/src/lib.rs +++ b/threerender/src/lib.rs @@ -87,7 +87,7 @@ window.set_inner_size(winit::dpi::PhysicalSize::new( renderer_builder.height(), )); -let mut renderer = Renderer::new(renderer_builder, Some(&window)); +let mut renderer = pollster::block_on(Renderer::new(renderer_builder, Some(&window))); event_loop.run(move |event, _target, control_flow| { match event { winit::event::Event::WindowEvent { diff --git a/threerender/src/renderer/_wgpu/builder.rs b/threerender/src/renderer/_wgpu/builder.rs index e03bd8f..f205ce1 100644 --- a/threerender/src/renderer/_wgpu/builder.rs +++ b/threerender/src/renderer/_wgpu/builder.rs @@ -11,7 +11,7 @@ impl Default for RendererSpecificAttributes { fn default() -> Self { Self { features: Features::TEXTURE_BINDING_ARRAY, - adapter_features: false, + adapter_features: true, } } } diff --git a/threerender/src/renderer/_wgpu/renderer.rs b/threerender/src/renderer/_wgpu/renderer.rs index bb34d7a..67356d2 100644 --- a/threerender/src/renderer/_wgpu/renderer.rs +++ b/threerender/src/renderer/_wgpu/renderer.rs @@ -638,7 +638,7 @@ impl Renderer { impl Renderer { const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float; - pub fn new< + pub async fn new< W: raw_window_handle::HasRawWindowHandle + raw_window_handle::HasRawDisplayHandle, >( mut renderer_builder: RendererBuilder, @@ -653,13 +653,15 @@ impl Renderer { }); let surface = window.map(|w| unsafe { instance.create_surface(w) }.unwrap()); - let adapter = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions { - power_preference: wgpu::PowerPreference::default(), - force_fallback_adapter: false, - // Request an adapter which can render to our surface - compatible_surface: surface.as_ref(), - })) - .expect("Failed to find an appropriate adapter"); + let adapter = instance + .request_adapter(&wgpu::RequestAdapterOptions { + power_preference: wgpu::PowerPreference::default(), + force_fallback_adapter: false, + // Request an adapter which can render to our surface + compatible_surface: surface.as_ref(), + }) + .await + .expect("Failed to find an appropriate adapter"); let adapter_features = if renderer_builder .renderer_specific_attributes @@ -674,16 +676,19 @@ impl Renderer { // TODO: Use constant variable to reduce group. limits.max_bind_groups = 5; // Create the logical device and command queue - let (device, queue) = pollster::block_on(adapter.request_device( - &wgpu::DeviceDescriptor { - label: None, - features: adapter_features | renderer_builder.renderer_specific_attributes.features, - // Make sure we use the texture resolution limits from the adapter, so we can support images the size of the swapchain. - limits, - }, - None, - )) - .expect("Failed to create device"); + let (device, queue) = adapter + .request_device( + &wgpu::DeviceDescriptor { + label: None, + features: adapter_features + | renderer_builder.renderer_specific_attributes.features, + // Make sure we use the texture resolution limits from the adapter, so we can support images the size of the swapchain. + limits, + }, + None, + ) + .await + .expect("Failed to create device"); let config = if let Some(surface) = &surface { surface diff --git a/threerender_entities/Cargo.toml b/threerender_entities/Cargo.toml index 7e70e08..8b276ff 100644 --- a/threerender_entities/Cargo.toml +++ b/threerender_entities/Cargo.toml @@ -5,6 +5,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] + [dependencies] threerender_traits = { path = "../threerender_traits" } threerender_math = { path = "../threerender_math" } diff --git a/threerender_loader/Cargo.toml b/threerender_loader/Cargo.toml index 064c041..132d5e6 100644 --- a/threerender_loader/Cargo.toml +++ b/threerender_loader/Cargo.toml @@ -5,6 +5,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] + [features] default = ["gltf_loader"] gltf_loader = ["gltf"] diff --git a/threerender_math/Cargo.toml b/threerender_math/Cargo.toml index 5954901..7d19eb2 100644 --- a/threerender_math/Cargo.toml +++ b/threerender_math/Cargo.toml @@ -5,5 +5,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] + [dependencies] glam = "0.22.0" diff --git a/threerender_traits/Cargo.toml b/threerender_traits/Cargo.toml index 4b61da0..2f5d100 100644 --- a/threerender_traits/Cargo.toml +++ b/threerender_traits/Cargo.toml @@ -5,6 +5,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[lib] + [dependencies] threerender_math = { path = "../threerender_math" } threerender_color = { path = "../threerender_color" }