Skip to content

Commit

Permalink
Support interpolation for 2D rendering modes (#102)
Browse files Browse the repository at this point in the history
Changed to 2D rendering API to support render modes which use linear
interpolation to process full / empty regions.

- Specifically, `RenderMode::interval` now returns an `IntervalAction`,
which can be `Fill(..)`, `Recurse`, or `Interpolate`
- Modify `SdfRenderMode` use this interpolation; the previous
pixel-perfect behavior is renamed to `SdfPixelRenderModel`
- Make `RenderMode` trait methods static, because they weren't using
`&self`
- Change signature of `fidget::render::render2d` to pass the mode only
as a generic parameter, instead of an argument
  • Loading branch information
mkeeter authored May 12, 2024
1 parent 4a141ae commit f15e65d
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 94 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# 0.2.7 (in progress)
- Changed to 2D rendering API to support render modes which use linear
interpolation to process full / empty regions
- Specifically, `RenderMode::interval` now returns an `IntervalAction`,
which can be `Fill(..)`, `Recurse`, or `Interpolate`.
- Modify `SdfRenderMode` use this interpolation; the previous pixel-perfect
behavior is renamed to `SdfPixelRenderModel`
- Make `RenderMode` trait methods static, because they weren't using `&self`
- Change signature of `fidget::render::render2d` to pass the mode only as a
generic parameter, instead of an argument

# 0.2.6
This is a relatively small release; there are a few features to improve the
Expand Down
18 changes: 8 additions & 10 deletions demo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,10 @@ fn run2d<S: fidget::eval::Shape>(
if sdf {
let mut image = vec![];
for _ in 0..settings.n {
image = fidget::render::render2d(
shape.clone(),
&cfg,
&fidget::render::SdfRenderMode,
);
image = fidget::render::render2d::<
_,
fidget::render::SdfRenderMode,
>(shape.clone(), &cfg);
}
image
.into_iter()
Expand All @@ -222,11 +221,10 @@ fn run2d<S: fidget::eval::Shape>(
} else {
let mut image = vec![];
for _ in 0..settings.n {
image = fidget::render::render2d(
shape.clone(),
&cfg,
&fidget::render::DebugRenderMode,
);
image = fidget::render::render2d::<
_,
fidget::render::DebugRenderMode,
>(shape.clone(), &cfg);
}
image
.into_iter()
Expand Down
36 changes: 16 additions & 20 deletions fidget/benches/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ pub fn prospero_size_sweep(c: &mut Criterion) {
group.bench_function(BenchmarkId::new("vm", size), move |b| {
b.iter(|| {
let tape = shape_vm.clone();
black_box(fidget::render::render2d(
tape,
cfg,
&fidget::render::BitRenderMode,
))
black_box(fidget::render::render2d::<
_,
fidget::render::BitRenderMode,
>(tape, cfg))
})
});

Expand All @@ -42,11 +41,10 @@ pub fn prospero_size_sweep(c: &mut Criterion) {
group.bench_function(BenchmarkId::new("jit", size), move |b| {
b.iter(|| {
let tape = shape_jit.clone();
black_box(fidget::render::render2d(
tape,
cfg,
&fidget::render::BitRenderMode,
))
black_box(fidget::render::render2d::<
_,
fidget::render::BitRenderMode,
>(tape, cfg))
})
});
}
Expand All @@ -72,11 +70,10 @@ pub fn prospero_thread_sweep(c: &mut Criterion) {
group.bench_function(BenchmarkId::new("vm", threads), move |b| {
b.iter(|| {
let tape = shape_vm.clone();
black_box(fidget::render::render2d(
tape,
cfg,
&fidget::render::BitRenderMode,
))
black_box(fidget::render::render2d::<
_,
fidget::render::BitRenderMode,
>(tape, cfg))
})
});
#[cfg(feature = "jit")]
Expand All @@ -90,11 +87,10 @@ pub fn prospero_thread_sweep(c: &mut Criterion) {
group.bench_function(BenchmarkId::new("jit", threads), move |b| {
b.iter(|| {
let tape = shape_jit.clone();
black_box(fidget::render::render2d(
tape,
cfg,
&fidget::render::BitRenderMode,
))
black_box(fidget::render::render2d::<
_,
fidget::render::BitRenderMode,
>(tape, cfg))
})
});
}
Expand Down
2 changes: 1 addition & 1 deletion fidget/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
//! ..RenderConfig::default()
//! };
//! let shape = VmShape::from_tree(&tree);
//! let out = cfg.run(shape, &BitRenderMode)?;
//! let out = cfg.run::<_, BitRenderMode>(shape)?;
//! let mut iter = out.iter();
//! for y in 0..cfg.image_size {
//! for x in 0..cfg.image_size {
Expand Down
3 changes: 1 addition & 2 deletions fidget/src/render/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,8 @@ impl RenderConfig<2> {
pub fn run<S: Shape, M: RenderMode + Sync>(
&self,
shape: S,
mode: &M,
) -> Result<Vec<<M as RenderMode>::Output>, Error> {
Ok(crate::render::render2d::<S, M>(shape, self, mode))
Ok(crate::render::render2d::<S, M>(shape, self))
}
}

Expand Down
Loading

0 comments on commit f15e65d

Please sign in to comment.