2
\$\begingroup\$

I writing my resource mangaer, and I consider about how it can work for graphics objects (like textures, meshes).
I think about this :
I want to load texture (in pseudocode):

Texture t = resMgr.GetTex("image.png");

and GetTex make something like this:

  1. load texture from disk to main memory
  2. create texture object (load it to gpu memory)
  3. unload texture from main memory

I consider about 3 step, does game engines that you know unload meshes/textures after load them into gpu memory ?

\$\endgroup\$

3 Answers 3

2
\$\begingroup\$

No, fetching them from the hard drive is very time-intensive. It is possible that you have so much texture/model/animation data that everything will not fit concurrently on the GPU, especially for someone using an older graphics card or laptop.

Main memory is probably the cheapest resource you have to work with on a modern computer. You should leave things like unloading textures from memory for when you are switching maps.

\$\endgroup\$
2
\$\begingroup\$

Loading and unloading resources at runtime is not practical. The only time you do that is when you are streaming resources.

A general idea to go on is to load rescouers that you need for a current map or segment. and when the player is past that to unload the rescoures. Never keep something you dont need, but keep what you need now or soon.

\$\endgroup\$
1
\$\begingroup\$

You should generally free your mesh and texture data after uploading into OpenGL textures or vertex buffers. The driver must keep a copy of your data in any case, so why waste memory by keeping another useless copy around?

Main memory may be cheap, but even so you shouldn't waste for no reason. Especially not on 32-bit architectures where you may bump into the 4GB per-process virtual address space limit sooner rather than later.

The best performing method to load mesh data, if using OpenGL, is to:

  1. Create vertex buffer object.
  2. Use glMapBuffer to get a pointer to driver memory.
  3. Load data directly into driver memory.
  4. glUnmapBuffer to tell the driver you've finished filling the buffer with data.

Less applicable on textures, since the driver may need to convert your data to an internal format.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .