What differs between them: the source
Open the live demo · Read the guide · View on GitHub
Regions the guide quotes: rows (line 44), stable (line 95).
1/// A live table of what the device open right now can do, read straight off
2/// `GraphicsDevice`, not off a name.
3///
4/// Quoted by `backend_matrix.md` and shown whole in the Source tab.
5library;
7import 'package:flutter/widgets.dart';
8import 'package:flutter3d/flutter3d.dart';
9import 'package:flutter3d_showcase/src/demo/capability_report.dart';
10import 'package:flutter3d_showcase/src/demo/demo.dart';
12/// The `backend-matrix` page: the lit ball beside a table of the open device's
13/// capabilities. Its check fails if the device answers any of them differently
14/// after a frame.
15final class BackendMatrixDemo extends ShowcaseDemo {
16 late final GraphicsDevice _device;
17 late final CapabilityReport _atBuild;
20 Scene build(DemoContext context) {
21 _device = context.device;
22 _atBuild = context.caps;
23 final RenderMaterial stone = RenderMaterial(
24 name: 'stone',
25 baseColor: LinearColor.fromSrgb(0.5, 0.5, 0.55, 1.0),
26 roughness: 0.6,
27 );
28 final MeshNode ball = MeshNode(
29 DeviceMesh.upload(
30 context.device,
31 SphereShape(segments: 24, rings: 12).build(),
32 ),
33 stone,
34 name: 'ball',
35 );
36 return Scene()
37 ..add(ball)
38 ..add(
39 LightNode(name: 'sun', intensity: 3.0 * LightNode.legacyUnit)
40 ..setLocalForward(Vector3(-0.4, -1.0, -0.3)),
41 );
42 }
44 List<(String, String)> _rows(GraphicsDevice device) => <(String, String)>[
45 ('wireframe', '${device.features.has(DeviceFeature.wireframe)}'),
46 ('cube textures', '${device.features.has(DeviceFeature.cubeTextures)}'),
47 ('mip maps', '${device.features.has(DeviceFeature.manualMipmaps)}'),
48 (
49 'render into a mip level',
50 '${device.features.has(DeviceFeature.renderToMipLevel)}',
51 ),
52 ('a stencil buffer', '${device.features.has(DeviceFeature.stencil)}'),
53 ('a blend constant', '${device.features.has(DeviceFeature.blendConstant)}'),
54 (
55 'offscreen MSAA',
56 '${device.features.has(DeviceFeature.offscreenMultisample)}',
57 ),
58 ('max anisotropy', '${device.limits.maxSamplerAnisotropy}'),
59 ('max colour attachments', '${device.limits.maxColorAttachments}'),
60 ('preferred sample count', '${device.preferredSampleCount}'),
61 ];
64 Widget? customBody(BuildContext buildContext, DemoContext context) =>
65 Container(
66 color: const Color(0xFF14161A),
67 padding: const EdgeInsets.all(24),
68 alignment: Alignment.topLeft,
69 child: DefaultTextStyle(
70 style: const TextStyle(color: Color(0xFFE8E8EC), fontSize: 16),
71 child: Column(
72 crossAxisAlignment: CrossAxisAlignment.start,
73 children: <Widget>[
74 const Text(
75 'What the device open right now answers to every capability '
76 'question the engine asks. No name is read anywhere on this '
77 'page; the table below is built entirely from the device.',
78 ),
79 const SizedBox(height: 16),
80 for (final (String, String) row in _rows(context.device))
81 Padding(
82 padding: const EdgeInsets.symmetric(vertical: 2),
83 child: Text('${row.$1}: ${row.$2}'),
84 ),
85 ],
86 ),
87 ),
88 );
91 void verify(Scene scene, FrameResult frame) {
92 if (frame.drawCalls < 1) {
93 throw StateError('the ball was not drawn');
94 }
95 // The capability report this page showed at build time has to still
96 // agree with a fresh reading of the same device after a frame has run.
97 // A backend's answers are a property of the device, not something a
98 // frame could have changed.
99 final CapabilityReport now = CapabilityReport.of(_device);
100 if (!now.met.containsAll(_atBuild.met) ||
101 !_atBuild.met.containsAll(now.met)) {
102 throw StateError(
103 'the device answered a capability differently after a frame',
104 );
105 }
106 }
107}