Rowandjj / wgpu-on-app

Integrate wgpu on iOS | Android Apps without using winit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

wgpu on App

Integrate wgpu on your existing iOS | Android apps.

winit-free mode can useful for integrating wgpu into existing apps to implement some graphics features.

Screenshot

wgpu on iOS wgpu on Android

iOS

Add build target

Since iPhone 5 and later are 64-bit devices, armv7s-apple-ios and armv7-apple-ios are not required.

# Add hardware iOS target
rustup target add aarch64-apple-ios 
# Add iOS simulator target
# Intel CPU Mac
rustup target add x86_64-apple-ios
# M1 Mac
rustup target add aarch64-apple-ios-sim

Build and run

Build for iOS device and simulator

# Use Metal backend
cargo build --target aarch64-apple-ios && cargo build --target <aarch64-apple-ios-sim or x86_64-apple-ios>

Then, Open iOS/wgpu_on_iOS.xcodeproj with Xcode, select wgpu_phone scheme run on iOS device, wgpu_simulator scheme run on simulator.

About Rust and Swift Interaction

Passing Primitive Data Between Rust and iOS

Passing Owned Objects between Rust and iOS

Sending a boxed trait over FFI

Android

Set up Android environment

Assuming your computer already has Android Studio installed, go to Android Studio > Tools > SDK Manager > Android SDK > SDK Tools. Check the following options for installation and click OK.

  • Android SDK Build-Tools
  • Android SDK Command-line Tools
  • NDK(Side by side)

Then, set two following environment variables:

export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
# Replace the NDK version number with the version you installed 
export NDK_HOME=$ANDROID_SDK_ROOT/ndk/23.1.7779620

Add build targets

Since simulator and virtual devices only support GLES, x86_64-linux-android and i686-linux-android targets are not necessary

rustup target add aarch64-linux-android armv7-linux-androideabi

Install cargo so subcommand

# from crates.io
cargo install cargo-so
# frome source code
cargo install --path cargo-so

Build

# currently, multi-target build only useable on the nightly channel
cargo so b --lib --target aarch64-linux-android --release
cargo so b --lib --target armv7-linux-androideabi --release

# copy .so files to android project jniLibs folder
cp target/aarch64-linux-android/release/libwgpu_on_app.so android/app/libs/arm64-v8a/libwgpu_on_app.so
cp target/armv7-linux-androideabi/release/libwgpu_on_app.so android/app/libs/armeabi-v7a/libwgpu_on_app.so

Desktop

# Use Metal backend.
cargo run
# Use GL backend, need `Angle` libs on your computer.
# https://github.com/gfx-rs/wgpu/pull/2461
WGPU_BACKEND=gl cargo run --features angle
# Use Vulkan backend
# https://github.com/gfx-rs/wgpu/pull/2488
cargo run --features vulkan-portability
# Then, press 0, 1, 2, 3, 4 keys change running example.

About

Integrate wgpu on iOS | Android Apps without using winit


Languages

Language:Rust 90.2%Language:Kotlin 6.4%Language:Swift 2.1%Language:Shell 0.8%Language:C 0.3%Language:Objective-C 0.1%