Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions native/macos/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion native/macos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,13 @@ pub extern "C" fn bloom_init_window(
app.setActivationPolicy(NSApplicationActivationPolicy::Prohibited);
} else {
app.setActivationPolicy(NSApplicationActivationPolicy::Regular);
// Bloom is commonly launched as a raw Perry executable rather than an
// .app bundle. AppKit does not finish its normal launch sequence for
// that shape automatically, and a key/visible NSWindow can then keep a
// CAMetalLayer whose nextDrawable reports `Occluded` forever. Complete
// launch before creating the standalone surface so Core Animation can
// register and service the layer normally.
app.finishLaunching();
}

// Far-off-screen origin keeps the window out of every display
Expand Down Expand Up @@ -356,8 +363,21 @@ pub extern "C" fn bloom_init_window(
let _: () = msg_send![&window, orderOut: std::ptr::null::<objc2::runtime::AnyObject>()];
}
} else {
window.center();
// Keep the explicit (100, 100) origin above. `center()` selects the
// screen macOS currently considers active, which can be a sleeping or
// negatively-positioned secondary display for command-line launches;
// Metal then reports the otherwise visible surface as occluded.
window.makeKeyAndOrderFront(None);
// `makeKeyAndOrderFront` is sufficient for bundled applications. For
// command-line executables it can leave the window ordered but without
// a committed backing layer until the next full AppKit run-loop turn;
// Perry drives that loop manually. Ordering and displaying explicitly
// makes the first Metal drawable available even after a long,
// synchronous Three.js scene import.
unsafe {
let _: () = msg_send![&window, orderFrontRegardless];
let _: () = msg_send![&window, displayIfNeeded];
}
#[allow(deprecated)]
app.activateIgnoringOtherApps(true);
}
Expand Down
17 changes: 17 additions & 0 deletions native/shared/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions native/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ cmake = "0.1"
bloom-geometry-format = { path = "../../crates/bloom-geometry-format", optional = true }
bloom-scene-format = { path = "../../crates/bloom-scene-format", optional = true }
wgpu = "29"
naga = { version = "29", features = ["glsl-in", "wgsl-out"] }
log = "0.4"
raw-window-handle = "0.6"
fontdue = "0.9"
Expand Down
5 changes: 3 additions & 2 deletions native/shared/shaders/material_indirection.wgsl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Bloom global material indirection ABI — version 1.
// Bloom global material indirection ABI — version 2.
//
// This header is consumed by GPU-driven opaque passes. The legacy/custom
// material ABI remains version 3 and unchanged: Tier C therefore stays a
// pixel-identical compatibility path.

const BLOOM_RESOURCE_SLOT_MASK: u32 = 0x000fffffu;
const BLOOM_RESOURCE_GENERATION_SHIFT: u32 = 20u;
const BLOOM_GLOBAL_MATERIAL_RECORD_VERSION: u32 = 1u;
const BLOOM_GLOBAL_MATERIAL_RECORD_VERSION: u32 = 2u;
const BLOOM_GLOBAL_MATERIAL_VERSION_SHIFT: u32 = 24u;
const BLOOM_GLOBAL_MATERIAL_LOBE_MASK: u32 = 0x00ffffffu;

Expand All @@ -25,6 +25,7 @@ struct GlobalMaterialRecord {
texture_ids_2: vec4<u32>,
sampler_ids_0: vec4<u32>,
sampler_ids_1: vec4<u32>,
uv_transforms: array<vec4<f32>, 10>,
};

struct GlobalMaterialTable {
Expand Down
118 changes: 118 additions & 0 deletions native/shared/src/ffi_core/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,40 @@ macro_rules! __bloom_ffi_assets {
})
}

// Upload RGBA8 supplied through the all-f64 mesh scratch. Each u32 is
// one little-endian texel: r | g<<8 | b<<16 | a<<24. This keeps raw
// texture uploads callable from Perry without an unsafe array pointer.
#[no_mangle]
pub extern "C" fn bloom_load_texture_rgba8_scratch(
width: f64,
height: f64,
kind: f64,
) -> f64 {
$crate::ffi::guard("bloom_load_texture_rgba8_scratch", move || {
let width = width as u32;
let height = height as u32;
let Some(texel_count) = width.checked_mul(height).map(|count| count as usize)
else {
return 0.0;
};
let eng = engine();
if width == 0 || height == 0 || eng.models.scratch_u32s().len() < texel_count {
return 0.0;
}
let mut bytes = Vec::with_capacity(texel_count * 4);
for &texel in &eng.models.scratch_u32s()[..texel_count] {
bytes.extend_from_slice(&texel.to_le_bytes());
}
eng.models.mesh_scratch_reset();
let $crate::engine::EngineState {
ref mut textures,
ref mut renderer,
..
} = *eng;
textures.load_texture_rgba8(renderer, width, height, &bytes, kind as u32)
})
}

// bloom_unload_texture [source: curated]
#[no_mangle]
pub extern "C" fn bloom_unload_texture(handle: f64) {
Expand Down Expand Up @@ -442,6 +476,90 @@ macro_rules! __bloom_ffi_assets {
})
}

// Explicit render-target color treatment for compatibility renderers:
// 0=sRGB RGBA8, 1=linear RGBA8, 2=linear RGBA16F.
#[no_mangle]
pub extern "C" fn bloom_load_render_texture_kind(
width: f64,
height: f64,
kind: f64,
) -> f64 {
$crate::ffi::guard("bloom_load_render_texture_kind", move || {
let w = (width as u32).max(1);
let h = (height as u32).max(1);
let kind = (kind as u32).min(2);
let eng = engine();
let rt_handle = eng.textures.load_render_texture_kind(w, h);
let (bind_group_idx, _) = eng.renderer.create_render_texture_kind(w, h, kind);
let tex_handle = eng.textures.textures.alloc($crate::textures::TextureData {
bind_group_idx,
width: w,
height: h,
});
eng.textures
.set_render_texture_handle(rt_handle, tex_handle);
rt_handle
})
}

#[no_mangle]
pub extern "C" fn bloom_render_texture_glsl(
render_texture: f64,
source_ptr: *const u8,
) -> f64 {
$crate::ffi::guard("bloom_render_texture_glsl", move || {
let source = $crate::string_header::str_from_header(source_ptr);
let eng = engine();
let Some(rt) = eng.textures.render_textures.get(render_texture) else {
return 0.0;
};
let Some(texture) = eng.textures.textures.get(rt.texture_handle) else {
return 0.0;
};
match eng
.renderer
.render_glsl_fragment_to_texture(texture.bind_group_idx as usize, source)
{
Ok(()) => 1.0,
Err(error) => {
eprintln!("[compat-glsl] {error}");
0.0
}
}
})
}

#[no_mangle]
pub extern "C" fn bloom_render_texture_sobel(
render_texture: f64,
source_texture: f64,
strength: f64,
) -> f64 {
$crate::ffi::guard("bloom_render_texture_sobel", move || {
let eng = engine();
let Some(rt) = eng.textures.render_textures.get(render_texture) else {
return 0.0;
};
let Some(target) = eng.textures.textures.get(rt.texture_handle) else {
return 0.0;
};
let Some(source) = eng.textures.textures.get(source_texture) else {
return 0.0;
};
match eng.renderer.render_sobel_to_texture(
target.bind_group_idx as usize,
source.bind_group_idx as usize,
strength as f32,
) {
Ok(()) => 1.0,
Err(error) => {
eprintln!("[compat-sobel] {error}");
0.0
}
}
})
}

// bloom_unload_render_texture [source: macos]
#[no_mangle]
pub extern "C" fn bloom_unload_render_texture(handle: f64) {
Expand Down
Loading