Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GLSurfaceView.queueEvent does not execute in the GL thread

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?

like image 655
Mad Scientist Avatar asked Sep 16 '13 11:09

Mad Scientist


1 Answers

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!

like image 108
Momchil Atanasov Avatar answered Oct 01 '22 20:10

Momchil Atanasov