diff --git a/agdk-cpal/Cargo.toml b/agdk-cpal/Cargo.toml index 6bdf574..92c7c01 100644 --- a/agdk-cpal/Cargo.toml +++ b/agdk-cpal/Cargo.toml @@ -3,8 +3,6 @@ name = "agdk-cpal" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] tracing = "0.1" tracing-subscriber = { version = "0.3", features = [ diff --git a/agdk-cpal/README.md b/agdk-cpal/README.md index 5034864..4862b6f 100644 --- a/agdk-cpal/README.md +++ b/agdk-cpal/README.md @@ -2,7 +2,7 @@ This is a minimal test application based on `GameActivity` that just runs a mainloop based on android_activity::poll_events() and plays a sine wave audio test using the Cpal audio library. -``` +```bash export ANDROID_NDK_HOME="path/to/ndk" export ANDROID_HOME="path/to/sdk" diff --git a/agdk-cpal/src/lib.rs b/agdk-cpal/src/lib.rs index 0172129..d34f42f 100644 --- a/agdk-cpal/src/lib.rs +++ b/agdk-cpal/src/lib.rs @@ -1,13 +1,13 @@ -///! Based on https://github.com/RustAudio/cpal/blob/master/examples/android.rs -use android_activity::{AndroidApp, InputStatus, MainEvent, PollEvent}; +//! Based on https://github.com/RustAudio/cpal/blob/master/examples/android.rs + use std::sync::OnceLock; -use tracing::{error, info}; +use android_activity::{AndroidApp, InputStatus, MainEvent, PollEvent}; use cpal::{ traits::{DeviceTrait, HostTrait, StreamTrait}, - SizedSample, + FromSample, Sample, SizedSample, }; -use cpal::{FromSample, Sample}; +use tracing::{error, info}; fn write_data(output: &mut [T], channels: usize, next_sample: &mut dyn FnMut() -> f32) where diff --git a/agdk-eframe/Cargo.toml b/agdk-eframe/Cargo.toml index 84ad5c4..d20c9ed 100644 --- a/agdk-eframe/Cargo.toml +++ b/agdk-eframe/Cargo.toml @@ -4,8 +4,6 @@ version = "0.1.0" edition = "2021" resolver = "2" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] tracing = "0.1" tracing-subscriber = { version = "0.3", features = [ diff --git a/agdk-eframe/README.md b/agdk-eframe/README.md index bdd1415..0abb2c1 100644 --- a/agdk-eframe/README.md +++ b/agdk-eframe/README.md @@ -3,7 +3,7 @@ This tests using `GameActivity` with egui, winit and wgpu. This is based on a re-worked winit backend here: https://github.com/rib/winit/tree/android-activity -``` +```bash export ANDROID_NDK_HOME="path/to/ndk" export ANDROID_HOME="path/to/sdk" diff --git a/agdk-eframe/src/lib.rs b/agdk-eframe/src/lib.rs index fbedc47..de1f13f 100644 --- a/agdk-eframe/src/lib.rs +++ b/agdk-eframe/src/lib.rs @@ -1,7 +1,5 @@ -use eframe::egui; -use eframe::{NativeOptions, Renderer}; +use eframe::{egui, NativeOptions, Renderer}; use tracing::{error, info}; - #[cfg(target_os = "android")] use winit::platform::android::activity::AndroidApp; diff --git a/agdk-egui/Cargo.toml b/agdk-egui/Cargo.toml index 01017ac..a47a511 100644 --- a/agdk-egui/Cargo.toml +++ b/agdk-egui/Cargo.toml @@ -4,8 +4,6 @@ version = "0.1.0" edition = "2021" resolver = "2" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] tracing = "0.1" tracing-subscriber = { version = "0.3", features = [ diff --git a/agdk-egui/src/lib.rs b/agdk-egui/src/lib.rs index 1df8393..db0f2ca 100644 --- a/agdk-egui/src/lib.rs +++ b/agdk-egui/src/lib.rs @@ -1,22 +1,17 @@ #[cfg(target_os = "android")] use std::sync::OnceLock; use std::{num::NonZeroU32, sync::Arc}; -use tracing::{debug, error}; use egui::ViewportId; -use egui_wgpu::RendererOptions; -use egui_winit::winit; - -use winit::event_loop::{ActiveEventLoop, EventLoop}; - +use egui_wgpu::{winit::Painter, RendererOptions}; +use egui_winit::{winit, State}; +use tracing::{debug, error}; #[cfg(target_os = "android")] use winit::platform::android::activity::AndroidApp; - -use winit::event_loop::ControlFlow; - -use egui_wgpu::winit::Painter; -use egui_winit::State; -use winit::event::Event::*; +use winit::{ + event::Event::*, + event_loop::{ActiveEventLoop, ControlFlow, EventLoop}, +}; const INITIAL_WIDTH: u32 = 1920; const INITIAL_HEIGHT: u32 = 1080; diff --git a/agdk-mainloop/Cargo.toml b/agdk-mainloop/Cargo.toml index ee846ae..dc154b9 100644 --- a/agdk-mainloop/Cargo.toml +++ b/agdk-mainloop/Cargo.toml @@ -3,8 +3,6 @@ name = "agdk-mainloop" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] tracing = "0.1" tracing-subscriber = { version = "0.3", features = [ diff --git a/agdk-mainloop/README.md b/agdk-mainloop/README.md index 19a6abb..fe3ffb8 100644 --- a/agdk-mainloop/README.md +++ b/agdk-mainloop/README.md @@ -3,7 +3,7 @@ runs a mainloop based on android_activity::poll_events() and traces the events received without doing any rendering. It also saves and restores some minimal application state. -``` +```bash export ANDROID_NDK_HOME="path/to/ndk" export ANDROID_HOME="path/to/sdk" diff --git a/agdk-mainloop/src/lib.rs b/agdk-mainloop/src/lib.rs index 25ad97e..a453430 100644 --- a/agdk-mainloop/src/lib.rs +++ b/agdk-mainloop/src/lib.rs @@ -227,6 +227,7 @@ fn android_main(app: AndroidApp) { } InputEvent::MotionEvent(motion_event) => { println!("action = {:?}", motion_event.action()); + #[expect(clippy::single_match)] match motion_event.action() { MotionAction::Up => { let pointer = motion_event.pointer_index(); @@ -367,7 +368,7 @@ fn character_map_and_combine_key( Some(unicode) }; *combining_accent = None; - combined_unicode.map(|unicode| KeyMapChar::Unicode(unicode)) + combined_unicode.map(KeyMapChar::Unicode) } else { Some(KeyMapChar::Unicode(unicode)) } diff --git a/agdk-oboe/Cargo.toml b/agdk-oboe/Cargo.toml index 4c9e509..1a9a5c5 100644 --- a/agdk-oboe/Cargo.toml +++ b/agdk-oboe/Cargo.toml @@ -3,8 +3,6 @@ name = "agdk-oboe" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] log = "0.4" android_logger = "0.13.1" @@ -14,4 +12,4 @@ atomic_float = "0.1" [lib] name="main" -crate_type=["cdylib"] \ No newline at end of file +crate_type=["cdylib"] diff --git a/agdk-oboe/README.md b/agdk-oboe/README.md index 6ffaf78..636c1c7 100644 --- a/agdk-oboe/README.md +++ b/agdk-oboe/README.md @@ -2,7 +2,7 @@ This is a minimal test application based on `GameActivity` that just runs a mainloop based on android_activity::poll_events() and plays a sine wave audio test using the Oboe audio library. -``` +```bash export ANDROID_NDK_HOME="path/to/ndk" export ANDROID_HOME="path/to/sdk" diff --git a/agdk-oboe/src/audio.rs b/agdk-oboe/src/audio.rs index c2a0571..8d196c4 100644 --- a/agdk-oboe/src/audio.rs +++ b/agdk-oboe/src/audio.rs @@ -1,10 +1,10 @@ -use atomic_float::AtomicF32; use std::{ f32::consts::PI, marker::PhantomData, sync::{atomic::Ordering, Arc}, }; +use atomic_float::AtomicF32; use oboe::{ AudioDeviceDirection, AudioDeviceInfo, AudioFeature, AudioOutputCallback, AudioOutputStream, AudioOutputStreamSafe, AudioStream, AudioStreamAsync, AudioStreamBase, AudioStreamBuilder, diff --git a/agdk-winit-wgpu/Cargo.toml b/agdk-winit-wgpu/Cargo.toml index c7029c7..979306b 100644 --- a/agdk-winit-wgpu/Cargo.toml +++ b/agdk-winit-wgpu/Cargo.toml @@ -3,8 +3,6 @@ name = "agdk-winit-wgpu" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] tracing = "0.1" tracing-subscriber = { version = "0.3", features = [ diff --git a/agdk-winit-wgpu/src/app.rs b/agdk-winit-wgpu/src/app.rs index e0f4305..3d66c1f 100644 --- a/agdk-winit-wgpu/src/app.rs +++ b/agdk-winit-wgpu/src/app.rs @@ -1,21 +1,19 @@ -use std::borrow::Cow; #[cfg(target_os = "android")] use std::ffi::c_void; #[cfg(target_os = "android")] use std::ptr::NonNull; -use std::sync::Arc; - -use tracing::{error, info, trace, warn}; +use std::{borrow::Cow, sync::Arc}; use raw_window_handle::{HandleError, HasDisplayHandle, HasWindowHandle}; -use wgpu::{Adapter, Device, Instance, PipelineLayout, Queue, RenderPipeline, ShaderModule}; -use wgpu::{PipelineCompilationOptions, TextureFormat}; - -use winit::error::EventLoopError; -use winit::event_loop::{EventLoop, EventLoopProxy}; +use tracing::{error, info, trace, warn}; +use wgpu::{ + Adapter, Device, Instance, PipelineCompilationOptions, PipelineLayout, Queue, RenderPipeline, + ShaderModule, TextureFormat, +}; use winit::{ + error::EventLoopError, event::{Event, WindowEvent}, - event_loop::{ActiveEventLoop, ControlFlow}, + event_loop::{ActiveEventLoop, ControlFlow, EventLoop, EventLoopProxy}, }; #[derive(Debug)] diff --git a/agdk-winit-wgpu/src/lib.rs b/agdk-winit-wgpu/src/lib.rs index 996056f..c2b0e66 100644 --- a/agdk-winit-wgpu/src/lib.rs +++ b/agdk-winit-wgpu/src/lib.rs @@ -8,11 +8,11 @@ mod app; #[cfg(target_os = "android")] #[unsafe(no_mangle)] fn android_main(app: AndroidApp) { - use app::App; use std::sync::OnceLock; + + use app::App; use tracing::error; - use winit::event_loop::EventLoop; - use winit::platform::android::EventLoopBuilderExtAndroid; + use winit::{event_loop::EventLoop, platform::android::EventLoopBuilderExtAndroid}; std::env::set_var("RUST_BACKTRACE", "full"); std::env::set_var("WGPU_BACKEND", "vulkan"); diff --git a/agdk-winit-wgpu/src/main.rs b/agdk-winit-wgpu/src/main.rs index 1d0ae3e..0b196b8 100644 --- a/agdk-winit-wgpu/src/main.rs +++ b/agdk-winit-wgpu/src/main.rs @@ -5,10 +5,8 @@ mod app; #[cfg(target_arch = "wasm32")] pub fn main() { use app::App; - use tracing_subscriber::layer::SubscriberExt; - use tracing_subscriber::util::SubscriberInitExt; - use winit::event_loop::EventLoop; - use winit::platform::web::EventLoopExtWebSys; + use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; + use winit::{event_loop::EventLoop, platform::web::EventLoopExtWebSys}; console_error_panic_hook::set_once(); @@ -52,9 +50,8 @@ use winit::error::EventLoopError; #[allow(dead_code)] #[cfg(not(any(target_os = "android", target_arch = "wasm32")))] fn main() -> Result<(), EventLoopError> { - use winit::event_loop::EventLoop; - use app::App; + use winit::event_loop::EventLoop; if std::option_env!("RUST_LOG").is_none() { std::env::set_var("RUST_LOG", app::DEFAULT_ENV_FILTER); diff --git a/na-egui/Cargo.toml b/na-egui/Cargo.toml index 128f4d0..1dc23be 100644 --- a/na-egui/Cargo.toml +++ b/na-egui/Cargo.toml @@ -4,8 +4,6 @@ version = "0.1.0" edition = "2021" resolver = "2" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] tracing = "0.1" tracing-subscriber = { version = "0.3", features = [ diff --git a/na-egui/src/lib.rs b/na-egui/src/lib.rs index 7157f3a..405ddea 100644 --- a/na-egui/src/lib.rs +++ b/na-egui/src/lib.rs @@ -1,20 +1,15 @@ use std::{num::NonZeroU32, sync::Arc}; -use tracing::{debug, error}; use egui::ViewportId; -use egui_wgpu::RendererOptions; -use egui_winit::winit; - -use winit::event_loop::{ActiveEventLoop, EventLoop}; - +use egui_wgpu::{winit::Painter, RendererOptions}; +use egui_winit::{winit, State}; +use tracing::{debug, error}; #[cfg(target_os = "android")] use winit::platform::android::activity::AndroidApp; - -use winit::event_loop::ControlFlow; - -use egui_wgpu::winit::Painter; -use egui_winit::State; -use winit::event::Event::*; +use winit::{ + event::Event::*, + event_loop::{ActiveEventLoop, ControlFlow, EventLoop}, +}; const INITIAL_WIDTH: u32 = 1920; const INITIAL_HEIGHT: u32 = 1080; @@ -209,6 +204,7 @@ const DEFAULT_ENV_FILTER: &str = "debug,wgpu_hal=info,winit=info,naga=info"; #[no_mangle] fn android_main(app: AndroidApp) { use std::sync::OnceLock; + use winit::platform::android::EventLoopBuilderExtAndroid; std::env::set_var("RUST_BACKTRACE", "full"); diff --git a/na-mainloop/Cargo.toml b/na-mainloop/Cargo.toml index 2af8005..0ad35f5 100644 --- a/na-mainloop/Cargo.toml +++ b/na-mainloop/Cargo.toml @@ -3,8 +3,6 @@ name = "na-mainloop" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] #log = "0.4" #android_logger = "0.11.0" diff --git a/na-mainloop/README.md b/na-mainloop/README.md index ee15263..18724af 100644 --- a/na-mainloop/README.md +++ b/na-mainloop/README.md @@ -7,7 +7,7 @@ Since this test doesn't require a custom `Activity` subclass it's optionally possible to build this example with `cargo apk`. # Gradle Build -``` +```bash export ANDROID_NDK_HOME="path/to/ndk" export ANDROID_HOME="path/to/sdk" @@ -26,7 +26,8 @@ adb shell am start -n com.github.realfit_mobile.namainloop/android.app.NativeAct ``` # Cargo APK Build -``` + +```bash export ANDROID_NDK_HOME="path/to/ndk" export ANDROID_SDK_HOME="path/to/sdk" diff --git a/na-mainloop/src/lib.rs b/na-mainloop/src/lib.rs index 153ef8a..a453430 100644 --- a/na-mainloop/src/lib.rs +++ b/na-mainloop/src/lib.rs @@ -1,9 +1,8 @@ use std::sync::OnceLock; use android_activity::{ - AndroidApp, InputStatus, MainEvent, OnCreateState, PollEvent, input::{InputEvent, KeyAction, KeyEvent, KeyMapChar, MotionAction}, - ndk, ndk_sys, + ndk, ndk_sys, AndroidApp, InputStatus, MainEvent, OnCreateState, PollEvent, }; use jni::{ objects::{JObject, JString}, @@ -228,6 +227,7 @@ fn android_main(app: AndroidApp) { } InputEvent::MotionEvent(motion_event) => { println!("action = {:?}", motion_event.action()); + #[expect(clippy::single_match)] match motion_event.action() { MotionAction::Up => { let pointer = motion_event.pointer_index(); @@ -368,7 +368,7 @@ fn character_map_and_combine_key( Some(unicode) }; *combining_accent = None; - combined_unicode.map(|unicode| KeyMapChar::Unicode(unicode)) + combined_unicode.map(KeyMapChar::Unicode) } else { Some(KeyMapChar::Unicode(unicode)) } diff --git a/na-openxr-info/Cargo.toml b/na-openxr-info/Cargo.toml index 7d9cbe4..f71b4af 100644 --- a/na-openxr-info/Cargo.toml +++ b/na-openxr-info/Cargo.toml @@ -3,8 +3,6 @@ name = "na-openxr-info" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] log = "0.4" openxr = { version = "0.17" } @@ -17,17 +15,17 @@ android_logger = "0.11.0" android-activity = { version = "0.4", features = ["native-activity"] } [features] -default = [ "linked" ] +default = ["linked"] -android = [ "openxr/linked" ] -desktop = [ "linked", "openxr/static"] -linked = [] +android = ["linked"] +desktop = ["linked", "openxr/static"] +linked = ["openxr/linked"] [lib] -name="main" -crate_type=["cdylib"] +name = "main" +crate_type = ["cdylib"] [[bin]] -path="src/lib.rs" -name="test-winit-wgpu" -required-features = [ "desktop" ] \ No newline at end of file +path = "src/lib.rs" +name = "test-winit-wgpu" +required-features = ["desktop"] diff --git a/na-openxr-info/src/lib.rs b/na-openxr-info/src/lib.rs index 8003c78..edafab1 100644 --- a/na-openxr-info/src/lib.rs +++ b/na-openxr-info/src/lib.rs @@ -1,8 +1,7 @@ -///! Based on https://github.com/Ralith/openxrs/blob/master/openxr/examples/hello.rs -use openxr as xr; - +//! Based on #[cfg(target_os = "android")] use android_activity::AndroidApp; +use openxr as xr; fn _main() { println!("OpenXR Info"); diff --git a/na-openxr-wgpu/Cargo.toml b/na-openxr-wgpu/Cargo.toml index b321ee5..e749fab 100644 --- a/na-openxr-wgpu/Cargo.toml +++ b/na-openxr-wgpu/Cargo.toml @@ -3,8 +3,6 @@ name = "na-openxr-wgpu" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] log = "0.4" ash = "0.37" diff --git a/na-openxr-wgpu/README.md b/na-openxr-wgpu/README.md index 1371e43..2ba3678 100644 --- a/na-openxr-wgpu/README.md +++ b/na-openxr-wgpu/README.md @@ -21,7 +21,7 @@ library to `app/src/main/jniLibs/` For example if building for arm64-v8a: `cp path/to/ovr_openxr_mobile_sdk_42.0/OpenXR/Libs/Android/arm64-v8a/Debug/libopenxr_loader.so app/src/main/jniLibs/arm64-v8a` -``` +```bash export ANDROID_NDK_HOME="path/to/ndk" export ANDROID_HOME="path/to/sdk" @@ -36,7 +36,8 @@ cargo ndk -t arm64-v8a -o app/src/main/jniLibs/ build # Oculus Quest: Vulkan Validation Layer To enable the Vulkan validation layer on the Oculus Quest run: -``` + +```bash adb shell setprop debug.oculus.loadandinjectpackagedvvl.co.realfit.naopenxrwgpu 1 ``` diff --git a/na-openxr-wgpu/src/lib.rs b/na-openxr-wgpu/src/lib.rs index be5f927..fa65cab 100644 --- a/na-openxr-wgpu/src/lib.rs +++ b/na-openxr-wgpu/src/lib.rs @@ -20,22 +20,17 @@ use std::{ time::Duration, }; -use anyhow::anyhow; -use anyhow::Result; -use bitflags::bitflags; - +#[cfg(target_os = "android")] +use android_activity::AndroidApp; +use anyhow::{anyhow, Result}; use ash::{ util::read_spv, vk::{self, Handle}, }; - +use bitflags::bitflags; +use openxr as xr; use wgpu_hal as hal; use wgpu_types as wgt; - -use openxr as xr; - -#[cfg(target_os = "android")] -use android_activity::AndroidApp; struct Framebuffer { color: wgpu::TextureView, } @@ -194,14 +189,14 @@ impl XrShell { let app_info = vk::ApplicationInfo::builder() .application_name(app_name.as_c_str()) .application_version(app_version) - .engine_name(CStr::from_bytes_with_nul(b"wgpu-hal\0").unwrap()) + .engine_name(c"wgpu-hal") .engine_version(2) .api_version(vk_target_version); log::debug!("Enumerating Vulkan instance layer properties"); let instance_layers = entry.enumerate_instance_layer_properties()?; - let nv_optimus_layer = CStr::from_bytes_with_nul(b"VK_LAYER_NV_optimus\0").unwrap(); + let nv_optimus_layer = c"VK_LAYER_NV_optimus"; let has_nv_optimus = instance_layers .iter() .any(|inst_layer| unsafe { CStr::from_ptr(inst_layer.layer_name.as_ptr()) } == nv_optimus_layer); @@ -210,7 +205,7 @@ impl XrShell { let layers = { let mut layers: Vec<&'static CStr> = Vec::new(); if hal_instance_flags.contains(hal::InstanceFlags::VALIDATION) { - layers.push(CStr::from_bytes_with_nul(b"VK_LAYER_KHRONOS_validation\0").unwrap()); + layers.push(c"VK_LAYER_KHRONOS_validation"); } // Only keep available layers. diff --git a/na-subclass-jni/Cargo.toml b/na-subclass-jni/Cargo.toml index 1b150ea..065d99b 100644 --- a/na-subclass-jni/Cargo.toml +++ b/na-subclass-jni/Cargo.toml @@ -3,8 +3,6 @@ name = "na-subclass-jni" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] log = "0.4" android_logger = "0.11.0" diff --git a/na-subclass-jni/README.md b/na-subclass-jni/README.md index 56e8e20..c413147 100644 --- a/na-subclass-jni/README.md +++ b/na-subclass-jni/README.md @@ -6,7 +6,8 @@ Note: unlike the `na-mainloop` example, this one can't be built via `cargo apk` since it needs to compile some Java code. # Gradle Build -``` + +```bash export ANDROID_NDK_HOME="path/to/ndk" export ANDROID_HOME="path/to/sdk" diff --git a/na-winit-glutin/build.rs b/na-winit-glutin/build.rs index 724cbff..f109423 100644 --- a/na-winit-glutin/build.rs +++ b/na-winit-glutin/build.rs @@ -1,6 +1,4 @@ -use std::env; -use std::fs::File; -use std::path::PathBuf; +use std::{env, fs::File, path::PathBuf}; use cfg_aliases::cfg_aliases; use gl_generator::{Api, Fallbacks, Profile, Registry, StructGenerator}; diff --git a/na-winit-glutin/src/lib.rs b/na-winit-glutin/src/lib.rs index 7e3ce3a..281746c 100644 --- a/na-winit-glutin/src/lib.rs +++ b/na-winit-glutin/src/lib.rs @@ -1,20 +1,24 @@ -use std::ffi::{CStr, CString}; -use std::num::NonZeroU32; - +use std::{ + ffi::{CStr, CString}, + num::NonZeroU32, +}; + +use glutin::{ + config::{Config, ConfigSurfaceTypes, ConfigTemplate, ConfigTemplateBuilder}, + context::{ContextApi, ContextAttributesBuilder, NotCurrentContext}, + display::{Display, DisplayApiPreference}, + prelude::*, + surface::{SurfaceAttributesBuilder, WindowSurface}, +}; use raw_window_handle::{HasDisplayHandle, HasWindowHandle, RawDisplayHandle, RawWindowHandle}; - -use winit::event::WindowEvent; -use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop}; #[cfg(target_os = "android")] use winit::platform::android::activity::AndroidApp; #[cfg(glx_backend)] use winit::platform::x11; - -use glutin::config::{Config, ConfigSurfaceTypes, ConfigTemplate, ConfigTemplateBuilder}; -use glutin::context::{ContextApi, ContextAttributesBuilder, NotCurrentContext}; -use glutin::display::{Display, DisplayApiPreference}; -use glutin::prelude::*; -use glutin::surface::{SurfaceAttributesBuilder, WindowSurface}; +use winit::{ + event::WindowEvent, + event_loop::{ActiveEventLoop, ControlFlow, EventLoop}, +}; #[rustfmt::skip] static VERTEX_DATA: [f32; 15] = [ @@ -107,8 +111,8 @@ impl Renderer { gl::STATIC_DRAW, ); - let pos_attrib = gl.GetAttribLocation(program, b"position\0".as_ptr() as *const _); - let color_attrib = gl.GetAttribLocation(program, b"color\0".as_ptr() as *const _); + let pos_attrib = gl.GetAttribLocation(program, c"position".as_ptr() as *const _); + let color_attrib = gl.GetAttribLocation(program, c"color".as_ptr() as *const _); gl.VertexAttribPointer( pos_attrib as gl::types::GLuint, 2, @@ -247,7 +251,7 @@ impl App { .build(Some(raw_window_handle)); unsafe { glutin_display - .create_context(&config, &context_attributes) + .create_context(config, &context_attributes) .unwrap_or_else(|_| { glutin_display .create_context(config, &fallback_context_attributes) diff --git a/na-winit-wgpu/Cargo.toml b/na-winit-wgpu/Cargo.toml index a234938..9f84bf4 100644 --- a/na-winit-wgpu/Cargo.toml +++ b/na-winit-wgpu/Cargo.toml @@ -3,8 +3,6 @@ name = "na-winit-wgpu" version = "0.1.0" edition = "2021" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] tracing = "0.1" tracing-subscriber = { version = "0.3", features = [ diff --git a/na-winit-wgpu/src/app.rs b/na-winit-wgpu/src/app.rs index e0f4305..3d66c1f 100644 --- a/na-winit-wgpu/src/app.rs +++ b/na-winit-wgpu/src/app.rs @@ -1,21 +1,19 @@ -use std::borrow::Cow; #[cfg(target_os = "android")] use std::ffi::c_void; #[cfg(target_os = "android")] use std::ptr::NonNull; -use std::sync::Arc; - -use tracing::{error, info, trace, warn}; +use std::{borrow::Cow, sync::Arc}; use raw_window_handle::{HandleError, HasDisplayHandle, HasWindowHandle}; -use wgpu::{Adapter, Device, Instance, PipelineLayout, Queue, RenderPipeline, ShaderModule}; -use wgpu::{PipelineCompilationOptions, TextureFormat}; - -use winit::error::EventLoopError; -use winit::event_loop::{EventLoop, EventLoopProxy}; +use tracing::{error, info, trace, warn}; +use wgpu::{ + Adapter, Device, Instance, PipelineCompilationOptions, PipelineLayout, Queue, RenderPipeline, + ShaderModule, TextureFormat, +}; use winit::{ + error::EventLoopError, event::{Event, WindowEvent}, - event_loop::{ActiveEventLoop, ControlFlow}, + event_loop::{ActiveEventLoop, ControlFlow, EventLoop, EventLoopProxy}, }; #[derive(Debug)] diff --git a/na-winit-wgpu/src/lib.rs b/na-winit-wgpu/src/lib.rs index 996056f..c2b0e66 100644 --- a/na-winit-wgpu/src/lib.rs +++ b/na-winit-wgpu/src/lib.rs @@ -8,11 +8,11 @@ mod app; #[cfg(target_os = "android")] #[unsafe(no_mangle)] fn android_main(app: AndroidApp) { - use app::App; use std::sync::OnceLock; + + use app::App; use tracing::error; - use winit::event_loop::EventLoop; - use winit::platform::android::EventLoopBuilderExtAndroid; + use winit::{event_loop::EventLoop, platform::android::EventLoopBuilderExtAndroid}; std::env::set_var("RUST_BACKTRACE", "full"); std::env::set_var("WGPU_BACKEND", "vulkan"); diff --git a/na-winit-wgpu/src/main.rs b/na-winit-wgpu/src/main.rs index 1d0ae3e..0b196b8 100644 --- a/na-winit-wgpu/src/main.rs +++ b/na-winit-wgpu/src/main.rs @@ -5,10 +5,8 @@ mod app; #[cfg(target_arch = "wasm32")] pub fn main() { use app::App; - use tracing_subscriber::layer::SubscriberExt; - use tracing_subscriber::util::SubscriberInitExt; - use winit::event_loop::EventLoop; - use winit::platform::web::EventLoopExtWebSys; + use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; + use winit::{event_loop::EventLoop, platform::web::EventLoopExtWebSys}; console_error_panic_hook::set_once(); @@ -52,9 +50,8 @@ use winit::error::EventLoopError; #[allow(dead_code)] #[cfg(not(any(target_os = "android", target_arch = "wasm32")))] fn main() -> Result<(), EventLoopError> { - use winit::event_loop::EventLoop; - use app::App; + use winit::event_loop::EventLoop; if std::option_env!("RUST_LOG").is_none() { std::env::set_var("RUST_LOG", app::DEFAULT_ENV_FILTER);