How to force Unity to update/redraw whole scene

24 Views Asked by At

I am displaying a texture from an Android native camera and experiencing performance issues.

I recorded camera latency as follows:

Directly rendering with SurfaceTexture: ~80ms
In OpenGL, which introduces OES-to-FBO drawing: ~90ms
Unity rendering at 60fps (which is way faster than the camera recording fps): 100-150ms

It's not reasonable that Unity may have an extra latency of ~60ms.

In theory, the rendering process should be:

CameraHAL -> OES texture -> TextureView
CameraHAL -> OES texture -> draw to FBO (<10ms) -> GLView
CameraHAL -> OES texture -> draw to FBO (<10ms) -> Unity renders the last texture

For details, in my native Android plugin, I create an FBO (or 2 FBOs for double-buffering implementation) and draw from OES to FBO when onFrameAvailable() is triggered in a render thread. In the Unity Update() function, I create ExternalTexture(nativeFboTextureId) and set it to the shader.

So, the latency should only come from these processes:

Thread switch (from camera thread to drawingHandler thread)
OES to FBO conversion
Unity drawing frequency, which should be 16.67ms

Is there any internal latency in Unity? Does Unity redraw using the latest external texture?

How can I force Unity to redraw when the native frame is finished?

0

There are 0 best solutions below