Skip to content

matthewjberger/wgpu-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

115 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust / Winit / Egui / Wgpu Triangle

A cross-platform Rust graphics demo using wgpu to render a spinning triangle. Supports native desktop, WebGL/WebGPU (WASM), Android, Steam Deck, and OpenXR VR with hand tracking.

Related Projects:

native

Other languages (experimental):

Quickstart

All platforms are driven through the justfile. Run just (no args) to list every recipe.

Platform Run Build only
Native Desktop just run just build
WebGPU just run-webgpu just build-webgpu
WebGL just run-webgl just build-webgl
Android just run-android DEVICE_ID just build-android
Android (all archs) — just build-android-all
Steam Deck just build-steamdeck && just deploy-steamdeck just build-steamdeck
OpenXR VR (Desktop) just run-openxr just build-openxr
OpenXR VR (Quest) just build-android-openxr + adb install -r target/x/release/android/app_core.apk just build-android-openxr

First-time setup per platform: just init-wasm, just init-android, just init-steamdeck.

Platform Setup

Native Desktop

just run           # Release build, runs the `app` binary
just build         # Release build only
just run-openxr    # Run with the OpenXR feature (desktop VR, see below)
just build-openxr  # Build the OpenXR binary without running it

Web (WebAssembly)

Prerequisites: trunk

First-time setup:

just init-wasm

Serve locally:

just run-webgpu  # Serves on http://localhost:8080 and opens the browser
just run-webgl   # WebGL fallback for older browsers

Build only (outputs to dist/):

just build-webgpu
just build-webgl

Browser Support: All Chromium-based browsers (Chrome, Brave, Vivaldi) support WebGPU. Firefox supports WebGPU starting with version 141 (announcement).

Android

Prerequisites:

  • xbuild
  • Android SDK and NDK
  • Connected Android device or emulator (API level 24+)

First-time setup:

just init-android

Build and run:

just list-android          # Find your device ID
just run-android DEVICE_ID # e.g., just run-android RFCY61DZZKT

Connect via USB with USB debugging enabled, or use wireless debugging (see below).

The build uses --features android which enables wgpu's Vulkan backend.

Wireless Debugging Setup
  1. Enable Developer options: Settings > About phone > tap Build number 7 times
  2. Disable auto-blocker if present (Samsung): Settings > Security > Auto Blocker
  3. Enable wireless debugging: Settings > Developer options > Wireless debugging
  4. Tap Pair device with pairing code and note the IP:port
  5. Pair and connect:
    just pair-android 192.168.1.100:37000  # Enter pairing code when prompted
    just list-android                       # Get device ID
    just run-android DEVICE_ID
Additional Android Commands
just build-android              # Build only (windowed app)
just build-android-all          # Build for arm64 and x64
just build-android-openxr       # Build for Meta Quest VR
just install-android DEVICE_ID  # Install without running
just connect-android IP:PORT    # Connect over wireless ADB
just list-android               # List connected devices

Steam Deck

Prerequisites:

  • cross
  • Docker Desktop running (for cross-compilation)

First-time setup:

just init-steamdeck

This installs cross and a Linux stable toolchain (stable-x86_64-unknown-linux-gnu). The Linux toolchain won't run natively on Windows/macOS, but cross mounts your ~/.rustup into its Linux container so it gets used there — overriding the older rustc baked into cross 0.2.5's image so modern crates (egui, wgpu) can build.

Build and deploy:

just build-steamdeck   # Cross-compiles to target/x86_64-unknown-linux-gnu/release/app
just deploy-steamdeck  # Transfers to steamdeck.local:~/Downloads

Run on Steam Deck:

just steamdeck-ssh
cd ~/Downloads && ./app

The Cross.toml file configures system libraries for graphics and windowing support.

OpenXR VR Mode (Desktop)

Renders the spinning triangle with an infinite grid, procedural skybox, and hand tracking in VR via PCVR streaming.

Setup:

  1. Install SteamVR
  2. Install Virtual Desktop or another OpenXR-compatible runtime
  3. Start Virtual Desktop and stream your desktop to your VR headset
  4. Run just run-openxr on your desktop

OpenXR VR Mode (Meta Quest)

Native standalone VR for Meta Quest 2, Quest Pro, Quest 3, and Quest 3S.

Prerequisites:

  • All Android prerequisites (see above)
  • Meta Quest device with Developer Mode enabled

Build:

just build-android-openxr

This produces an APK at target/x/release/android/app_core.apk.

Install on Quest:

adb install -r target/x/release/android/app_core.apk

Or use SideQuest to drag and drop the APK onto your Quest.

The app appears in your Quest library under "Unknown Sources".

Technical Notes
  • Uses the android-openxr feature which combines android and openxr features
  • Bundles Meta's OpenXR loader from libs/arm64-v8a/libopenxr_loader.so
  • Manifest includes com.oculus.intent.category.VR for proper VR app handling
  • Supports Quest hand tracking and controller input
  • Requires manifest.yaml with runtime_libs configuration for library bundling

Screenshots

webgl webgpu

About

A minimal example of using Rust, wgpu, and egui without using eframe 🦀 Works on Windows/Linux/MacOS/Web/Android/OpenXR (Such as Quest 3 + Virtual Desktop)

Topics

Resources

Stars

Watchers

Forks

Sponsor this project

 

Contributors