flutter3d
Showcase Changelog 38 packages API reference

Automatic multisampling: the source

since 0.7.0 Post-processing

Regions the guide quotes: ask (line 21), compete (line 27), declined (line 41).

1/// Automatic multisampling: smoothed edges from the scene pass itself, with
2/// no extra pass and no texture read back.
3///
4/// Quoted by `msaa.md` and shown whole in the Source tab.
5library;
6
7import 'package:flutter3d/flutter3d.dart';
8import 'package:flutter3d_showcase/pages/post/post_stage.dart';
9import 'package:flutter3d_showcase/src/demo/demo.dart';
11final class MsaaDemo extends ShowcaseDemo {
12 bool readSurface = false;
14 late final bool _deviceCanMsaa;
16 @override
17 void configureView(DemoContext context) => PostStage.frame(context);
19 @override
20 Scene build(DemoContext context) {
21 _deviceCanMsaa = context.device.supportsOffscreenMsaa;
22 return PostStage.build(context).scene;
23 }
25 @override
26 RenderSettings settings(DemoContext context) => RenderSettings(
27 ambientOcclusion: AmbientOcclusionSettings(enabled: readSurface),
28 );
30 @override
31 List<DemoControl> controls(DemoContext context) => <DemoControl>[
32 ToggleControl(
33 'Ambient occlusion (reads the surface buffer)',
34 value: () => readSurface,
35 onChanged: (bool v) => readSurface = v,
36 ),
37 ];
39 @override
40 void verify(Scene scene, FrameResult frame) {
41 final String? declined = frame.antiAliasing.msaaDeclined;
42 if (!_deviceCanMsaa) {
43 if (declined == null) {
44 throw StateError(
45 'this device cannot multisample and the frame '
46 'did not say so',
47 );
48 }
49 } else if (readSurface) {
50 if (declined == null || frame.antiAliasing.msaaSamples > 1) {
51 throw StateError(
52 'the surface buffer is in use and the scene pass '
53 'still multisampled',
54 );
55 }
56 } else {
57 if (declined != null || frame.antiAliasing.msaaSamples <= 1) {
58 throw StateError(
59 'nothing stopped multisampling and the scene pass '
60 'did not use it',
61 );
62 }
63 }
64 }