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 > Texture palette banks

#108041 - ollhak - Sat Nov 04, 2006 7:13 pm

Alright, I'm stuck again :/ I'm trying to set up the following memory bank layout (I basicly want to have as much texture memory as possible with some (64kb) 2d bg memory and a little memory for the subscreen):

Code:

vramSetBankA(VRAM_A_TEXTURE); // 128 KB
vramSetBankB(VRAM_B_TEXTURE); // 128 KB
vramSetBankC(VRAM_C_TEXTURE); // 128 KB
vramSetBankD(VRAM_D_TEXTURE); // 128 KB

vramSetBankE(VRAM_E_MAIN_BG); // 64 KB
vramSetBankF(VRAM_F_TEX_PALETTE); // 16 KB

vramSetBankG(VRAM_G_LCD); // 16 KB
vramSetBankH(VRAM_H_SUB_BG); // 32 KB
vramSetBankI(VRAM_I_SUB_SPRITE); // 16 kb


However, it doesn't work very well at all.. with this layout, I get neither textures nor a background. Only a subscreen background. The best layout I have got to work is this:

Code:
vramSetBankA(VRAM_A_TEXTURE); // 128 KB
vramSetBankB(VRAM_B_TEXTURE); // 128 KB
vramSetBankC(VRAM_C_TEXTURE); // 128 KB
vramSetBankD(VRAM_D_MAIN_BG_0x6000000); // 128 KB

vramSetBankE(VRAM_E_TEX_PALETTE); // 64 KB
//vramSetBankF(VRAM_F_TEX_PALETTE); // 16 KB
   
vramSetBankG(VRAM_G_LCD); // 16 KB
vramSetBankH(VRAM_H_SUB_BG); // 32 KB
vramSetBankI(VRAM_I_SUB_SPRITE); // 16 kb


If i change the texture palette to bank F instead, the texture goes black, and I can't figure out why...

Anyone got any ideas? Here's the code I use for loading the texture if that might be the problem:

Code:

glGenTextures(1, &textureID);
glBindTexture(0, textureID);
glTexImage2D(0, 0, GL_RGB256, TEXTURE_SIZE_64, TEXTURE_SIZE_64, 0, TEXGEN_TEXCOORD | GL_TEXTURE_COLOR0_TRANSPARENT, data);
   
u16 palette[256];
palette[1] = RGB15(0, 31, 0);
   
pal = gluTexLoadPal( (u16*)palette, 255, GL_RGB256);

#108103 - duencil - Sun Nov 05, 2006 1:26 pm

yes, last I looked the texture uploading code in libnds (function glTexLoadPal in videoGL.c) assumes palettes are uploaded to VRAM_E. It would need reworking to handle more complicated bank handling

#108107 - ollhak - Sun Nov 05, 2006 1:59 pm

Ah, I thought I had read that somewhere. Guess I'll try downloading the library source and see if I can change it then.

#108110 - ollhak - Sun Nov 05, 2006 2:32 pm

- wow, that was easy. Now it works perfectly, thanks for the heads-up.

For the record, I just changed the glTexLoadPal into this:

Code:
 //---------------------------------------------------------------------------------
void glTexLoadPal(u16* pal, u16 count, u32 addr) {
 //---------------------------------------------------------------------------------
    vramSetBankF(VRAM_F_LCD);
       
   swiCopy( pal, &VRAM_F[addr>>1] , count / 2 | COPY_MODE_WORD);
 
    vramSetBankF(VRAM_F_TEX_PALETTE);
}

// Note - the only thing changed is that all the E's are changed into F's.


Not sure if this breaks any other functionality but it works for the application I'm making right now.

#108112 - Payk - Sun Nov 05, 2006 2:48 pm

^^yeep...by default ndslib uses vram h to store pals for textures.
If u ask me, it should be change able on a more elegant way. But this way above, works fine and afaik it doesnt break down any things ;)

#108114 - OOPMan - Sun Nov 05, 2006 2:54 pm

ollhak, maybe you should just write a custom function based of the original glTexLoadPal that takes a custom VRAM bank as a parm. This way you get to keep the original, not change the defaults and keep your custom functionality :-)
_________________
"My boot, your face..." - Attributed to OOPMan, Emperor of Eroticon VI

You can find my NDS homebrew projects here...

#108119 - ollhak - Sun Nov 05, 2006 3:18 pm

Heh, good point OOPMan. Why didn't I think of that? :D