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 > NDSLib problem with texture sizes

#44987 - TheChuckster - Tue Jun 07, 2005 2:28 am

Any texture size up to but not including 256x256 works fine but when I try to have a texture at 256x256 or higher, it simply does not work. 256x128 and vice versa does work. When I try these larger sized textures, I get a white polygon instead of the actual texture. The texture conversion utility I am using has been proven to work fine in other cases. I am quite certain that my code is correct, but here it is nonetheless:

My Vram banks are set as:

Code:
vramSetBankA(VRAM_A_TEXTURE_SLOT0); vramSetBankB(VRAM_B_TEXTURE_SLOT1); vramSetBankC(VRAM_C_TEXTURE_SLOT2); vramSetBankD(VRAM_D_TEXTURE_SLOT3);


And I'm using:

Code:
glTexImage2D(0, 0, GL_RGBA, TEXTURE_SIZE_256, TEXTURE_SIZE_256, 0, TEXGEN_TEXCOORD, (u8*)texture);


I and the #dsdev IRC chatters just think it's running out of memory or something else that is the fault of ndslib due to its hacky OpenGL implementation. Anyone have any suggestions on how I could go about fixing this problem?

#45060 - exoticorn - Tue Jun 07, 2005 12:52 pm

This is a combination of two bugs in ndslib - it won't let you use the last byte of your vram banks and it won't let you use any other than the first vram bank... Since one 256x256x16bit texture is exactly the size of one vram bank ndslib isn't able to place it in vram.
You can fix this by changing two functions in videoGL.c:

Code:

int vramIsTextureBank(uint16 *addr)
{
   uint16* vram = vramGetBank(addr);

   if(vram == VRAM_A)
   {
      if((VRAM_A_CR & 3) == ((VRAM_A_TEXTURE) & 3))
         return 1;
      else return 0;
   }
   else if(vram == VRAM_B)
   {
      if((VRAM_B_CR & 3) == ((VRAM_B_TEXTURE) & 3))
         return 1;
      else return 0;
   }
   else if(vram == VRAM_C)
   {
      if((VRAM_C_CR & 3) == ((VRAM_C_TEXTURE) & 3))
         return 1;
      else return 0;
   }
   else if(vram == VRAM_D)
   {
      if((VRAM_D_CR & 3) == ((VRAM_D_TEXTURE) & 3))
         return 1;
      else return 0;
   }
   else
      return 0;
   
}
uint32* getNextTextureSlot(int size)
{
   uint32* result = nextBlock;
   nextBlock += size >> 2;

   //uh-oh...out of texture memory in this bank...find next one assigned to textures
   while(!vramIsTextureBank((uint16*)nextBlock - 1) && nextBlock <= (uint32*)VRAM_E)
   {
      nextBlock = (uint32*)vramGetBank((uint16*)result) + (0x20000 >> 2); //next bank
      result = nextBlock;        
      nextBlock += size >> 2;
   }

   if(nextBlock > (uint32*)VRAM_E)
      return 0;

   else return result;   

}


Using these changes we were able to render a simple 3d scene using 3 256x256x8 and 4 128x128x8 textures.
I hope this helps you,
exo

#45140 - TheChuckster - Tue Jun 07, 2005 11:08 pm

Worked like a charm. Thanks man.

NDSLib ought to be updated to include these changes.

#45175 - dovoto - Wed Jun 08, 2005 7:52 am

TheChuckster wrote:
Worked like a charm. Thanks man.

NDSLib ought to be updated to include these changes.


Done..thanks exoticorn
_________________
www.drunkencoders.com

#45239 - TheChuckster - Wed Jun 08, 2005 10:56 pm

Well, to continue reporting bugs, now I am having problems utilizing multiple textures in one app. Either texture works individually and on both objects. What I am doing is basically what any GL programmer would expect to do:

Code:
glGenTextures(2,&(textureID[0]));

glBindTexture(0, textureID[0]);
glTexImage2D(0, 0, GL_RGBA, TEXTURE_SIZE_512, TEXTURE_SIZE_512, 0, TEXGEN_TEXCOORD, (u8*)texture);   

glBindTexture(0, textureID[1]);
glTexImage2D(0, 0, GL_RGBA, TEXTURE_SIZE_512, TEXTURE_SIZE_512, 0, TEXGEN_TEXCOORD, (u8*)texture_bin);


Code:
glBindTexture(0, textureID[0]);
DrawQuad();

glBindTexture(0, textureID[1]);
DrawQuad2();


Yet only the first object drawn has a texture regardless.

#45259 - Ethos - Thu Jun 09, 2005 2:26 am

Is this on emus?

I have no problem using multiple textures.

note: your texture size is HUGE, two textures fill all 4 main banks, you must first have a bank fix and also dedicate all vram to textures
_________________
Ethos' Homepage (Demos/NDS 3D Tutorial)

#45268 - dovoto - Thu Jun 09, 2005 3:28 am

I think there is a good chance my texture load code does not support textures larger than a bank..this is just due to crapy memory management on my part (but maybe this is not the case). But as he said 512x512x2 is 512KB (all 4 main banks) with a single texture...there is not enough vram total for 2 of them.
_________________
www.drunkencoders.com

#45300 - TheChuckster - Thu Jun 09, 2005 11:54 am

Wow. This is very limiting for what I'm trying to do. What do commercial developers do for textures? 8 or so 64x64 256 color ones?

And I had no luck with palette textures. Is that because the if(palette) line is commented out in teximage2D?

#45303 - Ethos - Thu Jun 09, 2005 1:14 pm

Reduce the size and stretch it over a surface...its not like the DS has super high resolution graphics :)
_________________
Ethos' Homepage (Demos/NDS 3D Tutorial)

#45305 - FluBBa - Thu Jun 09, 2005 2:05 pm

TheChuckster:
A 512x512 texture rendered on a 256x192 display is limiting? wow...
_________________
I probably suck, my not is a programmer.

#45342 - dovoto - Thu Jun 09, 2005 8:51 pm

You currently have to load the palette manualy (As i am not certain how to handle multiple palettes yet):

<warning crapy psuedo code>

setVramBankE(VRAM_E_LCD); //unlock it
dma(pal, VRAM_E, 256); //write the palette
setVramBankE(VRAM_E_TEXTURE_PALETTE); //set it up for texture palettes

</crap code>

http://www.drunkencoders.com/documents/DS/ndslib.htm#_VRAM_Defines:

For the actual defines and function definitions
_________________
www.drunkencoders.com

#45908 - duencil - Thu Jun 16, 2005 12:24 pm

exoticorn wrote:

Using these changes we were able to render a simple 3d scene using 3 256x256x8 and 4 128x128x8 textures.
I hope this helps you,
exo


Did your 7 textures share the same palette? Or did you figure out how to specify the location of the current palette as well?

#45973 - exoticorn - Fri Jun 17, 2005 12:02 pm

duencil wrote:
exoticorn wrote:

Using these changes we were able to render a simple 3d scene using 3 256x256x8 and 4 128x128x8 textures.
I hope this helps you,
exo


Did your 7 textures share the same palette? Or did you figure out how to specify the location of the current palette as well?


All 7 textures shared one palette. I wrote a textureconverter for this which reads in a number of images and generates textures from then with one optimized palette.

#45978 - mike260 - Fri Jun 17, 2005 1:32 pm

duencil wrote:
exoticorn wrote:

Using these changes we were able to render a simple 3d scene using 3 256x256x8 and 4 128x128x8 textures.
I hope this helps you,
exo


Did your 7 textures share the same palette? Or did you figure out how to specify the location of the current palette as well?


FYI, the palette address register appears to live at 0x040004AC.