createTexture method
Implementation
Future<FlutterAngleTexture> createTexture(AngleOptions options) async {
final height = (options.height * options.dpr).toInt();
final width = (options.width * options.dpr).toInt();
late final dynamic result;
result = await _channel.invokeMethod(_useAngle?'createTextureAngle':'createTexture', {
"width": width,
"height": height,
"useSurfaceProducer": options.useSurfaceProducer
});
if (Platform.isAndroid) {
_useSurface = true;
final newTexture = FlutterAngleTexture.fromSurface(
this,
result['textureId']! as int,
Pointer.fromAddress(result['surface'] as int? ?? 0),
options
);
_rawOpenGl.glViewport(0, 0, width, height);
if (!options.customRenderer) {
_worker = RenderWorker(newTexture);
}
return newTexture;
}
else if (_isApple) {
_useSurface = true;
// Create the EGL surface from IOSurface before creating the texture object
Pointer<Void>? macIosSurface;
if (result.containsKey('surfacePointer')) {
final surfacePointer = result['surfacePointer'] as int;
if (surfacePointer != 0) {
final ioSurfacePtr = Pointer<Void>.fromAddress(surfacePointer);
macIosSurface = _createEGLSurfaceFromIOSurface(ioSurfacePtr, width, height);
if (macIosSurface == null) {
angleConsole.error("Failed to create EGL surface from IOSurface");
} else {
angleConsole.info("Successfully created EGL surface from IOSurface");
}
}
}
final newTexture = FlutterAngleTexture.fromSurface(
this,
result['textureId']! as int,
macIosSurface, // We'll use an IOSurface instead
options
);
_rawOpenGl.glViewport(0, 0, width, height);
if (!options.customRenderer) {
_worker = RenderWorker(newTexture);
}
return newTexture;
}
else if (Platform.isWindows && options.useSurfaceProducer) {
_useSurface = true;
// Create the EGL surface from D3DSurface before creating the texture object
Pointer<Void>? d3dSurface;
if (result.containsKey('surfacePointer')) {
final surfacePointer = result['surfacePointer'] as int;
if (surfacePointer != 0) {
final d3dSurfacePtr = Pointer<Void>.fromAddress(surfacePointer);
d3dSurface = _createEGLSurfaceFromD3DSurface(d3dSurfacePtr, width, height);
if (d3dSurface == null) {
angleConsole.info("Failed to create EGL surface from D3DSurface");
} else {
angleConsole.info("Successfully created EGL surface from D3DSurface");
}
}
}
final newTexture = FlutterAngleTexture.fromSurface(
this,
result['textureId']! as int,
d3dSurface, // We'll use an D3DSurface instead
options
);
_rawOpenGl.glViewport(0, 0, width, height);
if (!options.customRenderer) {
_worker = RenderWorker(newTexture);
}
return newTexture;
}
else{
Pointer<Uint32> fbo = calloc();
_rawOpenGl.glGenFramebuffers(1, fbo);
_rawOpenGl.glBindFramebuffer(GL_FRAMEBUFFER, fbo.value);
final int rbo = (result['openglTexture'] as int?) ?? (result['rbo'] as int?) ?? 0;
if(result['openglTexture'] != null){
_isRBO = false;
}
final value = _createFBOTexture(rbo, width, height);
final newTexture = FlutterAngleTexture(
this,
result['textureId']! as int,
rbo,
fbo.value,
value,
options
);
angleConsole.info(newTexture.toMap());
_rawOpenGl.glViewport(0, 0, width, height);
if (!options.customRenderer) {
_worker = RenderWorker(newTexture);
}
_activeFramebuffer = fbo.value;
calloc.free(fbo);
_rawOpenGl.glBindFramebuffer(GL_FRAMEBUFFER, 0);
return newTexture;
}
}