问题描述
我已经编写了一个Android库,该库对实时供稿相机图像执行计算机视觉任务。现在,我想将实时供稿摄像机图像传递给Unity应用程序(该应用程序仅将android代码用作库)。
这是我走了多远:
在Android中,我可以将相机渲染为opengl纹理并进行渲染:
- 使用android的
SurfaceTexture
将android camera2预览为opengl纹理 - 通过opengl代码渲染此纹理
我可以统一地从java更改opengl纹理:
- 统一渲染线程:统一c#调用jni,jni调用java传递opengl纹理 (使用'GL.IssuePluginEvent';渲染必须在unity的渲染线程上完成!)
- 渲染为opengl纹理
- 统一显示opengl纹理
自然地将那些步骤组合在一起是解决方案。但是,以下设置中断:
- 统一渲染线程:unity c#调用jni,jni调用java
- 使用“ SurfaceTexture”将Android的camera2渲染为opengl纹理
- 使用unity渲染opengl纹理
到目前为止,我的理解是,这可能来自Android SurfaceTexture
的限制。
来自文档:"The texture object uses the GL_TEXTURE_EXTERNAL_OES texture target,which is defined by the GL_OES_EGL_image_external OpenGL ES extension. This limits how the texture may be used. Each time the texture is bound it must be bound to the GL_TEXTURE_EXTERNAL_OES target rather than the GL_TEXTURE_2D target. Additionally,any OpenGL ES 2.0 shader that samples from the texture must declare its use of this extension using,for example,an "#extension GL_OES_EGL_image_external : require" directive. Such shaders must also access the texture using the samplerExternalOES GLSL sampler type. "
似乎统一渲染代码在从SurfaceTexture渲染opengl纹理时中断了。
有人有类似的问题吗?
PS:当然,我在opengl模式下使用unity,而不是vulkan模式
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)