readShaderUniformsFromAsset function
Reads a shader asset and returns all uniform declarations.
Uses UTF-8 decoding with malformed fallback to handle compiled payloads.
Implementation
Future<ShaderUniformBindings> readShaderUniformsFromAsset(
String filePath) async {
try {
final byteData = await rootBundle.load(filePath);
final bytes = byteData.buffer
.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes);
String shaderSource;
try {
shaderSource = utf8.decode(bytes);
} on FormatException {
// Some Android shader assets are not strict UTF-8, but still contain
// enough text/JSON metadata for uniform extraction.
shaderSource = const Utf8Decoder(allowMalformed: true).convert(bytes);
}
return parseShaderUniforms(shaderSource);
} on PlatformException catch (e) {
debugPrint('readShaderUniformsFromAsset.error: $e');
rethrow;
} on FormatException {
rethrow;
}
}