入门Android上的单独的线程GL10实例 [英] Getting GL10 instance on separate thread on Android

查看:158
本文介绍了入门Android上的单独的线程GL10实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做一个游戏,我已经创建了装载资产,三维模型等一个单独的线程所以,虽然它的加载UI线程不会锁定。但是,线程加载需要GL10的实例,以加载和正确映射的纹理。

I'm making a game and I've created a separate thread for loading assets, 3d models, etc. So that the UI thread won't lock up while its loading. However, the thread for loading requires an instance of GL10 in order to load and map textures correctly.

继承人的问题的概述,这样你就可以更好地理解我的predicament:结果
1.我的渲染器类创建并启动了加载的线程。结果
2.装载线程加载模型和纹理的资产结果
3.glGenTextures'需要加载的纹理, 的装载线程没有GL10实例

Heres an overview of the problem so you can better understand my predicament:
1. my Renderer class creates and starts the "loading" thread.
2. The loading thread loads the models and textures from assets
3. 'glGenTextures' is required to load the textures, but the loading thread doesn't have an instance of GL10

我尝试只是让装载线程通过渲染onSurfaceCreated方法给出的GL10实例,但它不工作。(我猜可能被删除或搞砸了,或者说当函数结束)

I tried just giving the loading thread the GL10 instance given by the Renderers onSurfaceCreated method, but it doesn't work.(I guess it gets deleted, or messed up, or something when the function is over)

那么,如何将能够GL10的工作实例传递给我装的线程?

So, how would I be able to pass a working instance of GL10 to my loading thread?

推荐答案

答案是:你不能。

在OpenGL的机器人中,GL对象/背景只在渲染循环存在。
据我所知,你不能使用GL函数线程之外。

In opengl android, the gl object/context only exist in the rendering loop. To my knowledge you can't use the gl functions outside that thread.

原因很简单OpenGL是那个状态并没有证明线程的状态机
- 酮主要的原因是,如果你没有添加测试它会减慢渲染
-being状态机,当你想画的东西会发生什么,你在同一时间改变像混合的状态
-...

the reason is simple opengl is a state machine that isnot thread proof -one main reason is that it would slow down the rendering if you did add the test -being a state machine what happens when you want to draw something and you change a state like blend at the same time -...

您想要做的是尽一切非GL在你的线程相关的工作(打开位图读点文件...)
在渲染循环添加一个IF(GL东西相关是必须要做的){...}
当你的线程准备变革的标志,让你知道要加载的东西渲染循环

What you want to do is do all the work that is non gl related in your thread (open bitmaps read point files ...) in your rendering loop you add a if(something gl related is to be done){...} and when your thread is ready change the flag to let the rendering loop know you want to load something

这篇关于入门Android上的单独的线程GL10实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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