flutter3d
Showcase Changelog 62 packages API reference

The software rasteriser: the source

since 0.2.0 Backends

Regions the guide quotes: read (line 40), verify (line 66).

1/// The software rasteriser: no driver, no shading language, no command
2/// buffer, and no GPU underneath any of it.
3///
4/// Quoted by `backend_cpu.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/demo.dart';
11/// The `backend-cpu` page: the same lit ball the other backend pages draw,
12/// rendered on the software rasteriser.
13final class BackendCpuDemo extends ShowcaseDemo {
14 late final GraphicsDevice _device;
16 @override
17 Scene build(DemoContext context) {
18 _device = context.device;
19 final RenderMaterial stone = RenderMaterial(
20 name: 'stone',
21 baseColor: LinearColor.fromSrgb(0.6, 0.6, 0.65, 1.0),
22 roughness: 0.7,
23 );
24 final MeshNode ball = MeshNode(
25 DeviceMesh.upload(
26 context.device,
27 SphereShape(segments: 24, rings: 12).build(),
28 ),
29 stone,
30 name: 'ball',
31 );
32 return Scene()
33 ..add(ball)
34 ..add(
35 LightNode(name: 'sun', intensity: 3.0 * LightNode.legacyUnit)
36 ..setLocalForward(Vector3(-0.4, -1.0, -0.3)),
37 );
38 }
40 String _report(GraphicsDevice device) =>
41 'preferred sample count: ${device.preferredSampleCount}\n'
42 'offscreen MSAA: ${device.features.has(DeviceFeature.offscreenMultisample)}\n'
43 'wireframe: ${device.features.has(DeviceFeature.wireframe)}\n'
44 'stencil: ${device.features.has(DeviceFeature.stencil)}\n'
45 'mip maps: ${device.features.has(DeviceFeature.manualMipmaps)}';
47 @override
48 Widget? customBody(
49 BuildContext buildContext,
50 DemoContext context,
51 ) => Container(
52 color: const Color(0xFF14161A),
53 padding: const EdgeInsets.all(24),
54 alignment: Alignment.topLeft,
55 child: DefaultTextStyle(
56 style: const TextStyle(color: Color(0xFFE8E8EC), fontSize: 16),
57 child: Text(
58 'This build asked flutter3d_hardware\'s registry for a backend and '
59 'got the software rasteriser: no driver, no shading language, no '
60 'command buffer, so a backend agreeing with the hardware ones proves '
61 'something.\n\n${_report(context.device)}',
62 ),
63 ),
64 );
66 void _checkNoMultisampling() {
67 if (_device.preferredSampleCount != 1 ||
68 _device.features.has(DeviceFeature.offscreenMultisample)) {
69 throw StateError(
70 'the software rasteriser answering anything but "no multisampling" '
71 'would be a silent difference from the picture a hardware backend '
72 'draws',
73 );
74 }
75 }
77 @override
78 void verify(Scene scene, FrameResult frame) {
79 if (frame.drawCalls < 1) {
80 throw StateError('the ball was not drawn');
81 }
82 _checkNoMultisampling();
83 }