Android GLSurfaceView ошибка eglcontext? - PullRequest
0 голосов
/ 13 декабря 2018
public class MainActivity extends AppCompatActivity {
private Button mBtn;
private RelativeLayout mContainer;
private MyGLSurfaceView mMyGLSurfaceView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mBtn = findViewById(R.id.btn);
    mContainer = findViewById(R.id.container);
    mBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(v.getContext(), "click",Toast.LENGTH_SHORT).show();
            initView();
        }
    });
}

private void initView() {
    if (mMyGLSurfaceView != null) {
        mContainer.removeView(mMyGLSurfaceView);
        mMyGLSurfaceView = null;
    }
    mMyGLSurfaceView = new MyGLSurfaceView(this);
    mMyGLSurfaceView.setEGLContextClientVersion(2);
    mMyGLSurfaceView.setRenderer(mMyGLSurfaceView);
    mMyGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 400);
    mMyGLSurfaceView.setLayoutParams(params);
    mContainer.addView(mMyGLSurfaceView);
}

}

public class MyGLSurfaceView extends GLSurfaceView implements GLSurfaceView.Renderer {
private static final String TAG = "hans";

public MyGLSurfaceView(Context context) {
    super(context);
}

public MyGLSurfaceView(Context context, AttributeSet attrs) {
    super(context, attrs);

}


@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    EGL10 egl = (EGL10) EGLContext.getEGL();
    EGLContext context = egl.eglGetCurrentContext();
    Log.i(TAG, "onSurfaceCreated:Current Thread = "+ Thread.currentThread() + "mEGLContext = " + context + " class " + this.toString() + " GL = " + context.getGL() + " instance = " + EGLContext.getEGL());
}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
}

@Override
public void onDrawFrame(GL10 gl) {
}

}

введите описание изображения здесь

при многократном нажатии кнопки.удалите последний GLSurfaceView и добавьте новый GLSurfaceView.почему я получаю тот же адрес EGLContext?я отлаживаю исходный код GLSurfaceView и не могу получить никакой полезной информации.

Кто-нибудь может мне помочь?спасибо!

...