I am working on a level editor for a graphics engine. Recently, as one project expanded I have been ex开发者_JAVA技巧periencing 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.
You basically have two options
- Switch to a tile-based approach. If you're using tiles, that means you can re-use the same texture over and over which saves a lot of memory.
- Switch to on-demand as you described.
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
- It doesn't necessarily have to be slow, as long as your "active" regions are big enough so that you don't thrash the disk by loading too often you should be fine.
- Measure measure measure, you probably have to get a better grip on what your memory budget is, and design your levels around that rather than designing until you hit a wall. :-)
- Maintain separate content managers, remember that you can't unload an individual piece of content loaded through contentmanager, so keep a list of managers that you can swap out as you move around.
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!
精彩评论