Sign in to follow this  
wease

I need a bit of texture loading advice

Recommended Posts

wease    148
Hello I am writting a simple 2d game. My main character, however, has many many animations it can do. So, I am wondering how many textures I can load into a typical graphics card. How big can they be? I read about some multiple of 2 issue. Does that mean that my textures should be something like 400X300, 680X530, etc or like 400X200, 2048X1024, 800X400, etc. Should I load all of them at once (there might be something like 30 2048X1024 textures) or can I load them as I need them? It would be easier if I could load them as I need them but I don't want to wait a long time for each one to load since it owuld disrupt gameplay. If I did load them as I need them, they could be quite small. I would just have to load them over and over depending on what action the main character was doing. Thanks in advance.

Share this post


Link to post
Share on other sites
jollyjeffers    1570
Quote:
Original post by wease
Hello

Hi! [smile]

Quote:
Original post by wease
So, I am wondering how many textures I can load into a typical graphics card.

Very difficult to say, low-end graphics cards can still be in the range of 16-32mb of VRAM, going all the way up to the top-of-the-line 512mb beasts. It also depends on what format you store the textures in - a 32bit ARGB texture (D3DFMT_A8R8G8B8) will take up twice the space of a 16bit RGB texture (D3DFMT_R5G6B5).

You need to determine what your target audience is. Low end/older machines and regular laptops? High end gaming systems?

Targetting 32mb of VRAM is probably a fairly safe bet to cover 90% of systems these days.

Quote:
Original post by wease
How big can they be? I read about some multiple of 2 issue.

It's 2N where N>=0. This gives the common computing sequence of 1,2,4,8,16,32,64,128 etc...

If you can, try sticking to dimensions of these sizes... e.g. 512x512. Rectangular textures are fine (e.g. 1024x64), but some IHV's recommend square textures for best performance.

Quote:
Original post by wease
Should I load all of them at once (there might be something like 30 2048X1024 textures) or can I load them as I need them? It would be easier if I could load them as I need them but I don't want to wait a long time for each one to load since it owuld disrupt gameplay.

There is no clear-cut easy answer to this. The common design is to allocate/create all resources at load-time (or between levels/scenes) and to never unless you absolutely have to create new resources inside the main game loop.

30x2048x1024 textures will hurt you to the tune of 240mb - which is NOT good!. With this much data, you probably do want to find some way to dynamically load/release textures. However, you'll have to be clever about it as loading even a couple of those inside of your main gameloop will have a noticeable impact on performance.

You probably also want to pay attention to the supported texture dimensions. To my knowledge the maximum size ATI Radeon's handle is 2048, and 4096 for the GeForce's. Back to what I originally said about your target audience - you might be unlucky enough to get hardware that won't support textures greater than 256x256 in size [sad].

hth
Jack

Share this post


Link to post
Share on other sites
wease    148
Thansk for your help. I'm targetting older machines I think. I would like to be able to run my game on a card that contains 32MB of VRAM. It seems like I am going to have to load some textures inside the game loop. There are some textures for animations such as walking that will be more frequently in use then others, so I guess I will just keep these ones loaded and load the others later.

If I have 32MB of VRAM, does that mean that I can use all of it for loading textures?

Also, how did you figure out how much memory 30 2048x1024 textures would need?

Thanks again

Share this post


Link to post
Share on other sites
jollyjeffers    1570
Quote:
Original post by wease
Thansk for your help. I'm targetting older machines I think. I would like to be able to run my game on a card that contains 32MB of VRAM. It seems like I am going to have to load some textures inside the game loop. There are some textures for animations such as walking that will be more frequently in use then others, so I guess I will just keep these ones loaded and load the others later.

As I mentioned, there are various schemes you can use to do this.

One that I've used before is to have a "working area" of VRAM that I know I can use. Say 20mb for example. I can then load as much data into that block as will fit, but when I need a new texture (in your case, the animation changes) I'll have to discard one of the existing textures and load in the missing one. How you do this is up to you, but the "Least Recently Used" algorithm often works well.

Quote:
Original post by wease
If I have 32MB of VRAM, does that mean that I can use all of it for loading textures?

Unfortunately not. To add to the fun, there isn't an easy way (via D3D) to obtain how much you can use [smile]

That 32mb of VRAM will also contain the frame buffer(s), depth buffers, any temporary storage, any extra padding required by the device... At a guess I'd be expecting anything up to/around 10mb of that to be used by "general" resources. Leaving you with about 20mb to use as you see fit.

Quote:
Original post by wease
Also, how did you figure out how much memory 30 2048x1024 textures would need?

Each texture has 2048*1024 pixels, I assumed a standard 32bit format - giving us 4 bytes per pixel. 2048*1024*4 = 8,388,608 bytes per texture. Multiply that by your 30 textures, you get 251,658,240 bytes - divide through by 1024*1024 and you'll get 240mb [smile]


One thing you might want to look into is DXTN compressed textures. They're well supported across most graphics hardware, and the basic D3DFMT_DXT1 format gets 6:1 compression. Meaning your 240mb becomes a much nicer 40mb.

It is a lossy compression, so quality can suffer in places and it is usually worse for performance (depending on the hardware/drivers) - so it's not quite perfect.

hth
Jack

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this