flutter3d
Showcase Changelog 38 packages API reference

The software rasteriser: the source

since 0.2.0 Backends

Regions the guide quotes: read (line 39), verify (line 65).

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';
10import 'package:vector_math/vector_math.dart';
12final class BackendCpuDemo extends ShowcaseDemo {
13 late final GraphicsDevice _device;
15 @override
16 Scene build(DemoContext context) {
17 _device = context.device;
18 final Material stone = Material(
19 name: 'stone',
20 baseColor: Vector4(0.6, 0.6, 0.65, 1.0),
21 roughness: 0.7,
22 );
23 final MeshNode ball = MeshNode(
24 DeviceMesh.upload(
25 context.device,
26 SphereShape(segments: 24, rings: 12).build(),
27 ),
28 stone,
29 name: 'ball',
30 );
31 return Scene()
32 ..add(ball)
33 ..add(
34 LightNode(name: 'sun', intensity: 3.0)
35 ..setLocalForward(Vector3(-0.4, -1.0, -0.3)),
36 );
37 }
39 String _report(GraphicsDevice device) =>
40 'preferred sample count: ${device.preferredSampleCount}\n'
41 'offscreen MSAA: ${device.supportsOffscreenMsaa}\n'
42 'wireframe: ${device.supportsWireframe}\n'
43 'stencil: ${device.supportsStencil}\n'
44 'mip maps: ${device.supportsMipmaps}';
46 @override
47 Widget? customBody(
48 BuildContext buildContext,
49 DemoContext context,
50 ) => Container(
51 color: const Color(0xFF14161A),
52 padding: const EdgeInsets.all(24),
53 alignment: Alignment.topLeft,
54 child: DefaultTextStyle(
55 style: const TextStyle(color: Color(0xFFE8E8EC), fontSize: 16),
56 child: Text(
57 'This build asked flutter3d_hardware\'s registry for a backend and '
58 'got the software rasteriser: no driver, no shading language, no '
59 'command buffer, so a backend agreeing with the hardware ones proves '
60 'something.\n\n${_report(context.device)}',
61 ),
62 ),
63 );
65 void _checkNoMultisampling() {
66 if (_device.preferredSampleCount != 1 || _device.supportsOffscreenMsaa) {
67 throw StateError(
68 'the software rasteriser answering anything but "no multisampling" '
69 'would be a silent difference from the picture a hardware backend '
70 'draws',
71 );
72 }
73 }
75 @override
76 void verify(Scene scene, FrameResult frame) {
77 if (frame.drawCalls < 1) {
78 throw StateError('the ball was not drawn');
79 }
80 _checkNoMultisampling();
81 }