Memory usage

Blitz3D Forums/Blitz3D Programming/Memory usage

cash(Posted 2004) [#1]
I have a 1Ghz , 1GB ram PC with 128Mb Graphicd card.
Running Win 2000

I have built several components for the level and have 10 animated entities.

3 lights, 1 camera and fog.

I have tried reducing colours etc in all textures, but the application still consumes 85Mb ram when running.

Reducing entities and graphics makes little difference.
Is this normal or am I overlooking something. I know its a bit difficult to guess.


MSW(Posted 2004) [#2]
have you tried?
Graphics3D 640,480,16


You can reduce the colors in the textures all you want...but even if you make your textures 8-bit color JPGs...when loading them in Blitz will automaticly convert them to 16 or 32-bit color depending on the color depth that was set with the last Graphics3D call...

another thing to try is to reduce the texture size...make those 1024 X 1024 textures into 256 X 256 ones, then load them in...also might want to consider turning off MIP-mapping for some textures...

Just as an example...lets say you have a 1024 X 1024 32-bit texture....that is 4MB on it's own...now you load that in as 32-bit color with mip-mapping enabled...blitz ends up constructing a 512 X 512, a 256 X 256, and a 128 X 128 versions of your texture for use with mip-mapping...so all combined that one texture would need about 5.4MB of video memory to store that one 32-bit texture....in 16-bit mode it's about half that.

Another thing to consider is the screen resolution...the higher it is the more memory is required...remember you arn't just setting the screen resolution with graphics3D, you are setting two buffers and a Z-buffer...effectively useing 3 times the amount of memory.

for example:

Graphics3D 640, 480, 16
the front buffer will need: 614400 bytes (exactly 600kb)
the backbuffer will need: 614400 bytes
the Z-buffer will need: 614400 bytes
combined total: approx 1.8MB

Graphics3D 1024, 768, 32
the front buffer will need: 3145728 bytes (exactly 3MB!)
the backbuffer will need: 3145728 bytes
the Z-buffer will need: 3145728 bytes
combined total: approx 9MB...or about 1/10th of the 85MB your game is useing.


cash(Posted 2004) [#3]
Thanks I`ll try all of these.

At the moment I am running a 1024 X 768 window.

In your experience what is the norm ?

640 x 480, 800 X 600 etc.


MSW(Posted 2004) [#4]
Most cards under windows can support 640 X 480 in 16-bit color...however, blitz has a couple of handy little built in functions for your game to deturmine the available graphics modes and if a 3D graphics driver is available...

I would first test if the graphics card can support 3D acceleration, then check if 640 X 480 X 16-bit mode is supported...If so then that is the initial graphics resolution I would start with, and set it in a window (not fullscreen)...after that you can allow the players to change the resolution basied on what the graphics card supports (take into account the memory requirements for all your textures...so you might not want the player to set a 1600 X 1200 X 32-bit mode if they only have 64MB of video memory and your game is going to need at least 40MB of it at 32-bit color depth)...once the player has changed the game resolution you can write those settings to a file and reapply them the next time the game is started (if no file exists then go with the windowed 640 X 480 16-bit setting)


BlitzSupport(Posted 2004) [#5]
My crappy game uses about 15MB, so it must be game-specific. What size is each of your models (triangle-wise), and what size are the textures involved? Any fixed-size arrays in use (and if so, how are they defined)?


Anthony Flack(Posted 2004) [#6]
Is this video ram or system ram you're talking about? Either way it's rather a lot and you're right to be concerned. I don't think video mode is your problem; yes it makes a difference but only a small difference in an extreme case like this.


MSW(Posted 2004) [#7]
Say you have 10 1024 X 1024 textures with mip-mapping enabled...and are running the game in 1024 X 768 in >>32-bit<< mode.

That is 9MB for the 2 buffers and 32-bit Z-buffer
Each of the ten textures needs 5.3MB for a total of approx 62MB...

Same 10 textures loading in but with Graphics3D set at 1024 X 768 >>16-bit<< mode and with the W-buffer on requires approx total of 33MB...And you can subtract about 1.5MB of that total if the W-Buffer is off at that resolution.

That is not a small difference


Anthony Flack(Posted 2004) [#8]
True, but only if you then load the textures in 16 bit colour. Personally I think that looks a bit crappy, and if there is transparency in the texture, it looks very very crappy as it uses 4x4x4x4.

However, using 1024x1024 textures is in itself rather excessive.


Ross C(Posted 2004) [#9]
Yeah, 512x512 is the largest i'd go. You could also double check to see if you have any memory leaks, things that are getting loaded and not freed, check to see if your loading entites or textures mulitple times by accident, check to see if your copying textures etc etc.


cash(Posted 2004) [#10]
I have sorted it now thanks.

I reduced the colour depth of all the textures and resized them to 512 X 384.

Also dropped the window size down to 800 x 600.

Used copyentity for several objects which were loaded rather than loadmesh.

It has now gone from 87Mb to 38Mb of system RAM.

Incidentally, the game so far has a series of corridoors, 11 rooms, 6 of which are furnished, 12 fully animated enemies and a main player.


Ross C(Posted 2004) [#11]
512x384 will be scaled up to 512x512. Textures in blitz must be of a square power (64x64,256x256,512x512). They don't have to be square tho, they can be like 512x256. Just as long as the numbers are powers of 2.

Also, when blitz scales texture, like yours, it doesn't make a very good job of it :)