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 in memory

#158584 - sUPREz - Sat Jun 14, 2008 12:00 am

Hi guys. I have a problem. I'm using glTexImage2D to put my texture into the NDS memory. I made a very little function that puts some pcx texture in memory with the 3 following lines :

Code:
glGenTextures(1, &texture[i]);
glBindTexture(0, texture[i]);
glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, pcx.image.data8);


(this is the basic code from every devkitpro examples)

The problem is that if I first readd a texture with the same ID, it doesn't erase the previous texture, it only add the new one after all the loaded textures. So my program quickly runs out of memory. I think I just change the pointer to my texture in my int array.

Some websites talks about the glDeleteTextures function but it's only with the full OGL engine, not with the NDS GL engine.

I also found the glResetTextures function but this one clear the entire memory !

How can I erase a specific texture in memory ? I have the pointer to the texture, and I want to destroy it. Please help ! :) Thanks a lot !

#158588 - silent_code - Sat Jun 14, 2008 12:12 am

There are some implementations available in the forum, you only have to search for them. But, yes, you are right, the texture handling in libnds' videoGL is very basic. You will have to implement anything more involved by yourself. Good luck.

Happy coding!
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.

#158592 - M3d10n - Sat Jun 14, 2008 2:03 am

Search the forums, I remember someone posting code to reload a texture in an existing address, but it has to be the same size.

If you want to be able to delete individual textures and whatnot, you'll have to come up with your own management. Download the libnds source and look at how it manages textures so you can have a good starting point.

At the most basic, you copy texture and palette data to VRAM slots and tell the DS it's offset address, it's dimensions, format and texgen flags before rendering. So you need a way to store all those flags (dimensions, format, etc) and the texture pixel and palette data location in VRAM, and a way to manage data in the VRAM (allocate/deallocate it).