我有過很多初始化的運行阻塞UI線程上運行glThread長期的任務之前,我可以在我的GLSurfaceView
沒有在Android
論文渲染任何必須在OpenGL的線程上完成的。
然而這掛起了我的主線程初始化的持續時間。
這裏是我的代碼:
@Override
protected void onStart() {
super.onStart();
FrameLayout renderingLayout = (FrameLayout) findViewById(R.id.movie_rendering_layout);
if (renderingLayout != null && mGLView == null) {
mGLView = new MyGLSurfaceView(getApplicationContext());
/** [..] **/
renderingLayout.addView(mGLView, params);
}
}
/*--------------- OPENGL RELATED ---------------*/
protected class MyGLSurfaceView extends GLSurfaceView {
private final MyGLRenderer mRenderer;
public MyGLSurfaceView(Context context) {
super(context);
// Create an OpenGL ES 1.0 context
setEGLContextClientVersion(1);
mRenderer = new MyGLRenderer();
// Set the Renderer for drawing on the GLSurfaceView
setRenderer(mRenderer);
}
}
protected class MyGLRenderer implements GLSurfaceView.Renderer {
private int mWidth, mHeight = 0;
private boolean isFinished = false;
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
// Set the background frame color
GLES10.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
init(mMovieIndex, AssetsUtils.getBinPath(getApplicationContext())); // <----- THIS takes long time
}
public void onDrawFrame(GL10 pGL10) {
GLES10.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
GLES10.glClear(GLES10.GL_COLOR_BUFFER_BIT);
/* [...] */
}