@bornengine/engine 0.4.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +231 -0
- package/native/android/Cargo.lock +1848 -0
- package/native/android/Cargo.toml +24 -0
- package/native/android/src/lib.rs +702 -0
- package/native/ios/Cargo.lock +1690 -0
- package/native/ios/Cargo.toml +32 -0
- package/native/ios/src/lib.rs +1267 -0
- package/native/linux/Cargo.lock +3279 -0
- package/native/linux/Cargo.toml +29 -0
- package/native/linux/src/lib.rs +1331 -0
- package/native/macos/Cargo.lock +3310 -0
- package/native/macos/Cargo.toml +46 -0
- package/native/macos/src/lib.rs +1302 -0
- package/native/shared/Cargo.lock +1899 -0
- package/native/shared/Cargo.toml +62 -0
- package/native/shared/assets/default_font.ttf +0 -0
- package/native/shared/build.rs +270 -0
- package/native/shared/shaders/common/clouds.wgsl +122 -0
- package/native/shared/shaders/common/fog.wgsl +16 -0
- package/native/shared/shaders/common/foliage_wind.wgsl +98 -0
- package/native/shared/shaders/common/imposter.wgsl +112 -0
- package/native/shared/shaders/common/pbr.wgsl +186 -0
- package/native/shared/shaders/common/shadows.wgsl +186 -0
- package/native/shared/shaders/common/sky.wgsl +8 -0
- package/native/shared/shaders/common/tonemap.wgsl +25 -0
- package/native/shared/shaders/impulse_field.wgsl +57 -0
- package/native/shared/shaders/material_abi.wgsl +383 -0
- package/native/shared/shaders/materials/test_minimal.wgsl +42 -0
- package/native/shared/src/anim_mixer.rs +61 -0
- package/native/shared/src/attach.rs +263 -0
- package/native/shared/src/audio/decode.rs +123 -0
- package/native/shared/src/audio/mod.rs +863 -0
- package/native/shared/src/audio/render.rs +892 -0
- package/native/shared/src/audio/spsc.rs +156 -0
- package/native/shared/src/audio/stream.rs +226 -0
- package/native/shared/src/custom_shaders.rs +104 -0
- package/native/shared/src/decals.rs +245 -0
- package/native/shared/src/drs.rs +211 -0
- package/native/shared/src/engine.rs +261 -0
- package/native/shared/src/ffi.rs +116 -0
- package/native/shared/src/ffi_core/assets.rs +388 -0
- package/native/shared/src/ffi_core/audio_ffi.rs +184 -0
- package/native/shared/src/ffi_core/draw.rs +334 -0
- package/native/shared/src/ffi_core/game_loop.rs +577 -0
- package/native/shared/src/ffi_core/input.rs +234 -0
- package/native/shared/src/ffi_core/mod.rs +127 -0
- package/native/shared/src/ffi_core/models.rs +1154 -0
- package/native/shared/src/ffi_core/ragdoll_ffi.rs +261 -0
- package/native/shared/src/ffi_core/scene.rs +626 -0
- package/native/shared/src/ffi_core/vfx.rs +212 -0
- package/native/shared/src/ffi_core/visual.rs +691 -0
- package/native/shared/src/frame_callbacks.rs +122 -0
- package/native/shared/src/geometry.rs +236 -0
- package/native/shared/src/handles.rs +182 -0
- package/native/shared/src/input.rs +448 -0
- package/native/shared/src/jolt_sys.rs +822 -0
- package/native/shared/src/lib.rs +55 -0
- package/native/shared/src/models.rs +1093 -0
- package/native/shared/src/models_gltf.rs +1280 -0
- package/native/shared/src/particles.rs +391 -0
- package/native/shared/src/physics_jolt.rs +1908 -0
- package/native/shared/src/picking.rs +298 -0
- package/native/shared/src/postfx.rs +345 -0
- package/native/shared/src/profiler.rs +492 -0
- package/native/shared/src/ragdoll.rs +474 -0
- package/native/shared/src/renderer/atmosphere_lut.rs +573 -0
- package/native/shared/src/renderer/brdf_lut.rs +154 -0
- package/native/shared/src/renderer/draw2d.rs +143 -0
- package/native/shared/src/renderer/formats.rs +822 -0
- package/native/shared/src/renderer/froxel.rs +421 -0
- package/native/shared/src/renderer/gi_bake.rs +653 -0
- package/native/shared/src/renderer/graph.rs +462 -0
- package/native/shared/src/renderer/hiz.rs +269 -0
- package/native/shared/src/renderer/hot_reload.rs +390 -0
- package/native/shared/src/renderer/impulse_field.rs +456 -0
- package/native/shared/src/renderer/lighting.rs +154 -0
- package/native/shared/src/renderer/material_instancing.rs +171 -0
- package/native/shared/src/renderer/material_pipeline.rs +700 -0
- package/native/shared/src/renderer/material_system.rs +1996 -0
- package/native/shared/src/renderer/material_system_tests.rs +601 -0
- package/native/shared/src/renderer/material_system_wasm.rs +41 -0
- package/native/shared/src/renderer/mod.rs +12556 -0
- package/native/shared/src/renderer/model_draw.rs +641 -0
- package/native/shared/src/renderer/occlusion.rs +429 -0
- package/native/shared/src/renderer/planar_pass.rs +593 -0
- package/native/shared/src/renderer/planar_reflection.rs +499 -0
- package/native/shared/src/renderer/post_pass.rs +249 -0
- package/native/shared/src/renderer/postfx_chain.rs +728 -0
- package/native/shared/src/renderer/pt_pass.rs +577 -0
- package/native/shared/src/renderer/scene_pass.rs +607 -0
- package/native/shared/src/renderer/shader_include.rs +205 -0
- package/native/shared/src/renderer/shader_library.rs +135 -0
- package/native/shared/src/renderer/shaders/ao.rs +570 -0
- package/native/shared/src/renderer/shaders/core.rs +1243 -0
- package/native/shared/src/renderer/shaders/env.rs +907 -0
- package/native/shared/src/renderer/shaders/gi.rs +810 -0
- package/native/shared/src/renderer/shaders/mod.rs +19 -0
- package/native/shared/src/renderer/shaders/post.rs +1558 -0
- package/native/shared/src/renderer/shaders/pt.rs +1859 -0
- package/native/shared/src/renderer/shaders/ssgi.rs +1586 -0
- package/native/shared/src/renderer/shadow_pass.rs +731 -0
- package/native/shared/src/renderer/ssgi_pass.rs +392 -0
- package/native/shared/src/renderer/ssr_pass.rs +188 -0
- package/native/shared/src/renderer/texture_store.rs +473 -0
- package/native/shared/src/renderer/transient.rs +591 -0
- package/native/shared/src/renderer/types.rs +941 -0
- package/native/shared/src/renderer/util.rs +152 -0
- package/native/shared/src/scene.rs +1362 -0
- package/native/shared/src/sdf_cache.rs +274 -0
- package/native/shared/src/shadows.rs +1036 -0
- package/native/shared/src/staging.rs +102 -0
- package/native/shared/src/string_header.rs +266 -0
- package/native/shared/src/text_renderer.rs +502 -0
- package/native/shared/src/textures.rs +197 -0
- package/native/tvos/Cargo.lock +1693 -0
- package/native/tvos/Cargo.toml +36 -0
- package/native/tvos/metal-patched/Cargo.toml +178 -0
- package/native/tvos/metal-patched/LICENSE-APACHE +201 -0
- package/native/tvos/metal-patched/LICENSE-MIT +25 -0
- package/native/tvos/metal-patched/src/acceleration_structure.rs +667 -0
- package/native/tvos/metal-patched/src/acceleration_structure_pass.rs +108 -0
- package/native/tvos/metal-patched/src/argument.rs +366 -0
- package/native/tvos/metal-patched/src/blitpass.rs +102 -0
- package/native/tvos/metal-patched/src/buffer.rs +71 -0
- package/native/tvos/metal-patched/src/capturedescriptor.rs +76 -0
- package/native/tvos/metal-patched/src/capturemanager.rs +113 -0
- package/native/tvos/metal-patched/src/commandbuffer.rs +192 -0
- package/native/tvos/metal-patched/src/commandqueue.rs +44 -0
- package/native/tvos/metal-patched/src/computepass.rs +107 -0
- package/native/tvos/metal-patched/src/constants.rs +152 -0
- package/native/tvos/metal-patched/src/counters.rs +119 -0
- package/native/tvos/metal-patched/src/depthstencil.rs +190 -0
- package/native/tvos/metal-patched/src/device.rs +2134 -0
- package/native/tvos/metal-patched/src/drawable.rs +39 -0
- package/native/tvos/metal-patched/src/encoder.rs +2041 -0
- package/native/tvos/metal-patched/src/heap.rs +281 -0
- package/native/tvos/metal-patched/src/indirect_encoder.rs +344 -0
- package/native/tvos/metal-patched/src/lib.rs +657 -0
- package/native/tvos/metal-patched/src/library.rs +902 -0
- package/native/tvos/metal-patched/src/mps.rs +575 -0
- package/native/tvos/metal-patched/src/pipeline/compute.rs +475 -0
- package/native/tvos/metal-patched/src/pipeline/mod.rs +71 -0
- package/native/tvos/metal-patched/src/pipeline/render.rs +762 -0
- package/native/tvos/metal-patched/src/renderpass.rs +443 -0
- package/native/tvos/metal-patched/src/resource.rs +182 -0
- package/native/tvos/metal-patched/src/sampler.rs +165 -0
- package/native/tvos/metal-patched/src/sync.rs +178 -0
- package/native/tvos/metal-patched/src/texture.rs +352 -0
- package/native/tvos/metal-patched/src/types.rs +90 -0
- package/native/tvos/metal-patched/src/vertexdescriptor.rs +250 -0
- package/native/tvos/src/audio_backend.rs +197 -0
- package/native/tvos/src/lib.rs +1891 -0
- package/native/visionos/Cargo.lock +1693 -0
- package/native/visionos/Cargo.toml +40 -0
- package/native/visionos/src/audio_backend.rs +197 -0
- package/native/visionos/src/lib.rs +1887 -0
- package/native/watchos/Cargo.lock +16 -0
- package/native/watchos/Cargo.toml +19 -0
- package/native/watchos/shaders/bloom_postfx.metal +99 -0
- package/native/watchos/src/BloomWatchApp.swift +1267 -0
- package/native/watchos/src/BloomWatchAudio.swift +179 -0
- package/native/watchos/src/audio.rs +55 -0
- package/native/watchos/src/draw_list.rs +229 -0
- package/native/watchos/src/ffi_stubs.rs +915 -0
- package/native/watchos/src/ffi_stubs_manual.rs +35 -0
- package/native/watchos/src/lib.rs +1124 -0
- package/native/watchos/src/models.rs +746 -0
- package/native/watchos/src/postfx.rs +95 -0
- package/native/watchos/src/scene.rs +534 -0
- package/native/watchos/src/textures.rs +184 -0
- package/native/web/Cargo.lock +1657 -0
- package/native/web/Cargo.toml +43 -0
- package/native/web/bloom_glue.js +695 -0
- package/native/web/build.sh +131 -0
- package/native/web/index.html +35 -0
- package/native/web/jolt_bridge.js +1519 -0
- package/native/web/src/input_ffi.rs +286 -0
- package/native/web/src/lib.rs +1796 -0
- package/native/web/src/material_ffi.rs +710 -0
- package/native/web/src/parity_ffi.rs +343 -0
- package/native/web/src/physics_ffi.rs +643 -0
- package/native/web/src/ragdoll_ffi.rs +250 -0
- package/native/web/src/render_settings.rs +98 -0
- package/native/windows/Cargo.lock +1815 -0
- package/native/windows/Cargo.toml +68 -0
- package/native/windows/src/lib.rs +1486 -0
- package/package.json +4279 -0
- package/src/audio/index.ts +315 -0
- package/src/core/colors.ts +63 -0
- package/src/core/index.ts +1206 -0
- package/src/core/keys.ts +63 -0
- package/src/core/types.ts +104 -0
- package/src/index.ts +171 -0
- package/src/math/index.ts +516 -0
- package/src/mobile/index.ts +294 -0
- package/src/models/index.ts +1258 -0
- package/src/physics/index.ts +1134 -0
- package/src/scene/index.ts +698 -0
- package/src/shapes/index.ts +120 -0
- package/src/text/index.ts +48 -0
- package/src/textures/index.ts +187 -0
- package/src/vfx/index.ts +191 -0
- package/src/world/index.ts +24 -0
- package/src/world/loader.ts +423 -0
- package/src/world/prefab.ts +217 -0
- package/src/world/render.ts +172 -0
- package/src/world/saver.ts +108 -0
- package/src/world/serialize.ts +301 -0
- package/src/world/terrain.ts +355 -0
- package/src/world/types.ts +160 -0
- package/src/world/validate.ts +319 -0
- package/src/world/version.ts +114 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Copyright 2016 GFX developers
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
|
4
|
+
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
|
5
|
+
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
|
6
|
+
// copied, modified, or distributed except according to those terms.
|
|
7
|
+
|
|
8
|
+
use super::NSUInteger;
|
|
9
|
+
use std::default::Default;
|
|
10
|
+
|
|
11
|
+
/// See <https://developer.apple.com/documentation/metal/mtlorigin>
|
|
12
|
+
#[repr(C)]
|
|
13
|
+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Default)]
|
|
14
|
+
pub struct MTLOrigin {
|
|
15
|
+
pub x: NSUInteger,
|
|
16
|
+
pub y: NSUInteger,
|
|
17
|
+
pub z: NSUInteger,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/// See <https://developer.apple.com/documentation/metal/mtlsize>
|
|
21
|
+
#[repr(C)]
|
|
22
|
+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Default)]
|
|
23
|
+
pub struct MTLSize {
|
|
24
|
+
pub width: NSUInteger,
|
|
25
|
+
pub height: NSUInteger,
|
|
26
|
+
pub depth: NSUInteger,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
impl MTLSize {
|
|
30
|
+
pub fn new(width: NSUInteger, height: NSUInteger, depth: NSUInteger) -> Self {
|
|
31
|
+
Self {
|
|
32
|
+
width,
|
|
33
|
+
height,
|
|
34
|
+
depth,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/// See <https://developer.apple.com/documentation/metal/mtlregion>
|
|
40
|
+
#[repr(C)]
|
|
41
|
+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Default)]
|
|
42
|
+
pub struct MTLRegion {
|
|
43
|
+
pub origin: MTLOrigin,
|
|
44
|
+
pub size: MTLSize,
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
impl MTLRegion {
|
|
48
|
+
#[inline]
|
|
49
|
+
pub fn new_1d(x: NSUInteger, width: NSUInteger) -> Self {
|
|
50
|
+
Self::new_2d(x, 0, width, 1)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
#[inline]
|
|
54
|
+
pub fn new_2d(x: NSUInteger, y: NSUInteger, width: NSUInteger, height: NSUInteger) -> Self {
|
|
55
|
+
Self::new_3d(x, y, 0, width, height, 1)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
#[inline]
|
|
59
|
+
pub fn new_3d(
|
|
60
|
+
x: NSUInteger,
|
|
61
|
+
y: NSUInteger,
|
|
62
|
+
z: NSUInteger,
|
|
63
|
+
width: NSUInteger,
|
|
64
|
+
height: NSUInteger,
|
|
65
|
+
depth: NSUInteger,
|
|
66
|
+
) -> Self {
|
|
67
|
+
Self {
|
|
68
|
+
origin: MTLOrigin { x, y, z },
|
|
69
|
+
size: MTLSize {
|
|
70
|
+
width,
|
|
71
|
+
height,
|
|
72
|
+
depth,
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/// See <https://developer.apple.com/documentation/metal/mtlsampleposition>
|
|
79
|
+
#[repr(C)]
|
|
80
|
+
#[derive(Copy, Clone, Debug, PartialEq, Default)]
|
|
81
|
+
pub struct MTLSamplePosition {
|
|
82
|
+
pub x: f32,
|
|
83
|
+
pub y: f32,
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
#[repr(C)]
|
|
87
|
+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Default)]
|
|
88
|
+
pub struct MTLResourceID {
|
|
89
|
+
pub _impl: u64,
|
|
90
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// Copyright 2016 GFX developers
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
|
4
|
+
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
|
5
|
+
// http://opensource.org/licenses/MIT>, at your option. This file may not be
|
|
6
|
+
// copied, modified, or distributed except according to those terms.
|
|
7
|
+
|
|
8
|
+
use super::NSUInteger;
|
|
9
|
+
|
|
10
|
+
/// See <https://developer.apple.com/documentation/metal/mtlvertexformat>
|
|
11
|
+
#[repr(u64)]
|
|
12
|
+
#[allow(non_camel_case_types)]
|
|
13
|
+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
|
14
|
+
pub enum MTLVertexFormat {
|
|
15
|
+
Invalid = 0,
|
|
16
|
+
UChar2 = 1,
|
|
17
|
+
UChar3 = 2,
|
|
18
|
+
UChar4 = 3,
|
|
19
|
+
Char2 = 4,
|
|
20
|
+
Char3 = 5,
|
|
21
|
+
Char4 = 6,
|
|
22
|
+
UChar2Normalized = 7,
|
|
23
|
+
UChar3Normalized = 8,
|
|
24
|
+
UChar4Normalized = 9,
|
|
25
|
+
Char2Normalized = 10,
|
|
26
|
+
Char3Normalized = 11,
|
|
27
|
+
Char4Normalized = 12,
|
|
28
|
+
UShort2 = 13,
|
|
29
|
+
UShort3 = 14,
|
|
30
|
+
UShort4 = 15,
|
|
31
|
+
Short2 = 16,
|
|
32
|
+
Short3 = 17,
|
|
33
|
+
Short4 = 18,
|
|
34
|
+
UShort2Normalized = 19,
|
|
35
|
+
UShort3Normalized = 20,
|
|
36
|
+
UShort4Normalized = 21,
|
|
37
|
+
Short2Normalized = 22,
|
|
38
|
+
Short3Normalized = 23,
|
|
39
|
+
Short4Normalized = 24,
|
|
40
|
+
Half2 = 25,
|
|
41
|
+
Half3 = 26,
|
|
42
|
+
Half4 = 27,
|
|
43
|
+
Float = 28,
|
|
44
|
+
Float2 = 29,
|
|
45
|
+
Float3 = 30,
|
|
46
|
+
Float4 = 31,
|
|
47
|
+
Int = 32,
|
|
48
|
+
Int2 = 33,
|
|
49
|
+
Int3 = 34,
|
|
50
|
+
Int4 = 35,
|
|
51
|
+
UInt = 36,
|
|
52
|
+
UInt2 = 37,
|
|
53
|
+
UInt3 = 38,
|
|
54
|
+
UInt4 = 39,
|
|
55
|
+
Int1010102Normalized = 40,
|
|
56
|
+
UInt1010102Normalized = 41,
|
|
57
|
+
UChar4Normalized_BGRA = 42,
|
|
58
|
+
UChar = 45,
|
|
59
|
+
Char = 46,
|
|
60
|
+
UCharNormalized = 47,
|
|
61
|
+
CharNormalized = 48,
|
|
62
|
+
UShort = 49,
|
|
63
|
+
Short = 50,
|
|
64
|
+
UShortNormalized = 51,
|
|
65
|
+
ShortNormalized = 52,
|
|
66
|
+
Half = 53,
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/// See <https://developer.apple.com/documentation/metal/mtlvertexstepfunction>
|
|
70
|
+
#[repr(u64)]
|
|
71
|
+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
|
72
|
+
pub enum MTLVertexStepFunction {
|
|
73
|
+
Constant = 0,
|
|
74
|
+
PerVertex = 1,
|
|
75
|
+
PerInstance = 2,
|
|
76
|
+
PerPatch = 3,
|
|
77
|
+
PerPatchControlPoint = 4,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/// See <https://developer.apple.com/documentation/metal/mtlvertexbufferlayoutdescriptor>
|
|
81
|
+
pub enum MTLVertexBufferLayoutDescriptor {}
|
|
82
|
+
|
|
83
|
+
foreign_obj_type! {
|
|
84
|
+
type CType = MTLVertexBufferLayoutDescriptor;
|
|
85
|
+
pub struct VertexBufferLayoutDescriptor;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
impl VertexBufferLayoutDescriptor {
|
|
89
|
+
pub fn new() -> Self {
|
|
90
|
+
unsafe {
|
|
91
|
+
let class = class!(MTLVertexBufferLayoutDescriptor);
|
|
92
|
+
msg_send![class, new]
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
impl VertexBufferLayoutDescriptorRef {
|
|
98
|
+
pub fn stride(&self) -> NSUInteger {
|
|
99
|
+
unsafe { msg_send![self, stride] }
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
pub fn set_stride(&self, stride: NSUInteger) {
|
|
103
|
+
unsafe { msg_send![self, setStride: stride] }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
pub fn step_function(&self) -> MTLVertexStepFunction {
|
|
107
|
+
unsafe { msg_send![self, stepFunction] }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
pub fn set_step_function(&self, func: MTLVertexStepFunction) {
|
|
111
|
+
unsafe { msg_send![self, setStepFunction: func] }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
pub fn step_rate(&self) -> NSUInteger {
|
|
115
|
+
unsafe { msg_send![self, stepRate] }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
pub fn set_step_rate(&self, step_rate: NSUInteger) {
|
|
119
|
+
unsafe { msg_send![self, setStepRate: step_rate] }
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/// See <https://developer.apple.com/documentation/metal/mtlvertexbufferlayoutdescriptorarray>
|
|
124
|
+
pub enum MTLVertexBufferLayoutDescriptorArray {}
|
|
125
|
+
|
|
126
|
+
foreign_obj_type! {
|
|
127
|
+
type CType = MTLVertexBufferLayoutDescriptorArray;
|
|
128
|
+
pub struct VertexBufferLayoutDescriptorArray;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
impl VertexBufferLayoutDescriptorArrayRef {
|
|
132
|
+
pub fn object_at(&self, index: NSUInteger) -> Option<&VertexBufferLayoutDescriptorRef> {
|
|
133
|
+
unsafe { msg_send![self, objectAtIndexedSubscript: index] }
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
pub fn set_object_at(
|
|
137
|
+
&self,
|
|
138
|
+
index: NSUInteger,
|
|
139
|
+
layout: Option<&VertexBufferLayoutDescriptorRef>,
|
|
140
|
+
) {
|
|
141
|
+
unsafe {
|
|
142
|
+
msg_send![self, setObject:layout
|
|
143
|
+
atIndexedSubscript:index]
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/// See <https://developer.apple.com/documentation/metal/mtlvertexattributedescriptor>
|
|
149
|
+
pub enum MTLVertexAttributeDescriptor {}
|
|
150
|
+
|
|
151
|
+
foreign_obj_type! {
|
|
152
|
+
type CType = MTLVertexAttributeDescriptor;
|
|
153
|
+
pub struct VertexAttributeDescriptor;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
impl VertexAttributeDescriptor {
|
|
157
|
+
pub fn new() -> Self {
|
|
158
|
+
unsafe {
|
|
159
|
+
let class = class!(MTLVertexAttributeDescriptor);
|
|
160
|
+
msg_send![class, new]
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
impl VertexAttributeDescriptorRef {
|
|
166
|
+
pub fn format(&self) -> MTLVertexFormat {
|
|
167
|
+
unsafe { msg_send![self, format] }
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
pub fn set_format(&self, format: MTLVertexFormat) {
|
|
171
|
+
unsafe { msg_send![self, setFormat: format] }
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
pub fn offset(&self) -> NSUInteger {
|
|
175
|
+
unsafe { msg_send![self, offset] }
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
pub fn set_offset(&self, offset: NSUInteger) {
|
|
179
|
+
unsafe { msg_send![self, setOffset: offset] }
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
pub fn buffer_index(&self) -> NSUInteger {
|
|
183
|
+
unsafe { msg_send![self, bufferIndex] }
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
pub fn set_buffer_index(&self, index: NSUInteger) {
|
|
187
|
+
unsafe { msg_send![self, setBufferIndex: index] }
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/// See <https://developer.apple.com/documentation/metal/mtlvertexattributedescriptorarray>
|
|
192
|
+
pub enum MTLVertexAttributeDescriptorArray {}
|
|
193
|
+
|
|
194
|
+
foreign_obj_type! {
|
|
195
|
+
type CType = MTLVertexAttributeDescriptorArray;
|
|
196
|
+
pub struct VertexAttributeDescriptorArray;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
impl VertexAttributeDescriptorArrayRef {
|
|
200
|
+
pub fn object_at(&self, index: NSUInteger) -> Option<&VertexAttributeDescriptorRef> {
|
|
201
|
+
unsafe { msg_send![self, objectAtIndexedSubscript: index] }
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
pub fn set_object_at(
|
|
205
|
+
&self,
|
|
206
|
+
index: NSUInteger,
|
|
207
|
+
attribute: Option<&VertexAttributeDescriptorRef>,
|
|
208
|
+
) {
|
|
209
|
+
unsafe {
|
|
210
|
+
msg_send![self, setObject:attribute
|
|
211
|
+
atIndexedSubscript:index]
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/// See <https://developer.apple.com/documentation/metal/mtlvertexdescriptor>
|
|
217
|
+
pub enum MTLVertexDescriptor {}
|
|
218
|
+
|
|
219
|
+
foreign_obj_type! {
|
|
220
|
+
type CType = MTLVertexDescriptor;
|
|
221
|
+
pub struct VertexDescriptor;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
impl VertexDescriptor {
|
|
225
|
+
pub fn new<'a>() -> &'a VertexDescriptorRef {
|
|
226
|
+
unsafe {
|
|
227
|
+
let class = class!(MTLVertexDescriptor);
|
|
228
|
+
msg_send![class, vertexDescriptor]
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
impl VertexDescriptorRef {
|
|
234
|
+
pub fn layouts(&self) -> &VertexBufferLayoutDescriptorArrayRef {
|
|
235
|
+
unsafe { msg_send![self, layouts] }
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
pub fn attributes(&self) -> &VertexAttributeDescriptorArrayRef {
|
|
239
|
+
unsafe { msg_send![self, attributes] }
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
#[cfg(feature = "private")]
|
|
243
|
+
pub unsafe fn serialize_descriptor(&self) -> *mut std::ffi::c_void {
|
|
244
|
+
msg_send![self, newSerializedDescriptor]
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
pub fn reset(&self) {
|
|
248
|
+
unsafe { msg_send![self, reset] }
|
|
249
|
+
}
|
|
250
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
//! CoreAudio (RemoteIO) backend for tvOS: AudioUnit FFI bindings, the
|
|
2
|
+
//! render callback, and the bloom_init_audio / bloom_close_audio entry
|
|
3
|
+
//! points. The render callback owns the engine's AudioRenderer (handed
|
|
4
|
+
//! off via AudioMixer::take_renderer) — see native/shared/src/audio for
|
|
5
|
+
//! the threading contract.
|
|
6
|
+
|
|
7
|
+
use crate::engine;
|
|
8
|
+
use std::ffi::c_void;
|
|
9
|
+
|
|
10
|
+
// CoreAudio (iOS) — RemoteIO Audio Unit
|
|
11
|
+
// ============================================================
|
|
12
|
+
|
|
13
|
+
type AudioUnit = *mut c_void;
|
|
14
|
+
type OSStatus = i32;
|
|
15
|
+
type AudioUnitPropertyID = u32;
|
|
16
|
+
type AudioUnitScope = u32;
|
|
17
|
+
type AudioUnitElement = u32;
|
|
18
|
+
|
|
19
|
+
#[repr(C)]
|
|
20
|
+
#[derive(Clone, Copy)]
|
|
21
|
+
struct AudioComponentDescription {
|
|
22
|
+
component_type: u32,
|
|
23
|
+
component_sub_type: u32,
|
|
24
|
+
component_manufacturer: u32,
|
|
25
|
+
component_flags: u32,
|
|
26
|
+
component_flags_mask: u32,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
#[repr(C)]
|
|
30
|
+
#[derive(Clone, Copy)]
|
|
31
|
+
struct AudioStreamBasicDescription {
|
|
32
|
+
sample_rate: f64,
|
|
33
|
+
format_id: u32,
|
|
34
|
+
format_flags: u32,
|
|
35
|
+
bytes_per_packet: u32,
|
|
36
|
+
frames_per_packet: u32,
|
|
37
|
+
bytes_per_frame: u32,
|
|
38
|
+
channels_per_frame: u32,
|
|
39
|
+
bits_per_channel: u32,
|
|
40
|
+
reserved: u32,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
#[repr(C)]
|
|
44
|
+
struct AudioBufferList {
|
|
45
|
+
number_buffers: u32,
|
|
46
|
+
buffers: [AudioBufferData; 1],
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#[repr(C)]
|
|
50
|
+
struct AudioBufferData {
|
|
51
|
+
number_channels: u32,
|
|
52
|
+
data_byte_size: u32,
|
|
53
|
+
data: *mut c_void,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
type AURenderCallback = unsafe extern "C" fn(
|
|
57
|
+
in_ref_con: *mut c_void,
|
|
58
|
+
io_action_flags: *mut u32,
|
|
59
|
+
in_time_stamp: *const c_void,
|
|
60
|
+
in_bus_number: u32,
|
|
61
|
+
in_number_frames: u32,
|
|
62
|
+
io_data: *mut AudioBufferList,
|
|
63
|
+
) -> OSStatus;
|
|
64
|
+
|
|
65
|
+
#[repr(C)]
|
|
66
|
+
struct AURenderCallbackStruct {
|
|
67
|
+
input_proc: AURenderCallback,
|
|
68
|
+
input_proc_ref_con: *mut c_void,
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
type AudioComponent = *mut c_void;
|
|
72
|
+
|
|
73
|
+
#[link(name = "AudioToolbox", kind = "framework")]
|
|
74
|
+
extern "C" {
|
|
75
|
+
fn AudioComponentFindNext(component: AudioComponent, desc: *const AudioComponentDescription) -> AudioComponent;
|
|
76
|
+
fn AudioComponentInstanceNew(component: AudioComponent, out: *mut AudioUnit) -> OSStatus;
|
|
77
|
+
fn AudioUnitSetProperty(
|
|
78
|
+
unit: AudioUnit,
|
|
79
|
+
property_id: AudioUnitPropertyID,
|
|
80
|
+
scope: AudioUnitScope,
|
|
81
|
+
element: AudioUnitElement,
|
|
82
|
+
data: *const c_void,
|
|
83
|
+
data_size: u32,
|
|
84
|
+
) -> OSStatus;
|
|
85
|
+
fn AudioUnitInitialize(unit: AudioUnit) -> OSStatus;
|
|
86
|
+
fn AudioOutputUnitStart(unit: AudioUnit) -> OSStatus;
|
|
87
|
+
fn AudioOutputUnitStop(unit: AudioUnit) -> OSStatus;
|
|
88
|
+
fn AudioComponentInstanceDispose(unit: AudioUnit) -> OSStatus;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const K_AUDIO_UNIT_TYPE_OUTPUT: u32 = u32::from_be_bytes(*b"auou");
|
|
92
|
+
const K_AUDIO_UNIT_SUB_TYPE_REMOTE_IO: u32 = u32::from_be_bytes(*b"rioc");
|
|
93
|
+
const K_AUDIO_UNIT_MANUFACTURER_APPLE: u32 = u32::from_be_bytes(*b"appl");
|
|
94
|
+
|
|
95
|
+
const K_AUDIO_UNIT_PROPERTY_STREAM_FORMAT: AudioUnitPropertyID = 8;
|
|
96
|
+
const K_AUDIO_UNIT_PROPERTY_SET_RENDER_CALLBACK: AudioUnitPropertyID = 23;
|
|
97
|
+
const K_AUDIO_UNIT_SCOPE_INPUT: AudioUnitScope = 1;
|
|
98
|
+
|
|
99
|
+
const K_AUDIO_FORMAT_LINEAR_PCM: u32 = u32::from_be_bytes(*b"lpcm");
|
|
100
|
+
const K_AUDIO_FORMAT_FLAG_IS_FLOAT: u32 = 1;
|
|
101
|
+
const K_AUDIO_FORMAT_FLAG_IS_PACKED: u32 = 8;
|
|
102
|
+
|
|
103
|
+
struct AudioUnitInstance { unit: AudioUnit }
|
|
104
|
+
unsafe impl Send for AudioUnitInstance {}
|
|
105
|
+
unsafe impl Sync for AudioUnitInstance {}
|
|
106
|
+
|
|
107
|
+
static mut AUDIO_UNIT: Option<AudioUnitInstance> = None;
|
|
108
|
+
// Render half of the audio system — owned by the CoreAudio render thread
|
|
109
|
+
// after bloom_init_audio hands it off via AudioMixer::take_renderer.
|
|
110
|
+
// See native/shared/src/audio/mod.rs for the threading contract.
|
|
111
|
+
static mut AUDIO_RENDERER: Option<bloom_shared::audio::AudioRenderer> = None;
|
|
112
|
+
|
|
113
|
+
unsafe extern "C" fn audio_render_callback(
|
|
114
|
+
_in_ref_con: *mut c_void,
|
|
115
|
+
_io_action_flags: *mut u32,
|
|
116
|
+
_in_time_stamp: *const c_void,
|
|
117
|
+
_in_bus_number: u32,
|
|
118
|
+
in_number_frames: u32,
|
|
119
|
+
io_data: *mut AudioBufferList,
|
|
120
|
+
) -> OSStatus {
|
|
121
|
+
let buffer_list = &mut *io_data;
|
|
122
|
+
let buffer = &mut buffer_list.buffers[0];
|
|
123
|
+
let num_samples = in_number_frames as usize * 2;
|
|
124
|
+
let output = std::slice::from_raw_parts_mut(buffer.data as *mut f32, num_samples);
|
|
125
|
+
match AUDIO_RENDERER.as_mut() {
|
|
126
|
+
Some(r) => r.mix(output),
|
|
127
|
+
None => output.iter_mut().for_each(|s| *s = 0.0),
|
|
128
|
+
}
|
|
129
|
+
0
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
#[no_mangle]
|
|
133
|
+
pub extern "C" fn bloom_init_audio() {
|
|
134
|
+
unsafe {
|
|
135
|
+
// Hand the render half to the audio thread before the callback
|
|
136
|
+
// can fire. Idempotent: a second init keeps the existing renderer.
|
|
137
|
+
if AUDIO_RENDERER.is_none() {
|
|
138
|
+
AUDIO_RENDERER = engine().audio.take_renderer();
|
|
139
|
+
}
|
|
140
|
+
let desc = AudioComponentDescription {
|
|
141
|
+
component_type: K_AUDIO_UNIT_TYPE_OUTPUT,
|
|
142
|
+
component_sub_type: K_AUDIO_UNIT_SUB_TYPE_REMOTE_IO,
|
|
143
|
+
component_manufacturer: K_AUDIO_UNIT_MANUFACTURER_APPLE,
|
|
144
|
+
component_flags: 0,
|
|
145
|
+
component_flags_mask: 0,
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
let component = AudioComponentFindNext(std::ptr::null_mut(), &desc);
|
|
149
|
+
if component.is_null() { return; }
|
|
150
|
+
|
|
151
|
+
let mut unit: AudioUnit = std::ptr::null_mut();
|
|
152
|
+
if AudioComponentInstanceNew(component, &mut unit) != 0 { return; }
|
|
153
|
+
|
|
154
|
+
let stream_desc = AudioStreamBasicDescription {
|
|
155
|
+
sample_rate: 44100.0,
|
|
156
|
+
format_id: K_AUDIO_FORMAT_LINEAR_PCM,
|
|
157
|
+
format_flags: K_AUDIO_FORMAT_FLAG_IS_FLOAT | K_AUDIO_FORMAT_FLAG_IS_PACKED,
|
|
158
|
+
bytes_per_packet: 8,
|
|
159
|
+
frames_per_packet: 1,
|
|
160
|
+
bytes_per_frame: 8,
|
|
161
|
+
channels_per_frame: 2,
|
|
162
|
+
bits_per_channel: 32,
|
|
163
|
+
reserved: 0,
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
AudioUnitSetProperty(
|
|
167
|
+
unit, K_AUDIO_UNIT_PROPERTY_STREAM_FORMAT, K_AUDIO_UNIT_SCOPE_INPUT, 0,
|
|
168
|
+
&stream_desc as *const _ as *const c_void,
|
|
169
|
+
std::mem::size_of::<AudioStreamBasicDescription>() as u32,
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
let callback_struct = AURenderCallbackStruct {
|
|
173
|
+
input_proc: audio_render_callback,
|
|
174
|
+
input_proc_ref_con: std::ptr::null_mut(),
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
AudioUnitSetProperty(
|
|
178
|
+
unit, K_AUDIO_UNIT_PROPERTY_SET_RENDER_CALLBACK, K_AUDIO_UNIT_SCOPE_INPUT, 0,
|
|
179
|
+
&callback_struct as *const _ as *const c_void,
|
|
180
|
+
std::mem::size_of::<AURenderCallbackStruct>() as u32,
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
AudioUnitInitialize(unit);
|
|
184
|
+
AudioOutputUnitStart(unit);
|
|
185
|
+
AUDIO_UNIT = Some(AudioUnitInstance { unit });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
#[no_mangle]
|
|
190
|
+
pub extern "C" fn bloom_close_audio() {
|
|
191
|
+
unsafe {
|
|
192
|
+
if let Some(au) = AUDIO_UNIT.take() {
|
|
193
|
+
AudioOutputUnitStop(au.unit);
|
|
194
|
+
AudioComponentInstanceDispose(au.unit);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|