start method
Makes the GPU device (or, without one, a null device), the renderer and the models; registers the model loader with the asset manager; adds a Graphics3DSceneRenderer to the engine's frame and an Animation3DSystem to its world.
Implementation
@override
Future<void> start(ServiceContext context) async {
final engine = _engine = context.engine;
String? reason;
var renderer = await Renderer3D.tryCreate(
device: _device,
onUnsupported: (r) => reason = r,
);
if (renderer == null) {
final why = _unsupportedReason = reason ?? 'There is no GPU device.';
debugPrint('just_game_engine: 3D is off. $why');
// Draws nothing, but scenes and models still load. It keeps no log
// (a whole session would grow it), and decodes no texture nothing
// will draw.
renderer = await Renderer3D.create(
NullGpuDevice(shaders: rendererNullShaders, record: false),
);
renderer.uploader.decodeTextures = false;
onUnsupported?.call(why);
}
_renderer = renderer..uploader.keepEdges = keepEdges;
final models = _models = Graphics3DModels(
engine.assets.bundle,
renderer.uploader,
);
engine.assets.registerLoader(
AssetType.model,
_loader = Graphics3DModelLoader(models),
);
context.context.graphics3DModels = models;
models.reloadListeners.add(_modelReloaded);
final scene = _scene = Graphics3DSceneRenderer(
world: () => engine.world,
renderer: renderer,
models: models,
unsupportedReason: _unsupportedReason,
frame: () => engine.rendering.drawingFrame,
)..renderScale = renderScale;
engine.rendering.addSceneRenderer(scene);
engine.world.addSystem(_animations = Animation3DSystem(models));
}