Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用GL_Texture_EXTERNAL_OES在Unity纹理上渲染Android相机预览_C#_Android_Unity3d_Opengl Es_Camera - Fatal编程技术网

C# 使用GL_Texture_EXTERNAL_OES在Unity纹理上渲染Android相机预览

C# 使用GL_Texture_EXTERNAL_OES在Unity纹理上渲染Android相机预览,c#,android,unity3d,opengl-es,camera,C#,Android,Unity3d,Opengl Es,Camera,我正在尝试在Unity纹理上渲染来自java android插件的相机预览。 Android插件在后台运行,因此没有视图或活动。在没有视图的情况下获取Cameradata的唯一方法是使用SurfaceTexture(请参阅) 由于性能方面的原因,我的计划是使用OpenGL将Android代码中的SurfaceTexture直接渲染到Unity纹理上。我没有得到任何编译/运行时错误,但是Unity内部的纹理保持为白色/黑色 这是我的密码: Android库(CameraFeed.java): pu

我正在尝试在Unity纹理上渲染来自java android插件的相机预览。 Android插件在后台运行,因此没有视图或活动。在没有视图的情况下获取Cameradata的唯一方法是使用
SurfaceTexture
(请参阅)

由于性能方面的原因,我的计划是使用OpenGL将Android代码中的
SurfaceTexture
直接渲染到Unity纹理上。我没有得到任何编译/运行时错误,但是Unity内部的纹理保持为白色/黑色

这是我的密码:

Android库(CameraFeed.java):

public class CameraFeed : MonoBehaviour {
private Texture2D nativeTexture;
private AndroidJavaObject javaCameraFeed;

void Start () {
    javaCameraFeed = new AndroidJavaObject("com.oberloestern.grabhuegel.arlibs3.CameraFeed");

    Int32 texPtr = javaCameraFeed.Call <Int32> ("getUnityTextureID");
    Debug.Log("texture pointer? " + texPtr);

    nativeTexture = Texture2D.CreateExternalTexture (128, 128, TextureFormat.RGBA32 , false, false, new System.IntPtr(texPtr));
}

void Update () {

}
void OnGUI() {
    // Draw the Texture from Android in the middle of the screen
    GUI.DrawTexture(new Rect(50, 50, Screen.width - 100, Screen.height - 100), nativeTexture);
}
}
公共类CameraFeed实现SurfaceTexture.OnFrameAvailableListener{
私人表面结构;
私人摄像机麦卡梅拉;
私人国际单位联合体;
公共摄影机提要(){
int纹理[]=新int[1];
//为GL纹理保留一个ID。。
GLES20.glGenTextures(1,纹理,0);
UNITYTEXTREID=纹理[0];
//将纹理绑定到外部纹理
GLES20.glBindTexture(Gles11Text.GL_TEXTURE_EXTERNAL_OES,unityTextureID);
//使用Unity纹理ID创建AndroidSurface纹理
mTexture=新表面结构(UnityTextReid);
//创建相机并打开它
mCamera=Camera.open();
mCamera.startPreview();
试一试{
//将Unity纹理绑定到摄影机帧
mCamera.setPreviewTexture(mTexture);
}捕获(IOE异常){
e、 printStackTrace();
}
//当frame就绪时,将调用此类的onFrameAvailable。。
mTexture.setOnFrameAvailableListener(此);
}
//将纹理的句柄提供给Unity脚本
public int getUnityTextReid(){
返回UnityTextReid;
}
@凌驾
框架上的公共空间可用(SurfaceTexture SurfaceTexture){
//新帧出现时更新。。
surfacettexture.updateMaximage();
}
}
Unity-C脚本(CameraFeed.cs):

public class CameraFeed : MonoBehaviour {
private Texture2D nativeTexture;
private AndroidJavaObject javaCameraFeed;

void Start () {
    javaCameraFeed = new AndroidJavaObject("com.oberloestern.grabhuegel.arlibs3.CameraFeed");

    Int32 texPtr = javaCameraFeed.Call <Int32> ("getUnityTextureID");
    Debug.Log("texture pointer? " + texPtr);

    nativeTexture = Texture2D.CreateExternalTexture (128, 128, TextureFormat.RGBA32 , false, false, new System.IntPtr(texPtr));
}

void Update () {

}
void OnGUI() {
    // Draw the Texture from Android in the middle of the screen
    GUI.DrawTexture(new Rect(50, 50, Screen.width - 100, Screen.height - 100), nativeTexture);
}
}
公共类CameraFeed:MonoBehavior{
私人织物2D本地织物;
私有AndroidJavaObject javaCameraFeed;
无效开始(){
javaCameraFeed=newandroidjavaobject(“com.oberloesten.grabhuegel.arlibs3.CameraFeed”);
Int32 texPtr=javaCameraFeed.Call(“getUnityTextReid”);
Log(“纹理指针?”+texPtr);
nativeTexture=Texture2D.CreateExternalTexture(128,128,TextureFormat.RGBA32,false,false,new System.IntPtr(texPtr));
}
无效更新(){
}
void OnGUI(){
//在屏幕中间从Android中绘制纹理
DrawTexture(新的矩形(50,50,Screen.width-100,Screen.height-100),nativeTexture);
}
}
我已经使用
GLES20.GL\u Texture\u 2D
向Unity发送了位图纹理,但是
SurfaceTexture
必须通过
GLES11Ext.GL\u Texture\u EXTERNAL\u OES
发送


有人知道如何让它工作吗?

我找到了类似的方法或其他方法。有人有类似的例子吗?或者有没有另一种perfomant方法将camerastream从android插件发送到unity?您是否设法解决了这个问题?如果是,请分享您的知识:)抱歉,根本找不到解决方案。我试图实现一个AR应用程序,最终使用了Vuforia和Wikitude。我也尝试过,但还没有解决它。解决方案必须存在,我在AR unity游戏中见过这种东西。类似的问题可能有助于: