createTexture static method
Implementation
static Future<FlutterAngleTexture> createTexture(AngleOptions options) async {
final textureTarget = GL_TEXTURE_2D;
final height = (options.height*options.dpr).toInt();
final width = (options.width*options.dpr).toInt();
final result = await _channel.invokeMethod('createTexture', {"width": width, "height": height,});
if (Platform.isAndroid) {
final newTexture = FlutterAngleTexture.fromMap(result, null, 0, options);
_rawOpenGl.glViewport(0, 0, width, height);
if(!options.customRenderer){
worker = RenderWorker(newTexture);
}
return newTexture;
}
Pointer<Uint32> fbo = calloc();
_rawOpenGl.glGenFramebuffers(1, fbo);
_rawOpenGl.glBindFramebuffer(GL_FRAMEBUFFER, fbo.value);
final newTexture = FlutterAngleTexture.fromMap(result, null, fbo.value, options);
angleConsole.info(newTexture.toMap());
angleConsole.info(_rawOpenGl.glGetError());
_rawOpenGl.glActiveTexture(WebGL.TEXTURE0);
if (newTexture.metalAsGLTextureId != 0) {
// Draw to metal interop texture directly
_rawOpenGl.glBindTexture(textureTarget, newTexture.metalAsGLTextureId);
_rawOpenGl.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureTarget, newTexture.metalAsGLTextureId, 0);
}
else {
_rawOpenGl.glBindRenderbuffer(GL_RENDERBUFFER, newTexture.rboId);
_rawOpenGl.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, newTexture.rboId);
}
var frameBufferCheck = _rawOpenGl.glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (frameBufferCheck != GL_FRAMEBUFFER_COMPLETE) {
angleConsole.error("Framebuffer (color) check failed: $frameBufferCheck");
}
_rawOpenGl.glViewport(0, 0, width, height);
Pointer<Int32> depthBuffer = calloc();
_rawOpenGl.glGenRenderbuffers(1, depthBuffer.cast());
_rawOpenGl.glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer.value);
_rawOpenGl.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);//,GL_DEPTH_COMPONENT16//GL_DEPTH24_STENCIL8
_rawOpenGl.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer.value);
frameBufferCheck = _rawOpenGl.glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (frameBufferCheck != GL_FRAMEBUFFER_COMPLETE) {
angleConsole.error("Framebuffer (depth) check failed: $frameBufferCheck");
}
_activeFramebuffer = fbo.value;
calloc.free(depthBuffer);
calloc.free(fbo);
if(!options.customRenderer){
worker = RenderWorker(newTexture);
}
return newTexture;
}