- Home /
Reading Native Surface Texture into Streaming Unity Texture [Android]?
I am trying to retrieve the camera preview image on Android and show it on a plane in Unity. In my native code I created the following function:
SurfaceTexture surfaceTex;
public void setUpVideoTexture(int texturePtr){
surfaceTex = new SurfaceTexture(texturePtr);
surfaceTex.setOnFrameAvailableListener(this);
Camera cam = Camera.open();//Alternatively I call this function on startup
try {
cam.setPreviewTexture(surfaceTex);
cam.setPreviewCallback(this);
cam.startPreview();
Log.d("Unity","Preview texture set up");
} catch (IOException e) {
e.printStackTrace();
}
}
In Unity I call this function and pass the native texture pointer of the Unity texture:
jo.Call("setUpVideoTexture", (int)renderer.material.mainTexture.GetNativeTexturePtr());
So now the camera preview image should be written into the Unity texture on every update.
However, on updating the surface texture, I get the error message "Error binding external texture image". I also tried using a RenderTexture but although I don't get an error the texture stays black. Why doesn't this work? Is it not possible to use the streaming texture in combination with a native surface texture?
Sorry for bumping this old thread. I am having the same issue. Were you able to solve this by any chance?
I'm attempting something similar, have you had any luck? I'm having a similar issue, in that it appears the texture is never properly assigned within the plugin.
Answer by MrPhysics · Jul 28, 2016 at 01:25 PM
Anybody have an idea?
This is not as simple. You have to go through a layer of C++ and write OpenGL code. See here:
https://docs.unity3d.com/$$anonymous$$anual/NativePluginInterface.html
Thanks, i already know that but some people seem to solved this case without help of C++.
Your answer
Follow this Question
Related Questions
DllNotFound when unmanaged c++ plugin library links to another unmanaged c++ library 1 Answer
pass texture2d or image to native android 0 Answers
EntryPointNotFound exception when integrating Picovoice Porcupine 0 Answers
How do you determine the Android Architecture during runtime? 1 Answer
Exception: Unkown CPU architecture for Android static library as Plugin 2 Answers