flutter3d
Showcase Changelog 38 packages API reference

The surface buffer: the source

since 0.4.3 Post-processing

Regions the guide quotes: show (line 27), consumed (line 41).

1/// The surface buffer: the world normal and view-axis depth the scene pass
2/// writes for every screen-space effect to share, put on the screen raw.
3///
4/// Quoted by `surface_buffer.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 SurfaceBufferDemo extends ShowcaseDemo {
12 bool show = true;
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 showSurfaceBuffer: show,
28 );
30 @override
31 List<DemoControl> controls(DemoContext context) => <DemoControl>[
32 ToggleControl(
33 'Show the buffer',
34 value: () => show,
35 onChanged: (bool v) => show = v,
36 ),
37 ];
39 @override
40 void verify(Scene scene, FrameResult frame) {
41 // Asking to see the buffer is asking the scene pass to write it, which on
42 // a device that can otherwise multisample costs the frame that
43 // multisampling for exactly the reason `msaa` explains.
44 final String? declined = frame.antiAliasing.msaaDeclined;
45 if (!_deviceCanMsaa) {
46 if (declined == null) {
47 throw StateError('this device cannot multisample and did not say so');
48 }
49 } else if (show) {
50 if (declined == null) {
51 throw StateError('showing the buffer should have cost multisampling');
52 }
53 } else if (declined != null) {
54 throw StateError('nothing here reads the buffer, and it still declined');
55 }
56 }