fromBytes static method
- ByteData bytes
Loads a ShaderLibrary directly from a shader bundle's bytes (the
contents of a .shaderbundle compiled by impellerc), rather than from a
bundled asset. This suits shader bundles produced or fetched at runtime,
which have no entry in the asset manifest that fromAsset resolves.
Async to match fromAsset and keep one entry point across platforms; on
native the Future still completes in the same turn. Throws through the
Future if bytes is not a parseable shader bundle.
Unlike fromAsset, the result is not cached (the bytes carry no stable key), so the asset-path hot reload does not apply. The caller owns the returned library and can refresh it in place with reinitializeFromBytes (for example after recompiling the source).
Implementation
static Future<ShaderLibrary?> fromBytes(ByteData bytes) async {
final lib = ShaderLibrary._();
final error = lib._initializeWithBytes(bytes);
if (error != null) {
throw Exception("Failed to initialize ShaderLibrary: ${error}");
}
assert(() {
_ensureHooksRegistered();
return true;
}());
return lib;
}