GLSurfaceView.queueEvent does not execute in the GL thread

*爱你&永不变心* 提交于 2020-01-01 12:16:11

问题


I'm trying to execute some OpenGL commands for my GLSurfaceView from my main activity. As the OpenGL renderer works in its own thread, I have to use queueEvent, as far as I understand.

I'm calling queueEvent with the following code in my GLSurfaceView:

queueEvent(new Runnable(){
     @Override
     public void run() {
          renderer.doSomething(data); //executes some OpenGL commands
          requestRender();
}});

The doSomething() method binds a texture and compiles shaders.

This does not work. glCreateProgram returns 0, which happens for example when a GL command is executed outside of the GL thread. Exactly the same code also works fine if I execute it from within my renderer. So it seems that the commands I execute using queueEvent are not executed within the GL context, but are executed in the wrong thread.

Is my understanding that calling queueEvent is sufficient to execute code inside the GL thread wrong? Is there anything else I have to do, or any mistake in how I call it now?


回答1:


It did some experimenting and it seems that in some cases queueEvent will execute the Runnable before onSurfaceCreated is actually called, though still on the GL thread. This can happen if you are using queueEvent immediately after onResume in the Activity.

I did the experiment with glClearColor and even though it called the command without any exceptions, the background had not changed. Maybe the GLContext is still not properly available and the commands do nothing.

Hope this helps!



来源:https://stackoverflow.com/questions/18827048/glsurfaceview-queueevent-does-not-execute-in-the-gl-thread

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