#167439 - 3dfx - Thu Mar 12, 2009 3:40 am
I was poking around the libnds source code and was wondering how to modify a texture I loaded?
I was figuring I could change glTexImage2D to return the address of the loaded texture, then to update it, I'd use parts of the original glTexImage2D in a new function that takes the address to store the texture as an argument like so:
where UpdateTexture would be nearly identical to glTexImage2D other than not looking for a free texture slot.
Would this method work?
I was figuring I could change glTexImage2D to return the address of the loaded texture, then to update it, I'd use parts of the original glTexImage2D in a new function that takes the address to store the texture as an argument like so:
Code: |
uint32 *textureAddress = glTexImage2D( .... ); // void UpdateTexture(int target, int empty1, GL_TEXTURE_TYPE_ENUM type, int sizeX, int sizeY, int empty2, GL_TEXTURE_PARAM_ENUM param, const uint8* texture, uint32 *addr) { uint32 size = 0; uint32 vramTemp; size = 1 << (sizeX + sizeY + 6); switch (type) { case GL_RGB: case GL_RGBA: size = size << 1; break; case GL_RGB4: size = size >> 2; break; case GL_RGB16: size = size >> 1; break; default: break; } // unlock texture memory vramTemp = vramSetMainBanks(VRAM_A_LCD,VRAM_B_LCD,VRAM_C_LCD,VRAM_D_LCD); if (type == GL_RGB) { // We do GL_RGB as GL_RGBA, but we set each alpha bit to 1 during the copy u16 * src = (u16*)texture; u16 * dest = (u16*)addr; glTexParameter(sizeX, sizeY, addr, GL_RGBA, param); while (size--) { *dest++ = *src | (1 << 15); src++; } } else { // For everything else, we do a straight copy glTexParameter(sizeX, sizeY, addr, type, param); swiCopy((uint32*)texture, addr , size / 4 | COPY_MODE_WORD); } vramRestoreMainBanks(vramTemp); } |
where UpdateTexture would be nearly identical to glTexImage2D other than not looking for a free texture slot.
Would this method work?