在 Android 上的单独线程上获取 GL10 实例

发布于 2024-10-12 04:58:02 字数 387 浏览 2 评论 0原文

我正在制作一个游戏,并且创建了一个单独的线程来加载资源、3d 模型等。这样 UI 线程在加载时就不会锁定。但是,加载线程需要 GL10 实例才能正确加载和映射纹理。

以下是问题的概述,以便您可以更好地理解我的困境:
1. 我的 Renderer 类创建并启动“加载”线程。
2.加载线程从资源中加载模型和纹理
3. 需要“glGenTextures”来加载纹理,但是加载线程没有 GL10 的实例

我尝试只为加载线程提供以下给出的 GL10 实例Renderers onSurfaceCreated 方法,但它不起作用。(我猜它会被删除,或者搞乱,或者当函数结束时发生什么)

那么,我如何才能将 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.

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

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)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乙白 2024-10-19 04:58:02

答案是你不能。

在opengl android中,gl对象/上下文仅存在于渲染循环中。
据我所知,您不能在该线程之外使用 gl 函数。

原因很简单 opengl 是一个状态机,不是线程证明的
- 一个主要原因是,如果您添加测试,它会减慢渲染速度
- 作为一个状态机,当你想画一些东西并且同时改变像混合这样的状态时会发生什么
-...

您想要做的是完成线程中与 gl 无关的所有工作(打开位图读取点文件...)
在渲染循环中添加一个 if(与 gl 相关的事情要做){...}
当你的线程准备好时,更改标志以使渲染循环知道你想要加载一些东西

The answer is your can't.

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.

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
-...

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

顾北清歌寒 2024-10-19 04:58:02

这在 iOS 和 OSX 上是完全可行的,只要您同步对 GL 状态机的访问,就不会有理论上的问题,除非 Android 在其实现中设置了限制。我刚刚尝试上传纹理,但我不进行成像,但事情不起作用。就像我说的,这项技术在其他方面都表现良好......

This is quite do-able on iOS and OSX, and as long as you synchronize your access to the GL state machine, there are no theoretical problems unless Android has created limitations in it's implementation. I've just tried uploading a texture while I refrain from imaging and things don't work. Like I said, this technique works fine every else ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文