Giter Club home page Giter Club logo

wgpu-in-app's Introduction

wgpu in App

Minimum Rust Version Build Status MIT License

Integrate wgpu into your existing iOS | Android apps.

wgpu does not depend on any window program, so it does not provide window creation and management functions. Only when creating a window-based Surface, an argument that implements the raw-window-handle abstract interface may be needed (may be needed because on iOS/macOS, instance of Surface can be created directly by CAMetalLayer). The winit used by the wgpu examples is a cross-platform window creation and management crate that implements the raw-window-handle abstract interface. It will take over the window management and events loop of the entire app, there is no doubt that for game apps, the combination of wgpu + winit is very suitable.

However, a large number of non-game apps also need to use graphics APIs (such as charts, image filters, etc.). These apps may require a large number of system components, as well as the ability to freely control various input devices (e.g., stylus, motion sensors). So, it would be very useful to integrate wgpu into these apps without using third-party window management libraries.

Screenshot

wgpu in iOS wgpu in Android
on_visionOS.mp4

iOS | iPadOS | visionOS

Add target

# Add Apple device (iOS | iPadOS | visionOS) target
# Since iPhone 5 and later are all 64-bit devices, `armv7s-apple-ios` and `armv7-apple-ios` are not required.
rustup target add aarch64-apple-ios

# Add Apple Simulator target
# M1+ Mac
rustup target add aarch64-apple-ios-sim

Build for Apple real device

# Build for iOS | iPadOS
sh ./apple_lib_build.sh --release

Then, Open Apple/wgpu_in_App.xcodeproj with Xcode and run on iPhone、iPad.

Build for visionOS Simulator

sh ./apple_lib_build.sh aarch64-apple-ios-sim --release

Then, Open Apple/wgpu_in_App.xcodeproj with Xcode 15 Beta 2+ and run on visionOS 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

Install cargo so subcommand

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

Build

# 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

# Build
sh ./android_lib_build.sh --release

Desktop

# Use primary backend (metal vulkan or dx12, depend on your computer OS).
cargo run
# Use OpenGL backend (platforms other than Linux, need to add the `angle` feature).
# https://github.com/gfx-rs/wgpu/pull/2461
WGPU_BACKEND=gl cargo run --features=angle
# Use Vulkan backend (on macOS, need to add the `vulkan-portability` feature)
# https://github.com/gfx-rs/wgpu/pull/2488
WGPU_BACKEND=vk cargo run --features=vulkan-portability
# Then, press 0, 1, 2, 3, 4 keys change running example.

wgpu-in-app's People

Contributors

jinleili avatar frozendevil avatar rizerco avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.