Video Memory Management

N3D does not provide functionality to manage video memory. I have chosen this approach for the following reasons:

In methods where N3D requires access to resources located in video memory, for example when drawing textured primitives, you pass the texture Vram offset. This imply the resource should at this point already loaded to video memory and ready to use (e.g. cache flushed).

Example: Calls functions from libnds.

#define MY_TEXTURE_VRAMOFFSET   (0)

N3DDEVICE device;

// Load texture to video memory.
// pTexture is a pointer to the texture in main memory.
// textureSizeInBytes equals the size of the texture in bytes.
unsigned vramMapping = vramSetMainBanks(VRAM_A_LCD,VRAM_B_LCD,VRAM_C_LCD,VRAM_D_LCD);
swiCopy(pTexture, VRAM_A + MY_TEXTURE_VRAMOFFSET, (textureSizeInBytes >> 2) | COPY_MODE_WORD);
vramRestoreMainBanks(vramMapping);

// Init device, setup view and projection matrix.

for(;;)
{
    // Clear and begin scene
    
    device.SetTexture(MY_TEXTURE_VRAMOFFSET, 64, 64, N3DFMT_A1B5G5R5);
    device.SetTextureState(N3DTST_ADDRESSU, N3DTADDRESS_MIRROR);
    device.SetTextureState(N3DTST_ADDRESSV, N3DTADDRESS_MIRROR);
    device.SetTextureState(N3DTST_COLOROP, N3DTOP_MODULATE);
            
    // Transform and draw textured object.
    // End and present scene, then wait to vblank.
}

See also:
N3DDEVICE::SetTexture, N3DDEVICE::SetTexturePalette

Generated on Wed Aug 29 19:48:04 2007 for N3D by  doxygen 1.5.3