Skip to content

Commit

Permalink
Use embedded glslang for runtime glsl-to-spirv and add Android example (
Browse files Browse the repository at this point in the history
bevyengine#740)

Use embedded glslang for runtime glsl-to-spirv and add Android example
  • Loading branch information
PrototypeNM1 authored Nov 3, 2020
1 parent f81ecdd commit 53c4c45
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
34 changes: 34 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ default = [
"mp3",
"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"]
wgpu_trace = ["bevy_wgpu/trace"]

Expand Down Expand Up @@ -90,6 +106,11 @@ log = "0.4"
ron = "0.6"
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]
console_error_panic_hook = "0.1.6"
console_log = { version = "0.2", features = ["color"] }
Expand Down Expand Up @@ -314,3 +335,16 @@ name = "assets_wasm"
path = "examples/wasm/assets_wasm.rs"
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"
2 changes: 1 addition & 1 deletion crates/bevy_render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ parking_lot = "0.11.0"
spirv-reflect = "0.2.3"

[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]
shaderc = "0.6.3"
Expand Down
7 changes: 1 addition & 6 deletions crates/bevy_render/src/shader/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ fn glsl_to_spirv(
stage: ShaderStage,
shader_defs: Option<&[String]>,
) -> Vec<u32> {
use std::io::Read;

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)
bevy_glsl_to_spirv::compile(glsl_source, stage.into(), shader_defs).unwrap()
}

#[cfg(target_os = "ios")]
Expand Down
10 changes: 10 additions & 0 deletions examples/android/bevy_android.rs
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit 53c4c45

Please sign in to comment.