@bloomengine/engine 0.4.1 → 0.4.3

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.
Files changed (38) hide show
  1. package/native/tvos/Cargo.lock +1 -0
  2. package/native/tvos/Cargo.toml +2 -0
  3. package/native/tvos/metal-patched/Cargo.toml +178 -0
  4. package/native/tvos/metal-patched/LICENSE-APACHE +201 -0
  5. package/native/tvos/metal-patched/LICENSE-MIT +25 -0
  6. package/native/tvos/metal-patched/src/acceleration_structure.rs +667 -0
  7. package/native/tvos/metal-patched/src/acceleration_structure_pass.rs +108 -0
  8. package/native/tvos/metal-patched/src/argument.rs +366 -0
  9. package/native/tvos/metal-patched/src/blitpass.rs +102 -0
  10. package/native/tvos/metal-patched/src/buffer.rs +71 -0
  11. package/native/tvos/metal-patched/src/capturedescriptor.rs +76 -0
  12. package/native/tvos/metal-patched/src/capturemanager.rs +113 -0
  13. package/native/tvos/metal-patched/src/commandbuffer.rs +192 -0
  14. package/native/tvos/metal-patched/src/commandqueue.rs +44 -0
  15. package/native/tvos/metal-patched/src/computepass.rs +107 -0
  16. package/native/tvos/metal-patched/src/constants.rs +152 -0
  17. package/native/tvos/metal-patched/src/counters.rs +119 -0
  18. package/native/tvos/metal-patched/src/depthstencil.rs +190 -0
  19. package/native/tvos/metal-patched/src/device.rs +2134 -0
  20. package/native/tvos/metal-patched/src/drawable.rs +39 -0
  21. package/native/tvos/metal-patched/src/encoder.rs +2041 -0
  22. package/native/tvos/metal-patched/src/heap.rs +281 -0
  23. package/native/tvos/metal-patched/src/indirect_encoder.rs +344 -0
  24. package/native/tvos/metal-patched/src/lib.rs +657 -0
  25. package/native/tvos/metal-patched/src/library.rs +902 -0
  26. package/native/tvos/metal-patched/src/mps.rs +575 -0
  27. package/native/tvos/metal-patched/src/pipeline/compute.rs +475 -0
  28. package/native/tvos/metal-patched/src/pipeline/mod.rs +71 -0
  29. package/native/tvos/metal-patched/src/pipeline/render.rs +762 -0
  30. package/native/tvos/metal-patched/src/renderpass.rs +443 -0
  31. package/native/tvos/metal-patched/src/resource.rs +182 -0
  32. package/native/tvos/metal-patched/src/sampler.rs +165 -0
  33. package/native/tvos/metal-patched/src/sync.rs +178 -0
  34. package/native/tvos/metal-patched/src/texture.rs +352 -0
  35. package/native/tvos/metal-patched/src/types.rs +90 -0
  36. package/native/tvos/metal-patched/src/vertexdescriptor.rs +250 -0
  37. package/native/tvos/src/lib.rs +151 -0
  38. package/package.json +5 -1
@@ -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
+ }
@@ -3177,3 +3177,154 @@ fn bloom_jolt_ffi_physics() -> &'static mut bloom_shared::physics_jolt::JoltPhys
3177
3177
 
3178
3178
  #[cfg(feature = "jolt")]
3179
3179
  bloom_shared::define_physics_ffi!();
3180
+
3181
+ // ============================================================
3182
+ // Screenshot + HDR env + Post-FX / resolution FFI
3183
+ // ------------------------------------------------------------
3184
+ // Ported from native/macos/src/lib.rs. These delegate to the shared
3185
+ // bloom_shared renderer (identical type used here), so they are real
3186
+ // implementations, not stubs. They were present on macOS/linux/windows
3187
+ // but missing on tvOS, which caused `ld64.lld: undefined symbol: _bloom_*`
3188
+ // link errors for any app using the post-processing API on tvOS.
3189
+ // ============================================================
3190
+
3191
+ /// Request a PNG screenshot of the next rendered frame. The capture happens
3192
+ /// during the next end_drawing(); used by bloom-diff / CI image regression.
3193
+ #[no_mangle]
3194
+ pub extern "C" fn bloom_take_screenshot(path_ptr: *const u8) {
3195
+ let path = str_from_header(path_ptr).to_string();
3196
+ let eng = engine();
3197
+ eng.renderer.screenshot_requested = true;
3198
+ eng.renderer.pending_screenshot_path = Some(path);
3199
+ }
3200
+
3201
+ /// Load an HDR equirectangular environment map and upload it to the GPU.
3202
+ /// The file must be Radiance HDR (.hdr).
3203
+ #[no_mangle]
3204
+ pub extern "C" fn bloom_set_env_clear_from_hdr(path_ptr: *const u8) {
3205
+ use image::ImageDecoder;
3206
+ let path = str_from_header(path_ptr).to_string();
3207
+ let file = match std::fs::File::open(&path) {
3208
+ Ok(f) => f,
3209
+ Err(_) => return,
3210
+ };
3211
+ let decoder = match image::codecs::hdr::HdrDecoder::new(std::io::BufReader::new(file)) {
3212
+ Ok(d) => d,
3213
+ Err(_) => return,
3214
+ };
3215
+ let (w, h) = decoder.dimensions();
3216
+ let byte_len = (w as usize) * (h as usize) * 3 * 4;
3217
+ let mut buf = vec![0u8; byte_len];
3218
+ if decoder.read_image(&mut buf).is_err() {
3219
+ return;
3220
+ }
3221
+ let rgb_f32: Vec<f32> = buf
3222
+ .chunks_exact(4)
3223
+ .map(|c| f32::from_le_bytes([c[0], c[1], c[2], c[3]]))
3224
+ .collect();
3225
+ engine().renderer.load_env_from_hdr(w, h, &rgb_f32);
3226
+ }
3227
+
3228
+ // --- Post-FX knobs (heuristic visual layer; default-off) ---
3229
+
3230
+ #[no_mangle]
3231
+ pub extern "C" fn bloom_set_fog(r: f64, g: f64, b: f64, density: f64, height_ref: f64, height_falloff: f64) {
3232
+ let r_ = engine();
3233
+ r_.renderer.set_fog_color(r as f32, g as f32, b as f32);
3234
+ r_.renderer.set_fog_density(density as f32);
3235
+ r_.renderer.set_fog_height_falloff(height_ref as f32, height_falloff as f32);
3236
+ }
3237
+
3238
+ #[no_mangle]
3239
+ pub extern "C" fn bloom_set_chromatic_aberration(strength: f64) {
3240
+ engine().renderer.set_chromatic_aberration(strength as f32);
3241
+ }
3242
+
3243
+ #[no_mangle]
3244
+ pub extern "C" fn bloom_set_vignette(strength: f64, softness: f64) {
3245
+ engine().renderer.set_vignette(strength as f32, softness as f32);
3246
+ }
3247
+
3248
+ #[no_mangle]
3249
+ pub extern "C" fn bloom_set_film_grain(strength: f64) {
3250
+ engine().renderer.set_film_grain(strength as f32);
3251
+ }
3252
+
3253
+ #[no_mangle]
3254
+ pub extern "C" fn bloom_set_sun_shafts(strength: f64, decay: f64, r: f64, g: f64, b: f64) {
3255
+ let eng = engine();
3256
+ eng.renderer.set_sun_shaft_strength(strength as f32);
3257
+ eng.renderer.set_sun_shaft_decay(decay as f32);
3258
+ eng.renderer.set_sun_shaft_color(r as f32, g as f32, b as f32);
3259
+ }
3260
+
3261
+ #[no_mangle]
3262
+ pub extern "C" fn bloom_set_auto_exposure(on: f64) {
3263
+ engine().renderer.set_auto_exposure(on != 0.0);
3264
+ }
3265
+
3266
+ #[no_mangle]
3267
+ pub extern "C" fn bloom_set_taa_enabled(on: f64) {
3268
+ engine().renderer.set_taa_enabled(on != 0.0);
3269
+ }
3270
+
3271
+ #[no_mangle]
3272
+ pub extern "C" fn bloom_set_render_scale(scale: f64) {
3273
+ engine().renderer.set_render_scale(scale as f32);
3274
+ }
3275
+
3276
+ #[no_mangle]
3277
+ pub extern "C" fn bloom_get_render_scale() -> f64 {
3278
+ engine().renderer.render_scale() as f64
3279
+ }
3280
+
3281
+ #[no_mangle]
3282
+ pub extern "C" fn bloom_set_upscale_mode(mode: f64) {
3283
+ engine().renderer.set_upscale_mode(mode as u32);
3284
+ }
3285
+
3286
+ #[no_mangle]
3287
+ pub extern "C" fn bloom_set_cas_strength(strength: f64) {
3288
+ engine().renderer.set_cas_strength(strength as f32);
3289
+ }
3290
+
3291
+ #[no_mangle]
3292
+ pub extern "C" fn bloom_get_physical_width() -> f64 {
3293
+ engine().renderer.physical_width() as f64
3294
+ }
3295
+
3296
+ #[no_mangle]
3297
+ pub extern "C" fn bloom_get_physical_height() -> f64 {
3298
+ engine().renderer.physical_height() as f64
3299
+ }
3300
+
3301
+ #[no_mangle]
3302
+ pub extern "C" fn bloom_set_auto_resolution(target_hz: f64, enabled: f64) {
3303
+ let eng = engine();
3304
+ if enabled != 0.0 {
3305
+ let current = eng.renderer.render_scale();
3306
+ eng.drs.enable(target_hz as f32, current);
3307
+ } else {
3308
+ eng.drs.disable();
3309
+ }
3310
+ }
3311
+
3312
+ #[no_mangle]
3313
+ pub extern "C" fn bloom_set_manual_exposure(value: f64) {
3314
+ engine().renderer.set_manual_exposure(value as f32);
3315
+ }
3316
+
3317
+ #[no_mangle]
3318
+ pub extern "C" fn bloom_set_env_intensity(intensity: f64) {
3319
+ engine().renderer.set_env_intensity(intensity as f32);
3320
+ }
3321
+
3322
+ #[no_mangle]
3323
+ pub extern "C" fn bloom_set_ssgi_enabled(enabled: f64) {
3324
+ engine().renderer.set_ssgi_enabled(enabled != 0.0);
3325
+ }
3326
+
3327
+ #[no_mangle]
3328
+ pub extern "C" fn bloom_set_ssgi_intensity(intensity: f64) {
3329
+ engine().renderer.set_ssgi_intensity(intensity as f32);
3330
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bloomengine/engine",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "Bloom Engine: native TypeScript game engine compiled by Perry",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -36,6 +36,10 @@
36
36
  "native/tvos/Cargo.toml",
37
37
  "native/tvos/Cargo.lock",
38
38
  "native/tvos/src/**",
39
+ "native/tvos/metal-patched/Cargo.toml",
40
+ "native/tvos/metal-patched/src/**",
41
+ "native/tvos/metal-patched/LICENSE-APACHE",
42
+ "native/tvos/metal-patched/LICENSE-MIT",
39
43
  "native/watchos/Cargo.toml",
40
44
  "native/watchos/Cargo.lock",
41
45
  "native/watchos/src/**",