embedded-3dgfx 0.7.2

3D graphics rendering for embedded systems (fork of embedded-gfx by Kezii)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
//! Standard Z-buffered triangle rasterization, Gouraud shading, and translucent triangles.

use core::fmt::Debug;
use embedded_graphics_core::draw_target::DrawTarget;
use embedded_graphics_core::pixelcolor::Rgb565;

use super::state::{RasterState, apply_order, ascending_y_order, tri_fully_off_screen};
use crate::pipeline::assemble::primitive::DrawPrimitive;
use crate::pipeline::effects::{DepthBias, DepthInterpolationMode, DitherConfig, FogConfig};

pub(crate) mod flat;
#[cfg(feature = "lighting")]
pub(crate) mod gouraud;
pub(crate) mod screendoor;
pub(crate) mod translucent;

use flat::fill_triangle_zbuffered;
#[cfg(feature = "lighting")]
use gouraud::fill_triangle_zbuffered_gouraud;
use screendoor::fill_triangle_zbuffered_screendoor;
use translucent::fill_triangle_zbuffered_translucent;

/// Render a primitive with Z-buffering and default raster state.
#[inline]
pub fn draw_zbuffered<D: DrawTarget<Color = Rgb565>>(
    primitive: DrawPrimitive,
    fb: &mut D,
    zbuffer: &mut [crate::ZDepth],
    width: usize,
) where
    <D as DrawTarget>::Error: Debug,
{
    let state = RasterState::from_zbuffer(width, zbuffer.len());
    draw_zbuffered_with_state(primitive, fb, zbuffer, &state);
}

/// Apply the per-triangle depth interpolation mode and optional constant bias.
#[inline]
fn resolve_depths(
    raw: [f32; 3],
    points: &[nalgebra::Point2<i32>; 3],
    state: &RasterState<'_>,
) -> (f32, f32, f32) {
    let (z1, z2, z3) = state.depth_mode.process_depths(raw[0], raw[1], raw[2]);
    match state.depth_bias {
        Some(b) => b.apply(points[0], points[1], points[2], z1, z2, z3),
        None => (z1, z2, z3),
    }
}

/// Render a primitive with Z-buffering, using fog / dither / depth settings
/// from `state`.
///
/// This is the single entry point the old `draw_zbuffered`,
/// `_with_effects`, `_with_options`, and `_with_bias` wrappers all forwarded to;
/// they are now expressed as [`RasterState`] builders instead of a chain of
/// near-identical functions.
pub fn draw_zbuffered_with_state<D: DrawTarget<Color = Rgb565>>(
    primitive: DrawPrimitive,
    fb: &mut D,
    zbuffer: &mut [crate::ZDepth],
    state: &RasterState<'_>,
) where
    <D as DrawTarget>::Error: Debug,
{
    match primitive {
        DrawPrimitive::ColoredTriangleWithDepth {
            mut points,
            depths: mut raw_depths,
            color,
        } => {
            let order = ascending_y_order(&points);
            apply_order(&mut points, order);
            apply_order(&mut raw_depths, order);
            if tri_fully_off_screen(&points, state.width, state.height) {
                return;
            }
            let (z1, z2, z3) = resolve_depths(raw_depths, &points, state);
            let [p1, p2, p3] = points;

            // Hardware path: offer the triangle to the sink before rasterizing.
            // The sink sees the same vertices and the same *resolved* depths the
            // CPU path would use, so a backend that declines -- buffer full, or a
            // primitive it cannot represent -- gets an identical CPU fallback.
            //
            // Withheld when fog or dither is active, because the CPU path applies
            // both *inside* `fill_triangle_zbuffered`, below. Offering the triangle
            // anyway would render it without them: wrong output rather than a slow
            // one. Screen-door stipple is a separate primitive variant, so it is not
            // a concern here. A sink able to apply these effects itself cannot yet
            // say so -- that needs a capability handshake rather than an assumption.
            let effects_blocked = state.fog.is_some() || state.dither.is_some();
            if let Some(sink) = state.sink {
                if !effects_blocked && sink.triangle(&[p1, p2, p3], &[z1, z2, z3], color) {
                    return;
                }
            }

            fill_triangle_zbuffered(
                p1,
                p2,
                p3,
                z1,
                z2,
                z3,
                color,
                fb,
                zbuffer,
                state.width,
                state.fog,
                state.dither,
            );
        }

        DrawPrimitive::TranslucentTriangleWithDepth {
            mut points,
            depths: mut raw_depths,
            color,
            alpha,
        } => {
            let order = ascending_y_order(&points);
            apply_order(&mut points, order);
            apply_order(&mut raw_depths, order);
            if tri_fully_off_screen(&points, state.width, state.height) {
                return;
            }
            let (z1, z2, z3) = resolve_depths(raw_depths, &points, state);
            let [p1, p2, p3] = points;
            fill_triangle_zbuffered_translucent(
                p1,
                p2,
                p3,
                z1,
                z2,
                z3,
                color,
                alpha,
                fb,
                zbuffer,
                state.width,
            );
        }

        DrawPrimitive::ScreenDoorTriangleWithDepth {
            mut points,
            depths: mut raw_depths,
            color,
            alpha,
        } => {
            let order = ascending_y_order(&points);
            apply_order(&mut points, order);
            apply_order(&mut raw_depths, order);
            if tri_fully_off_screen(&points, state.width, state.height) {
                return;
            }
            let (z1, z2, z3) = resolve_depths(raw_depths, &points, state);
            let [p1, p2, p3] = points;
            fill_triangle_zbuffered_screendoor(
                p1,
                p2,
                p3,
                z1,
                z2,
                z3,
                color,
                alpha,
                fb,
                zbuffer,
                state.width,
            );
        }

        #[cfg(feature = "lighting")]
        DrawPrimitive::GouraudTriangleWithDepth {
            mut points,
            depths: mut raw_depths,
            mut colors,
        } => {
            let order = ascending_y_order(&points);
            apply_order(&mut points, order);
            apply_order(&mut raw_depths, order);
            apply_order(&mut colors, order);
            if tri_fully_off_screen(&points, state.width, state.height) {
                return;
            }
            let (z1, z2, z3) = resolve_depths(raw_depths, &points, state);
            let [p1, p2, p3] = points;
            let [c1, c2, c3] = colors;
            fill_triangle_zbuffered_gouraud(
                p1,
                p2,
                p3,
                z1,
                z2,
                z3,
                c1,
                c2,
                c3,
                fb,
                zbuffer,
                state.width,
                state.fog,
                state.dither,
            );
        }

        // Non-zbuffered primitives -- lines, points, plain triangles -- are offered
        // to the sink inside `fill::draw_with_state`, which is why the state has to
        // travel with them.
        _ => super::fill::draw_with_state(primitive, fb, state),
    }
}

/// Compatibility adapter over [`draw_zbuffered_with_state`]: Z-buffer render
/// with optional fog / dither post-processing.
#[inline]
pub fn draw_zbuffered_with_effects<D: DrawTarget<Color = Rgb565>>(
    primitive: DrawPrimitive,
    fb: &mut D,
    zbuffer: &mut [crate::ZDepth],
    width: usize,
    fog_config: Option<&FogConfig>,
    dither_config: Option<&DitherConfig>,
) where
    <D as DrawTarget>::Error: Debug,
{
    let state = RasterState::from_zbuffer(width, zbuffer.len())
        .with_fog(fog_config)
        .with_dither(dither_config);
    draw_zbuffered_with_state(primitive, fb, zbuffer, &state);
}

/// Compatibility adapter over [`draw_zbuffered_with_state`]: adds an explicit
/// depth interpolation mode.
#[inline]
pub fn draw_zbuffered_with_options<D: DrawTarget<Color = Rgb565>>(
    primitive: DrawPrimitive,
    fb: &mut D,
    zbuffer: &mut [crate::ZDepth],
    width: usize,
    fog_config: Option<&FogConfig>,
    dither_config: Option<&DitherConfig>,
    depth_mode: DepthInterpolationMode,
) where
    <D as DrawTarget>::Error: Debug,
{
    let state = RasterState::from_zbuffer(width, zbuffer.len())
        .with_fog(fog_config)
        .with_dither(dither_config)
        .with_depth_mode(depth_mode);
    draw_zbuffered_with_state(primitive, fb, zbuffer, &state);
}

/// Compatibility adapter over [`draw_zbuffered_with_state`]: adds an optional
/// constant depth bias (decals / overlays).
#[inline]
pub fn draw_zbuffered_with_bias<D: DrawTarget<Color = Rgb565>>(
    primitive: DrawPrimitive,
    fb: &mut D,
    zbuffer: &mut [crate::ZDepth],
    width: usize,
    fog_config: Option<&FogConfig>,
    dither_config: Option<&DitherConfig>,
    depth_mode: DepthInterpolationMode,
    bias: Option<DepthBias>,
) where
    <D as DrawTarget>::Error: Debug,
{
    let state = RasterState::from_zbuffer(width, zbuffer.len())
        .with_fog(fog_config)
        .with_dither(dither_config)
        .with_depth_mode(depth_mode)
        .with_depth_bias(bias);
    draw_zbuffered_with_state(primitive, fb, zbuffer, &state);
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::pipeline::assemble::primitive::DrawPrimitive;
    use crate::pipeline::effects::{DepthInterpolationMode, FogConfig};
    use embedded_graphics_core::Pixel;
    use embedded_graphics_core::geometry::{OriginDimensions, Size};
    use embedded_graphics_core::pixelcolor::RgbColor;

    struct TestFb<const W: usize, const H: usize> {
        pixels: [Rgb565; 400],
    }

    impl<const W: usize, const H: usize> Default for TestFb<W, H> {
        fn default() -> Self {
            Self {
                pixels: [Rgb565::BLACK; 400],
            }
        }
    }

    impl<const W: usize, const H: usize> OriginDimensions for TestFb<W, H> {
        fn size(&self) -> Size {
            Size::new(W as u32, H as u32)
        }
    }

    impl<const W: usize, const H: usize> DrawTarget for TestFb<W, H> {
        type Color = Rgb565;
        type Error = core::convert::Infallible;

        fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>
        where
            I: IntoIterator<Item = Pixel<Self::Color>>,
        {
            for Pixel(point, color) in pixels {
                if point.x >= 0 && point.x < W as i32 && point.y >= 0 && point.y < H as i32 {
                    let idx = (point.y as usize) * W + (point.x as usize);
                    if idx < self.pixels.len() {
                        self.pixels[idx] = color;
                    }
                }
            }
            Ok(())
        }
    }

    #[test]
    fn test_draw_zbuffered_primitives() {
        let mut fb = TestFb::<20, 20>::default();
        let mut zbuf = [crate::Z_MAX_VALUE; 400];

        // Draw close red triangle at z = 1.0
        let close_tri = DrawPrimitive::ColoredTriangleWithDepth {
            points: [
                nalgebra::Point2::new(10, 2),
                nalgebra::Point2::new(2, 18),
                nalgebra::Point2::new(18, 18),
            ],
            depths: [1.0, 1.0, 1.0],
            color: Rgb565::RED,
        };
        draw_zbuffered(close_tri, &mut fb, &mut zbuf, 20);

        let center_idx = 10 * 20 + 10;
        assert_eq!(fb.pixels[center_idx], Rgb565::RED);

        // Draw far green triangle at z = 5.0 (should be occluded by zbuffer)
        let far_tri = DrawPrimitive::ColoredTriangleWithDepth {
            points: [
                nalgebra::Point2::new(10, 2),
                nalgebra::Point2::new(2, 18),
                nalgebra::Point2::new(18, 18),
            ],
            depths: [5.0, 5.0, 5.0],
            color: Rgb565::GREEN,
        };
        draw_zbuffered(far_tri, &mut fb, &mut zbuf, 20);

        // Center pixel should STILL be red
        assert_eq!(fb.pixels[center_idx], Rgb565::RED);
    }

    /// Records what it is offered, and can be told to decline.
    #[derive(Debug)]
    struct RecordingSink {
        accept: bool,
        seen: core::cell::Cell<usize>,
        last: core::cell::Cell<(nalgebra::Point2<i32>, f32, Rgb565)>,
    }

    impl RecordingSink {
        fn new(accept: bool) -> Self {
            Self {
                accept,
                seen: core::cell::Cell::new(0),
                last: core::cell::Cell::new((nalgebra::Point2::new(0, 0), 0.0, Rgb565::BLACK)),
            }
        }
    }

    impl crate::pipeline::rasterize::draw::sink::RasterSink for RecordingSink {
        fn triangle(
            &self,
            points: &[nalgebra::Point2<i32>; 3],
            depths: &[f32; 3],
            color: Rgb565,
        ) -> bool {
            self.seen.set(self.seen.get() + 1);
            self.last.set((points[0], depths[0], color));
            self.accept
        }

        fn line(&self, a: nalgebra::Point2<i32>, _b: nalgebra::Point2<i32>, color: Rgb565) -> bool {
            self.seen.set(self.seen.get() + 1);
            self.last.set((a, 0.0, color));
            self.accept
        }
    }

    /// The sink sees the triangle the CPU would have drawn, and its answer
    /// decides whether the CPU draws it.
    #[test]
    fn raster_sink_takes_over_and_can_decline() {
        let tri = || DrawPrimitive::ColoredTriangleWithDepth {
            points: [
                nalgebra::Point2::new(10, 2),
                nalgebra::Point2::new(2, 18),
                nalgebra::Point2::new(18, 18),
            ],
            depths: [1.0, 1.0, 1.0],
            color: Rgb565::RED,
        };
        let center = 10 * 20 + 10;

        // Accepted: hardware owns the triangle, so the CPU must not draw it.
        let mut fb = TestFb::<20, 20>::default();
        let mut zbuf = [crate::Z_MAX_VALUE; 400];
        let accepting = RecordingSink::new(true);
        let state = RasterState::new(20, 20).with_raster_sink(Some(&accepting));
        draw_zbuffered_with_state(tri(), &mut fb, &mut zbuf, &state);

        assert_eq!(
            accepting.seen.get(),
            1,
            "triangle should be offered to the sink"
        );
        let (first_point, first_depth, color) = accepting.last.get();
        assert_eq!(first_point, nalgebra::Point2::new(10, 2));
        assert_eq!(first_depth, 1.0);
        assert_eq!(color, Rgb565::RED);
        assert_eq!(
            fb.pixels[center],
            Rgb565::BLACK,
            "an accepted triangle must be left to the hardware"
        );

        // Declined: the CPU rasterizer must still draw it.
        let mut fb2 = TestFb::<20, 20>::default();
        let mut zbuf2 = [crate::Z_MAX_VALUE; 400];
        let declining = RecordingSink::new(false);
        let state2 = RasterState::new(20, 20).with_raster_sink(Some(&declining));
        draw_zbuffered_with_state(tri(), &mut fb2, &mut zbuf2, &state2);

        assert_eq!(
            declining.seen.get(),
            1,
            "a declining sink is still offered it"
        );
        assert_eq!(
            fb2.pixels[center],
            Rgb565::RED,
            "a declined triangle must fall back to the CPU rasterizer"
        );
    }

    /// Lines take the same two-way path, but through `fill::draw_with_state`
    /// because they are not z-buffered -- they reach the sink via the match
    /// catch-all rather than a triangle arm.
    #[test]
    fn line_sink_takes_over_and_can_decline() {
        let line = || {
            DrawPrimitive::Line(
                [nalgebra::Point2::new(2, 2), nalgebra::Point2::new(17, 2)],
                Rgb565::RED,
            )
        };
        let start = 2 * 20 + 2;

        // Accepted: hardware owns the whole line, so no pixel is written.
        let mut fb = TestFb::<20, 20>::default();
        let accepting = RecordingSink::new(true);
        let state = RasterState::new(20, 20).with_raster_sink(Some(&accepting));
        crate::pipeline::rasterize::draw::fill::draw_with_state(line(), &mut fb, &state);

        assert_eq!(
            accepting.seen.get(),
            1,
            "line should be offered to the sink"
        );
        assert_eq!(
            fb.pixels[start],
            Rgb565::BLACK,
            "an accepted line must be left to the hardware"
        );

        // Declined: the CPU Bresenham path must draw it.
        let mut fb2 = TestFb::<20, 20>::default();
        let declining = RecordingSink::new(false);
        let state2 = RasterState::new(20, 20).with_raster_sink(Some(&declining));
        crate::pipeline::rasterize::draw::fill::draw_with_state(line(), &mut fb2, &state2);

        assert_eq!(
            declining.seen.get(),
            1,
            "a declining sink is still offered it"
        );
        assert_eq!(
            fb2.pixels[start],
            Rgb565::RED,
            "a declined line must fall back to CPU Bresenham"
        );
    }

    /// Fog (and dither) are applied *inside* the CPU triangle fill, so a
    /// sink-served triangle would silently render without them. The engine must
    /// withhold the triangle while either is active -- wrong output is worse than
    /// a slow path.
    #[test]
    fn triangle_is_withheld_from_the_sink_when_fog_is_active() {
        let mut fb = TestFb::<20, 20>::default();
        let mut zbuf = [crate::Z_MAX_VALUE; 400];
        let sink = RecordingSink::new(true);
        let fog = FogConfig::new(Rgb565::BLACK, 1.0, 100.0);
        let state = RasterState::new(20, 20)
            .with_raster_sink(Some(&sink))
            .with_fog(Some(&fog));

        draw_zbuffered_with_state(
            DrawPrimitive::ColoredTriangleWithDepth {
                points: [
                    nalgebra::Point2::new(10, 2),
                    nalgebra::Point2::new(2, 18),
                    nalgebra::Point2::new(18, 18),
                ],
                depths: [1.0, 1.0, 1.0],
                color: Rgb565::RED,
            },
            &mut fb,
            &mut zbuf,
            &state,
        );

        assert_eq!(
            sink.seen.get(),
            0,
            "fog must keep the triangle off the sink, on the CPU path"
        );
        assert_eq!(
            fb.pixels[10 * 20 + 10],
            Rgb565::RED,
            "and the CPU must still have drawn it"
        );
    }

    #[test]
    fn test_draw_zbuffered_with_options() {
        let mut fb = TestFb::<20, 20>::default();
        let mut zbuf = [crate::Z_MAX_VALUE; 400];

        let tri = DrawPrimitive::ColoredTriangleWithDepth {
            points: [
                nalgebra::Point2::new(10, 2),
                nalgebra::Point2::new(2, 18),
                nalgebra::Point2::new(18, 18),
            ],
            depths: [2.0, 2.0, 2.0],
            color: Rgb565::WHITE,
        };

        let fog = FogConfig::new(Rgb565::BLUE, 1.0, 5.0);

        draw_zbuffered_with_options(
            tri,
            &mut fb,
            &mut zbuf,
            20,
            Some(&fog),
            None,
            DepthInterpolationMode::Exact,
        );

        let center_idx = 10 * 20 + 10;
        assert!(fb.pixels[center_idx].b() > 0);
    }

    #[test]
    fn test_draw_zbuffered_translucent() {
        let mut fb = TestFb::<20, 20>::default();
        let mut zbuf = [crate::Z_MAX_VALUE; 400];

        let trans_tri = DrawPrimitive::TranslucentTriangleWithDepth {
            points: [
                nalgebra::Point2::new(10, 2),
                nalgebra::Point2::new(2, 18),
                nalgebra::Point2::new(18, 18),
            ],
            depths: [1.0, 1.0, 1.0],
            color: Rgb565::RED,
            alpha: 128,
        };
        draw_zbuffered(trans_tri, &mut fb, &mut zbuf, 20);

        let center_idx = 10 * 20 + 10;
        assert!(fb.pixels[center_idx].r() > 0);
    }

    #[test]
    fn test_draw_zbuffered_screendoor() {
        let mut fb = TestFb::<20, 20>::default();
        let mut zbuf = [crate::Z_MAX_VALUE; 400];

        let screendoor_tri = DrawPrimitive::ScreenDoorTriangleWithDepth {
            points: [
                nalgebra::Point2::new(10, 2),
                nalgebra::Point2::new(2, 18),
                nalgebra::Point2::new(18, 18),
            ],
            depths: [1.0, 1.0, 1.0],
            color: Rgb565::GREEN,
            alpha: 128,
        };
        draw_zbuffered(screendoor_tri, &mut fb, &mut zbuf, 20);

        // At least some pixels inside the triangle should be rendered GREEN
        let mut green_count = 0;
        for p in fb.pixels {
            if p == Rgb565::GREEN {
                green_count += 1;
            }
        }
        assert!(green_count > 0);
    }

    #[test]
    fn test_draw_zbuffered_bias() {
        let mut fb = TestFb::<20, 20>::default();
        let mut zbuf = [crate::Z_MAX_VALUE; 400];

        // Draw a base red triangle at depth 2.0
        let base_tri = DrawPrimitive::ColoredTriangleWithDepth {
            points: [
                nalgebra::Point2::new(10, 2),
                nalgebra::Point2::new(2, 18),
                nalgebra::Point2::new(18, 18),
            ],
            depths: [2.0, 2.0, 2.0],
            color: Rgb565::RED,
        };
        draw_zbuffered(base_tri, &mut fb, &mut zbuf, 20);

        let center_idx = 10 * 20 + 10;
        assert_eq!(fb.pixels[center_idx], Rgb565::RED);

        // Draw a coplanar decal blue triangle with depth bias
        let decal_tri = DrawPrimitive::ColoredTriangleWithDepth {
            points: [
                nalgebra::Point2::new(10, 2),
                nalgebra::Point2::new(2, 18),
                nalgebra::Point2::new(18, 18),
            ],
            depths: [2.0, 2.0, 2.0],
            color: Rgb565::BLUE,
        };
        draw_zbuffered_with_bias(
            decal_tri,
            &mut fb,
            &mut zbuf,
            20,
            None,
            None,
            DepthInterpolationMode::Exact,
            Some(DepthBias::decal()),
        );

        // Decal should cleanly overwrite the base triangle due to depth bias
        assert_eq!(fb.pixels[center_idx], Rgb565::BLUE);
    }
}