OpenGL 纹理是否应该动态加载和卸载
我正在使用 OpenGL 实现一个游戏引擎,想知道手动卸载在相机特定半径内未使用的纹理是否是一个好主意。有人向我建议,对于 Android 和 OpenGL ES,根据需要动态加载和卸载纹理可能是一个好主意,以节省内存。是否建议将其用于 OpenGL ES 和 OpenGL?我个人并不相信这种方法,但我很好奇这种方法何时会对桌面 PC 上的 OpenGL 设置和手机上的 OpenGL ES 带来好处(如果有的话)。
I am implementing a game engine using OpenGL and wonder if it's a good idea to manually unload textures that are not used within a certain radius of the camera. It has been suggested to me for Android and OpenGL ES that it might be a good idea to load and unload textures on the fly as needed to save memory. Is this recommended for OpenGL ES and OpenGL? I am personally not convinced by the approach but I am curious as to when this will have benefits, if any, in the setting of OpenGL on a desktop PC and with OpenGL ES on a mobile phone.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这取决于您在游戏中使用的纹理数量/纹理大小。
我相信神奇的数字是至少 10MB 的纹理内存,所以如果你的纹理使用的内存超过这个数字,人们倾向于使用纹理压缩(这里的手机兼容性问题,一些压缩格式是专有的,有一个关于这个的完整主题)。您可以在不使用纹理时卸载它们,但重新加载它们时会产生很大的成本,因此请注意这一点。
一般来说,您不需要诉诸此方法。
It will depend on how many textures/the size of the textures you use in your game.
I believe the magic number is minimum 10MB of texture memory, so if your textures use more than that people tend to use texture compression (phone compatibility issues here, some compression formats are proprietary, there's a whole topic on this). You could unload textures when they aren't being used but there will be a heavy cost when you reload them, so be aware of that.
Generally speaking, you shouldn't need to resort to this method though.
如果你不需要那个记忆,那么呆在那里也没什么坏处。如果您确实需要这些记忆,那么您已经知道您需要这样做。所以答案是……如果你需要就去做。
If you don't need that memory, then it does no harm being there. And if you do need that memory, then you already know that you need to do it. So the answer is... do it if you need to.