Use embedded glslang for runtime glsl-to-spirv and add Android example (#740)

Use embedded glslang for runtime glsl-to-spirv and add Android example
This commit is contained in:
Nicholas Rishel 2020-11-02 16:30:30 -08:00 committed by GitHub
parent f81ecddafc
commit 53c4c45eca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 7 deletions

View file

@ -29,6 +29,22 @@ default = [
"mp3", "mp3",
"x11", "x11",
] ]
supported_android_features = [
# cpal is not supported yet
# "bevy_audio",
"bevy_dynamic_plugin",
"bevy_gilrs",
"bevy_gltf",
"bevy_wgpu",
"bevy_winit",
"render",
"png",
"hdr",
# "mp3",
"x11",
]
profiler = ["bevy_ecs/profiler", "bevy_diagnostic/profiler"] profiler = ["bevy_ecs/profiler", "bevy_diagnostic/profiler"]
wgpu_trace = ["bevy_wgpu/trace"] wgpu_trace = ["bevy_wgpu/trace"]
@ -90,6 +106,11 @@ log = "0.4"
ron = "0.6" ron = "0.6"
anyhow = "1.0" anyhow = "1.0"
# bevy (Android)
[target.'cfg(target_os = "android")'.dependencies]
ndk-glue = { version = "0.2", features = ["logger"] }
android_logger = "0.9"
[target.'cfg(target_arch = "wasm32")'.dev-dependencies] [target.'cfg(target_arch = "wasm32")'.dev-dependencies]
console_error_panic_hook = "0.1.6" console_error_panic_hook = "0.1.6"
console_log = { version = "0.2", features = ["color"] } console_log = { version = "0.2", features = ["color"] }
@ -314,3 +335,16 @@ name = "assets_wasm"
path = "examples/wasm/assets_wasm.rs" path = "examples/wasm/assets_wasm.rs"
required-features = ["bevy_winit"] required-features = ["bevy_winit"]
[[example]]
name = "bevy_android"
path = "examples/android/bevy_android.rs"
crate-type = ["cdylib"]
[package.metadata.android]
build_targets = [ "aarch64-linux-android", "armv7-linux-androideabi" ]
target_sdk_version = 28
min_sdk_version = 28
[[package.metadata.android.feature]]
name = "android.hardware.vulkan.level"
version = "1"

View file

@ -48,7 +48,7 @@ parking_lot = "0.11.0"
spirv-reflect = "0.2.3" spirv-reflect = "0.2.3"
[target.'cfg(all(not(target_os = "ios"), not(target_arch = "wasm32")))'.dependencies] [target.'cfg(all(not(target_os = "ios"), not(target_arch = "wasm32")))'.dependencies]
bevy-glsl-to-spirv = "0.1.7" bevy-glsl-to-spirv = "0.2.0"
[target.'cfg(target_os = "ios")'.dependencies] [target.'cfg(target_os = "ios")'.dependencies]
shaderc = "0.6.3" shaderc = "0.6.3"

View file

@ -28,12 +28,7 @@ fn glsl_to_spirv(
stage: ShaderStage, stage: ShaderStage,
shader_defs: Option<&[String]>, shader_defs: Option<&[String]>,
) -> Vec<u32> { ) -> Vec<u32> {
use std::io::Read; bevy_glsl_to_spirv::compile(glsl_source, stage.into(), shader_defs).unwrap()
let mut output = bevy_glsl_to_spirv::compile(glsl_source, stage.into(), shader_defs).unwrap();
let mut spv_bytes = Vec::new();
output.read_to_end(&mut spv_bytes).unwrap();
bytes_to_words(&spv_bytes)
} }
#[cfg(target_os = "ios")] #[cfg(target_os = "ios")]

View file

@ -0,0 +1,10 @@
// Edit to run any single file example from Bevy.
include!("../3d/3d_scene.rs");
#[cfg_attr(
target_os = "android",
ndk_glue::main(logger(level = "trace", tag = "bevy_android"), backtrace = "full")
)]
pub fn android_main() {
main();
}