android opengl游戏的线程纹理加载过程 [英] Threading textures load process for android opengl game

查看:23
本文介绍了android opengl游戏的线程纹理加载过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大量 JPG 格式的纹理.而且我需要在实际绘图开始之前将它们预加载到 opengl 内存中.我问了一个问题,有人告诉我这样做的方法是将 JPEG 解包与 glTexImage2D(...) 调用分离到另一个线程.问题是我不太确定该怎么做.

I have a large amount of textures in JPG format. And I need to preload them in opengl memory before the actual drawing starts. I've asked a question and I've been told that the way to do this is to separate JPEG unpacking from glTexImage2D(...) calls to another thread. The problem is I'm not quite sure how to do this.

执行 glTexImage2D 所需的 OpenGL(处理程序?)仅在 GLSurfaceView.Renderer 的 onSurfaceCreated 和 OnDrawFrame 方法中可用.

OpenGL (handler?), needed to execute glTexImage2D is only available in GLSurfaceView.Renderer's onSurfaceCreated and OnDrawFrame methods.

我无法解压缩所有纹理,然后在 onSurfaceCreated(...) 中将它们加载到 opnegl 中,因为它们可能不适合有限的虚拟机内存(20-40MB?)

I can't unpack all my textures and then in onSurfaceCreated(...) load them in opnegl, because they probably won't fit in limited vm's memory (20-40MB?)

这意味着我必须一个一个地解包并加载它们,但在这种情况下我无法获得 opengl 指针.

That means I have to unpack and load them one-by one, but in that case I can't get an opengl pointer.

谁能给我和opengl游戏纹理加载线程的例子?

Could someone, please, give me and example of threading of textures loading for opengl game?

这一定是一些典型的程序,我在任何地方都无法获得任何信息.

It must be some some typical procedure, and I can't get any info anywhere.

推荐答案

你的主线程只需要上传例程,它可以访问 OpenGL 并调用 glTexImage2D.另一个线程将图像从文件加载(并解码)到内存.当辅助线程加载下一张图片时,主线程将之前加载的图片上传到纹理中.所以你只需要两张图片的内存,一张是当前从文件中加载的,一张是当前上传到 GL 中的(这是之前加载的一张).当然你需要一点同步,以防止加载线程覆盖主线程当前发送给GL的内存,并防止主线程发送未完成的数据.

You just have your main thread with the uploading routine, that has access to OpenGL and calls glTexImage2D. The other thread loads (and decodes) the image from file to memory. While the secondary thread loads the next image, the main thread uploads the previously loaded image into the texture. So you only need memory for two images, the one currently loaded from file and the one currently uploaded into the GL (which is the one loaded previously). Of course you need a bit of synchronization, to prevent the loader thread from overwriting the memory, that the main thread currently sends to GL and to prevent the main thread from sending unfinished data.

这篇关于android opengl游戏的线程纹理加载过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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