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

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

问题描述

我有大量的JPG格式的纹理。 我需要$ P $实际的绘图开始前PLOAD他们在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.

OpenGL的(处理),执行glTexImage2D需要的是只适用于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。另一个线程负载(与去codeS)将图像从文件到内存中。而二级线程加载下一个图像,主线程上传previously加载图像到纹理。所以,你只需要记忆的两幅图像,目前上传到GL(这是一个被载入previously)从当前文件中加载的一年之一。当然,你需要一个位同步,以prevent从覆盖内存加载程序的线程,主线程当前发送到GL和prevent主线程发送未完成的数据。

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天全站免登陆