Skip to main content
gamedev.net
🔒 Locked

saving memory on multiple graphics

Started by drb2k2 Mar 11, 2004 at 8:39 AM 3 replies 250+ views
Original Post
drb2k2
drb2k2
Hi all, I am working on a level designing program using directX and C++. At the moment I envisage it designing simple pac man type levels i.e. nothing too complicated. Anyhoo with a map like this are a lot of repeat models. At the moment I have only four buildings and am repeating them to create a simple environment. My question is "is there any way to cut down the amount of memory used by having multiple objects". You see each building is a custom class that has things like position, rotation and the .X file that represents its mesh. I was wondering if you could use pointers to other already loaded mesh''s in duplicate ones, but then though that this would alter the original. Is it best to make a vertexbuffer of the data and copy it into the clone. Any suggestions would be greatly appreciated. Cheers drb2k2
Enokh
Enokh
What you want is called a Resource Manager, basically whenever you want to load in a mesh (or sound, or texture, or whatnot) you call something like ResourceManager.LoadResource(newMesh); Then it searches through a database by the newMesh's location on the harddisk, and determines if this perticular mesh has been loaded into memory yet or not. If it hasn't, it loads it in and adds an entry to the HardDisk-Location-DB, if it HAS been loaded already then it re-directs newMesh to draw the mesh that has already been loaded.

That is easier to explain with say, OpenGL Textures. Each texture has it's own unique ID that OpenGL distributes, so if the texture is being loaded for the first time, you tell OpenGL to load the texture in and give it it's unique ID. If it HAS been loaded already you simply tell the texture you just recieved what is the texture ID of the texture that is already loaded. Then whenver you want to draw newTexture it actually automatically draws the first texture that was already loaded into memory, which is infact, eseentially the same texture as the one you just wanted to load in. Ta da.

[edited by - Enokh on March 11, 2004 10:23:55 AM]
drb2k2
drb2k2
Ok,
I see what you mean as regards to textures, but presumably all OpenGL is doing is supplying a pointer to the texture anyway. This is probably fine for textures because OpenGL will modify it to fit onto the mesh. However each mesh has its own position and rotation values. So if I make a pointer to one mesh from a duplicate, any modification done on the duplicate will also happen on the new one. I think.
twanvl
twanvl
You shouldn''t store position and rotation in the mesh object. It would be more logical to have a "GameObject" or something, that stores a position, rotation and information on what mesh it uses.
drb2k2
drb2k2
wahey,
now i like that idea a lot
cheers

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.