Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone!
I'm developing an Unity Android Plugin that allow user to record his/her gameplay
Overview of my solution:
- Using OpenGl FrameBufferObject (FBO) to make Unity render offscreen to this FBO
- Get the offscreen texture of this FBO then using for 2 purposes:
+ Render to video surface
+ Redraw to device screen
- Execute flow per frame:
+ bind my FBO
+ render scene to FBO (Unity code)
+ unbind my FBO
+ set up video surface
* configure surface size (execute first time only)
* save egl state
* make video surface current
+ draw to video surface using offscreen texture of my FBO
+ restore to default surface
* set presentation time to video frame
* swap buffer from video surface to default window
* restore egl state
* make default surface current
+ notify encoder thread that data is ready to write
My issue is performance while recording is not good. FPS downs from 60 to 40 on Samsung Galaxy S4. I tried to record execute time of render operations and recognize that the most affect performance operations are make video surface current operation and swap buffer from video surface to default window operation. Below is their code

Java
public void makeCurrent()
{
 if (!EGL14.eglMakeCurrent(this.mEGLDisplay, this.mEGLSurface, this.mEGLSurface, this.mEGLContext))
  throw new RuntimeException("eglMakeCurrent failed");
}

public boolean swapBuffers()
{
 return EGL14.eglSwapBuffers(this.mEGLDisplay, this.mEGLSurface);
}


Execute time of make current operation is 1 ~ 18 ms
Execute time of swap buffers operation is 4 ~ 14 ms
Execute time of other operations is usually 0 ~ 1 ms
How to improve performance of these operations?
Any help will be greatly appreciated!
Posted
Updated 3-Sep-14 0:38am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900