feat: compose interactive world ui across nested 3d viewports
This commit is contained in:
@@ -6,6 +6,42 @@ use crate::{
|
||||
|
||||
pub struct SoftwareRenderer;
|
||||
|
||||
thread_local! {
|
||||
static RENDER_DEPTH:std::cell::Cell<usize>=const { std::cell::Cell::new(0) };
|
||||
static PIXEL_UNITS:std::cell::Cell<usize>=const { std::cell::Cell::new(0) };
|
||||
}
|
||||
pub(crate) struct RenderScope;
|
||||
impl RenderScope {
|
||||
pub fn enter() -> Result<Self, &'static str> {
|
||||
RENDER_DEPTH.with(|depth| {
|
||||
let current = depth.get();
|
||||
if current >= 18 {
|
||||
return Err("render nesting budget exceeded");
|
||||
}
|
||||
if current == 0 {
|
||||
PIXEL_UNITS.with(|pixels| pixels.set(0));
|
||||
}
|
||||
depth.set(current + 1);
|
||||
Ok(Self)
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Drop for RenderScope {
|
||||
fn drop(&mut self) {
|
||||
RENDER_DEPTH.with(|depth| depth.set(depth.get() - 1));
|
||||
}
|
||||
}
|
||||
pub(crate) fn reserve_pixels(units: usize) -> Result<(), &'static str> {
|
||||
PIXEL_UNITS.with(|pixels| {
|
||||
let next = pixels.get().saturating_add(units);
|
||||
if next > 16_777_216 {
|
||||
return Err("nested render pixel budget exceeded");
|
||||
}
|
||||
pixels.set(next);
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
impl SoftwareRenderer {
|
||||
pub fn render(
|
||||
list: &DisplayList,
|
||||
@@ -13,6 +49,7 @@ impl SoftwareRenderer {
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<(), &'static str> {
|
||||
let _scope = RenderScope::enter()?;
|
||||
let mut canvas = Canvas {
|
||||
pixels: target,
|
||||
width,
|
||||
|
||||
Reference in New Issue
Block a user