gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Textures for 3D and memory limitation

#170677 - gusano - Sun Oct 11, 2009 5:03 pm

I'm trying to code a platformer by doing 2D graphics via the 3D hardware (using glOrtho and drawing quads). My main character has several sprite sheets for his different animations (idle, run, climb, jump, ranged attack, melee attack, getting hit, death, etc) As far as I know, I can have at most four 256x256 textures in VRAM at one time, because only VRAM banks A-D can be used for textures and if I'm not mistaken, each bank can hold a single 256x256 texture (or two 128x128 textures.. and so on). Assuming each of my sprite sheets is 256x256 pixels... I can only have 4 animations loaded at one time. BTW, each sprite sheet has 16 frames in it laid out in 4x4 tiles of 64x64 pixels each. Out of the following approaches, which would you recommend most?

1. Resize my sprite sheets to 128x128 to be able to have 8 textures loaded at a time, sacrificing visual quality. (I'd like my character to occupy close to 1/4 the screen size of 256x192)

2. Keep only the textures being used right now in VRAM, and when I need a different one (like switching from melee atack mode to ranged attack mode), load the texture on the fly, swapping an existing one with the new one. Is this a slow process on the DS? I'm using loadPCX() from <nds/arm9/image.h>.

3. Look for a hack that allows me to load more textures into VRAM (possibly into the other banks... although they have less memory)

4. Scrap the 2d via 3d idea and try to do it using hardware sprites (how would this work for animated sprites? I'd still have the same VRAM limit wouldn't I?)

5. Take out a few things from my game design (choose a single attack instead of ranged + melee) to reduce the amount of animations.

6. A different solution I haven't thought of

Thanks for reading this kinda long post... and thanks in advance for any info you can give me!

*EDIT:

For #2 I could keep all the PCX's in regular RAM and only the four I need in VRAM. That way, the only thing I would need to do on the fly is glTexImage2D (copy the image data from RAM to VRAM). That may make a considerable speed difference.

I could also cut out every other frame from my animations. They won't be as smooth, but some of them may not look so bad. When I said 16 frames above I was exaggerating... the animations are between 8 - 12 frames. But I tried skipping frames on a "run" animation and it didn't look so bad.

Since the animations don't really use 16 frames, I could also combine some animations' sheets with other animations' sheets to avoid leaving any empty spaces in the 256x256 images.

#170679 - Min - Sun Oct 11, 2009 9:02 pm

6. You could use a different format for your textures to save a lot of space.
List of texture formats.

Look at the Paletted_Cube example that comes with devkitPro to see how to use them.

#170681 - TwentySeven - Sun Oct 11, 2009 11:11 pm

If you're only displaying a single 64x64 character texture per frame, upload that to vram on the frame you use it.

You don't need to store stuff in vram if you arnt using it on a given frame, and the DS is fairly fast at moving stuff to/from vram, you can move 3-4 64x64 textures per vblank if you need to.

#170684 - gusano - Mon Oct 12, 2009 3:40 am

Pardon my ignorance, but is there a tool to save/convert an image to the formats used by the Paletted_Cube example? They use .bin files for images (there are 2 files per texture, the palette and the indexed image itself) and I'm not sure how they've saved those. I've tried creating my .pcx with a 16 color table and then using GL_RGB16 to load it (newbie test) but that didn't work. I could look into creating my own converter, but I'm pretty sure there's already something out there.

#170685 - Min - Mon Oct 12, 2009 9:12 am

There is texmex. And then there is the texture converter that comes with AntonioND's NitroEngine. There are others as well ( though I don't think they support as many formats as the two mentioned ), just search the forum for "texture converter". ;P

#170691 - gusano - Mon Oct 12, 2009 4:42 pm

Thanks everyone for your help! I have a much better understanding of the DS texture formats, how to convert to them and how to load them! Hopefully I can put up a pic or video of my demo soon...