我的Flutter应用程序需要显示3D模型并允许用户旋转它。我通过本地视图(ViewController和Activity)和用于渲染的C++代码来实现这一点,作为下一步,我尝试使用Texture小部件来删除本地视图并仅使用Flutter。我成功地通过FlutterTexture在iOS上显示了OpenGL渲染,但不知道如何在Android上实现。你能展示一些如何使用SurfaceTexture和将其连接到Texture小部件的示例吗?
在配置OpenGL栈时,eglCreateWindowSurface
应该接受一个SurfaceTexture参数。
我花了一些时间创建了一个示例项目和文章: https://github.com/mogol/opengl_texture_widget_example https://medium.com/@germansaprykin/opengl-with-texture-widget-f919743d25d9
private void initGL() {
egl = (EGL10) EGLContext.getEGL();
eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
int[] version = new int[2];
egl.eglInitialize(eglDisplay, version);
EGLConfig eglConfig = chooseEglConfig();
eglContext = createContext(egl, eglDisplay, eglConfig);
eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfig, texture, null);
egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
}