GLSurfaceView.queueEvent不在GL线程中执行 [英] GLSurfaceView.queueEvent does not execute in the GL thread

查看:215
本文介绍了GLSurfaceView.queueEvent不在GL线程中执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的主要活动中为我的GLSurfaceView执行一些OpenGL命令.据我所知,由于OpenGL渲染器在其自己的线程中工作,因此我必须使用queueEvent.

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.

我在我的GLSurfaceView中使用以下代码调用queueEvent:

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();
}});

doSomething()方法绑定纹理并编译着色器.

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

这不起作用. glCreateProgram返回0,例如,当在GL线程之外执行GL命令时,就会发生0.如果从渲染器中执行相同的代码,也可以正常工作.因此,看来我使用queueEvent执行的命令不是在GL上下文中执行的,而是在错误的线程中执行的.

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.

我是否理解调用queueEvent足以在GL线程内执行代码?我还有什么需要做的,或者我现在怎么称呼它是错误的?

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?

推荐答案

它做了一些实验,似乎在某些情况下,虽然仍然在GL线程上,但queueEvent会在onSurfaceCreated实际被调用之前执行Runnable. 如果您在Activity中的onResume之后立即使用queueEvent,则会发生这种情况.

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.

我使用glClearColor进行了实验,即使它无任何例外地调用了命令,背景也没有改变.也许GLContext仍然无法正确使用,并且命令什么也不做.

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.

希望这会有所帮助!

这篇关于GLSurfaceView.queueEvent不在GL线程中执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆