baseShaderLibrary top-level property Assets and loading

ShaderLibrary get baseShaderLibrary

The shader bundle shipped with flutter_scene.

Contains the vertex and fragment shaders used by the built-in geometries (UnskinnedVertex, SkinnedVertex) and materials (StandardFragment, UnlitFragment). Custom Geometry or Material subclasses can pull additional shaders from this library.

Reading a shader bundle from an asset is asynchronous on every backend, so the bundle must be loaded ahead of time by awaiting Scene.initializeStaticResources (which calls loadBaseShaderLibrary); accessing this getter before that completes throws.

Implementation

gpu.ShaderLibrary get baseShaderLibrary {
  final cached = _baseShaderLibrary;
  if (cached == null) {
    final cause = _baseShaderLibraryLoadError;
    throw Exception(
      cause == null
          ? 'The base shader bundle has not been loaded yet. Await '
                'Scene.initializeStaticResources() before constructing geometry '
                'or materials that touch the base shader library.'
          // Pointing at initializeStaticResources() would send the developer
          // back to the call that already ran and failed, so lead with why.
          : 'The base shader bundle failed to load, so anything that touches '
                'the base shader library throws. The load reported: $cause',
    );
  }
  return cached;
}