flutter3d
Showcase Changelog 38 packages API reference

What differs between them: the source

since 0.2.0 Backends

Regions the guide quotes: rows (line 42), stable (line 87).

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;
6
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';
11import 'package:vector_math/vector_math.dart';
13final class BackendMatrixDemo extends ShowcaseDemo {
14 late final GraphicsDevice _device;
15 late final CapabilityReport _atBuild;
17 @override
18 Scene build(DemoContext context) {
19 _device = context.device;
20 _atBuild = context.caps;
21 final Material stone = Material(
22 name: 'stone',
23 baseColor: Vector4(0.5, 0.5, 0.55, 1.0),
24 roughness: 0.6,
25 );
26 final MeshNode ball = MeshNode(
27 DeviceMesh.upload(
28 context.device,
29 SphereShape(segments: 24, rings: 12).build(),
30 ),
31 stone,
32 name: 'ball',
33 );
34 return Scene()
35 ..add(ball)
36 ..add(
37 LightNode(name: 'sun', intensity: 3.0)
38 ..setLocalForward(Vector3(-0.4, -1.0, -0.3)),
39 );
40 }
42 List<(String, String)> _rows(GraphicsDevice device) => <(String, String)>[
43 ('wireframe', '${device.supportsWireframe}'),
44 ('cube textures', '${device.supportsCubeTextures}'),
45 ('mip maps', '${device.supportsMipmaps}'),
46 ('render into a mip level', '${device.supportsRenderToMip}'),
47 ('a stencil buffer', '${device.supportsStencil}'),
48 ('a blend constant', '${device.supportsBlendColor}'),
49 ('offscreen MSAA', '${device.supportsOffscreenMsaa}'),
50 ('max anisotropy', '${device.maxAnisotropy}'),
51 ('max colour attachments', '${device.maxColorAttachments}'),
52 ('preferred sample count', '${device.preferredSampleCount}'),
53 ];
55 @override
56 Widget? customBody(BuildContext buildContext, DemoContext context) =>
57 Container(
58 color: const Color(0xFF14161A),
59 padding: const EdgeInsets.all(24),
60 alignment: Alignment.topLeft,
61 child: DefaultTextStyle(
62 style: const TextStyle(color: Color(0xFFE8E8EC), fontSize: 16),
63 child: Column(
64 crossAxisAlignment: CrossAxisAlignment.start,
65 children: <Widget>[
66 const Text(
67 'What the device open right now answers to every capability '
68 'question the engine asks. No name is read anywhere on this '
69 'page; the table below is built entirely from the device.',
70 ),
71 const SizedBox(height: 16),
72 for (final (String, String) row in _rows(context.device))
73 Padding(
74 padding: const EdgeInsets.symmetric(vertical: 2),
75 child: Text('${row.$1}: ${row.$2}'),
76 ),
77 ],
78 ),
79 ),
80 );
82 @override
83 void verify(Scene scene, FrameResult frame) {
84 if (frame.drawCalls < 1) {
85 throw StateError('the ball was not drawn');
86 }
87 // The capability report this page showed at build time has to still
88 // agree with a fresh reading of the same device after a frame has run.
89 // A backend's answers are a property of the device, not something a
90 // frame could have changed.
91 final CapabilityReport now = CapabilityReport.of(_device);
92 if (!now.met.containsAll(_atBuild.met) ||
93 !_atBuild.met.containsAll(now.met)) {
94 throw StateError(
95 'the device answered a capability differently after a frame',
96 );
97 }
98 }