gpuTextureFromImage function
Implementation
Future<gpu.Texture> gpuTextureFromImage(ui.Image image) async {
final byteData = await image.toByteData(format: ui.ImageByteFormat.rawRgba);
if (byteData == null) {
throw Exception('Failed to get RGBA data from image.');
}
// Upload the RGBA image to a Flutter GPU texture.
final texture = gpu.gpuContext
.createTexture(gpu.StorageMode.hostVisible, image.width, image.height);
if (texture == null) {
throw Exception('Failed to create Flutter GPU texture.');
}
if (!texture.overwrite(byteData)) {
throw Exception('Failed to overwrite Flutter GPU texture data.');
}
return texture;
}