在我的GLSurfaceView
中渲染任何内容之前,我必须运行大量的初始化。
这些必须在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);
/* [...] */
}