Switching steps off: the source
Open the live demo · Read the guide · View on GitHub
Regions the guide quotes: names (line 15), disabled (line 42), report (line 56).
1/// Switching steps of the frame off, and asking the frame what became of
2/// their passes.
3///
4/// Quoted by `disabled_passes.md` and shown whole in the Source tab.
5library;
7import 'package:flutter3d/flutter3d.dart';
8import 'package:flutter3d_showcase/pages/post/post_stage.dart';
9import 'package:flutter3d_showcase/src/demo/demo.dart';
11/// The `disabled-passes` page: the post stage with steps of the frame
12/// switched off. Its check is that each pass of a step that is off reports
13/// `PassSkip.switchedOff`, and that the composite still ran.
14final class DisabledPassesDemo extends ShowcaseDemo {
15 /// The steps this scene turns on, in the order the frame runs them.
16 static const List<RenderStep> switchable = <RenderStep>[
17 RenderStep.shadows,
18 RenderStep.ambientOcclusion,
19 RenderStep.contactShadows,
20 RenderStep.bloom,
21 RenderStep.edgeSmoothing,
22 ];
24 /// The steps switched off, one switch each; bloom to begin with.
25 final Set<RenderStep> off = <RenderStep>{RenderStep.bloom};
28 void configureView(DemoContext context) => PostStage.frame(context);
31 Scene build(DemoContext context) =>
32 PostStage.build(context, shadows: true).scene;
35 RenderSettings settings(DemoContext context) =>
36 const RenderSettings(
37 ambientOcclusion: AmbientOcclusionSettings(enabled: true, radius: 0.8),
38 contactShadows: ContactShadowSettings(enabled: true),
39 antiAlias: AntiAliasSettings(enabled: true),
40 bloom: BloomSettings(intensity: 0.3),
41 )
42 .without(<RenderStep>{...off});
45 List<DemoControl> controls(DemoContext context) => <DemoControl>[
46 for (final RenderStep step in switchable)
47 ToggleControl(
48 'Skip ${step.name}',
49 value: () => off.contains(step),
50 onChanged: (bool skip) => skip ? off.add(step) : off.remove(step),
51 ),
52 ];
55 void verify(Scene scene, FrameResult frame) {
56 for (final RenderStep step in off) {
57 for (final String pass in step.passes) {
58 final PassSkip? why = frame.skipReasonOf(pass);
59 if (passRan(frame, pass) ||
60 (why != null && why != PassSkip.switchedOff)) {
61 throw StateError(
62 '"$pass" of $step was switched off and the frame '
63 'says ${why ?? 'it ran'}',
64 );
65 }
66 }
67 }
68 if (!passRan(frame, 'composite')) {
69 throw StateError('the composite pass is the frame and it did not run');
70 }
71 }
72}