XNA 内存中加载了太多纹理
我正在开发图形引擎的关卡编辑器。最近,随着一个项目的扩展,我遇到了内存问题。特别是,关卡相当大,需要加载大约 300 个不同大小的纹理。一些纹理非常大,例如 2048x2048,其他纹理较小,例如 256x256 或 512x512。不管怎样,编辑器在这个关卡消耗了 1.3GB 内存,并且一些纹理无法加载,因为它会抛出内存不足的异常。那么我这里有什么解决方案呢?
目前我能想到的唯一解决方案是将关卡分成更小的部分,并根据可见区域按需加载纹理。但我相信这会在场景中导航时大大降低性能。有什么想法吗?对于关卡编辑来说,在这个问题上应该有一些标准方法。
I am working on a level editor for a graphics engine. Recently, as one project expanded I have been experiencing memory issues. In particular, the level is quite big and around 300 textures of varying size need to be loaded. A few textures are quite big like 2048x2048, others are smaller like 256x256 or 512x512. Anyway, the editor consumes 1.3gb of memory for this level and some textures can't be loaded as it throws out of memory exceptions. So what solutions do I have here?
Right now the only solution I can think of is to divide the level into smaller parts and load the textures on demand, depending on the visible area. But I believe this would slow down the performance big time when navigating in the scene. Any thoughts? There should be some standard approach for level editors on that matter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用不同质量的纹理可能是一个好主意,如果您距离很远,请使用 64x64 纹理,那么当您靠近时,请继续将其交换为 128x128、256x256、512x512 等...还要重新考虑使用以下纹理2056x2056,因为最好有 4 个 1024x1024 纹理:)。
(注意:生成 mip-map 可以部分执行此操作,但不会释放计算机上的内存)
编辑:还可以尝试打开 DXT5 纹理压缩,这可能会节省大量内存!
It might be a good idea to use with different quality of textures, if you're far away use the 64x64 texture, then when you get closer keep swaping it out to 128x128, 256x256, 512x512, etc... Also reconsider using textures of 2056x2056, since its better to have 4 1024x1024 textures :).
(note: generating mip-maps partially does this, but doesn't free memory on your computer)
Edit: also try to turn on DXT5 texture compression, that might save a lot of memory!
您基本上有两个选择
我认为,如果您的艺术方向与基于图块的方法并不真正相符,那么您将需要开始考虑方法#2。需要考虑的一些事情
You basically have two options
I'm thinking that if your art direction doesn't really mesh with the tile-based approach, so you will want to start thinking about approach #2. A few things to think about