Low performance when execute eglSwapBuffer and eglMakeCurrent

余生颓废 提交于 2019-12-03 12:44:53

问题


I'm developing an Android Unity Plugin that allows 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

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!


回答1:


A lot of OpenGL calls are assync, and some calls may cause the OpenGL wait the queued operations to execute. So the times you are seen are because of the other calls that execute before the actual call you are doing.



来源:https://stackoverflow.com/questions/25518397/low-performance-when-execute-eglswapbuffer-and-eglmakecurrent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!