抑制 OpenGL ES (iPhone) 纹理/OpenAL 声音内存占用的最佳方法?
我应该怎么办? 我有一些 512x512 png。我将它们压缩为 PVR(这导致质量很差),并且我准备使用 pngcrush 工具压缩 PNG。 PVR 的文件大小比 PNG 大约大 2 倍,也许我可以尝试使用 JPG 文件。
图像是否以压缩状态存储在内存中?或者压缩仅在加载过程中计算?或者图像/纹理在内存中未压缩映射?
同样的问题也适用于声音。我尝试了不同的格式,如 wav、mp3、aac、aiff (caf),但附加 soundManager 似乎会占用相同大小的内存。
有没有办法减少实际的内存消耗,或者压缩只是为了加速纹理/声音加载?
请告诉我。
What should i do?
I have some 512x512 png. I compressed them to PVR (which results terrible quality), and I'm preparing to compress the PNGs with pngcrush tool. The PVRs have about 2x-x larger filesize than the PNGs, maybe I can experiment with JPG files.
Are the images stored in a compressed state in memory? Or compression counts only at loading process? Or the images/textures are mapped uncompressed in memory?
The same queston goes to sounds. I tried different formats, like wav, mp3, aac, aiff (caf), but it seems that attaching the soundManager eats the same size of memory.
Is there a way to reduce the actual memory consumption, or compressions are only for speed up texture/sound loading?
Please shed me a light.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的 RAM 中将始终保留完整的数据。对于纹理,我无法向您推荐任何内容,但对于声音,您可以使用单声道文件。这将使所需大小减少 50%。您还可以尝试声音文件的比特率。
You will always have the complete data in your RAM. For textures I can't recommend you anything, but for sound you could use mono files. This would reduce the needed size by 50%. You can also experiment with the bit-rate of your sound files.
压缩纹理使用较少的 RAM,因为它们压缩存储在 VRAM 中,并且以压缩形式操作。
因此,通过压缩纹理,您可以在上传和 VRAM 存储方面受益。
Compressed textures use less RAM since they are stored compressed in VRAM, and they are operated in compressed form.
So with compressed textures, you get benefits at uploading and VRAM store.
关于声音,您可以尝试缓冲它们 - 这意味着在需要时从文件中读取,然后在播放后丢弃数据。
请注意,如果您的声音很小(例如爆炸声),并且实际上可能会造成更大的危害(因为它每次播放时都必须读取文件),那么这并不是很有用 - 当然,这取决于播放的频率。
这种技术的用处是音乐之类的东西。在 OpenAL 中,您可以使用以下方法缓冲小音频片段:
还有一些函数可以检查排队和已处理的缓冲区的数量:
一旦获得已处理的缓冲区的数量,您可以简单地取消排队(然后删除)已完成的缓冲区:
...最后,删除缓冲区(假设它们未使用):
有关详细信息,您可以参阅 OpenAL 程序员指南(PDF 警告):http://connect.creativelabs.com/openal/Documentation/OpenAL_Programmers_Guide.pdf
Regarding sounds, what you could try is buffering them - that means reading from the files as they are needed, and then discarding the data once it's been played.
Note that this isn't really useful if your sounds are small (say, explosions) and may actually do more harm than not (because it has to read the file every time it plays) - it depends how often it's played, of course.
Where this technique comes to use is things like music; in OpenAL, you can buffer small audio segments by using:
There also exist functions to check the number of queued and already processed buffers:
Once you have the number of processed buffers, you can simply unqueue (and then remove) the ones that are done:
...and finally, remove the buffers (provided that they are unused):
For more info, you can see the OpenAL Programmers Guide (PDF warning): http://connect.creativelabs.com/openal/Documentation/OpenAL_Programmers_Guide.pdf
有件事没说出口。
对于声音文件,减少大小(RAM 和应用程序大小)的一个好方法是使用 caf 格式。
使用如下方式转换您的文件:
Something left unsaid.
For sound files a great way to reduce size (both in ram and app size) is to use the caf format.
Convert your files using something like this: