Conserving Texture Memory

[Previous] [Next]

The suggestions in this section will help you make optimal use of memory when working with Direct3D textures.

AGP Memory

Accelerated Graphics Port (AGP) memory is an excellent tool for texturing applications. You can achieve excellent performance using AGP memory, and it's your best option for using multiple, high-resolution textures. The following code shows how you can use AGP memory like video memory:

 // // Use the IDirect3DDevice7::GetCaps method to check the // D3DDEVCAPS_TEXTURENONLOCALVIDMEM flag to determine whether the  // device can retrieve textures from nonlocal video (AGP) memory.  // if (D3DHWDesc.dwDevCaps & D3DDEVCAPS_TEXTURENONLOCALVIDMEM != 0) {     //     // The card supports AGP texturing.     // You should use the IDirectDraw7::GetCaps method to check that the      // flags used for blt operations are the same for nonlocal and local      // video memory.     //          //     // You can now treat AGP memory like video memory.     //     // Create a surface in AGP memory.     //     DDSURFACEDESC2 ddsd2;     ZeroMemory(&ddsd2, sizeof(ddsd2));     ddsd2.dwSize = sizeof(ddsd2);     ddsd2.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;     ddsd2.dwWidth = width;     ddsd2.dwHeight = height;     ddsd2.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY |                             DDSCAPS_NONLOCALVIDMEM |                            DDSCAPS_TEXTURE |                            DDSCAPS_ALLOCONLOAD;     lpDD7->CreateSurface(&ddsd2, &lpDDSurface7, NULL); }  // // Perform an AGP write here. // lpDDSurface7->Blt(&ScreenCoords0, BackBuffer, &ScreenCoords1,                   NULL, NULL); 

Note that if you use Direct3D's automatic texture management, it will automatically take advantage of AGP memory when appropriate.

Texture Map Compression

A high-quality texture map often is 512 x 512 pixels and at least 16-bit-per-pixel color. Therefore, its image takes up over 500 KB. Using more than seven of these textures on a 4-MB video card would make the card run out of memory. To address this problem, many cards now have 16 to 64 MB of dedicated video memory. Other video cards use the AGP video slot and often can use system memory as video memory when needed.

Applications that have a lot of visual detail might need even more video memory. You might not want to grab a large amount of system memory, and you won't have to because DirectX 7 supports texture compression. Using the S3TC algorithm licensed from S3 Inc., DirectX 7 supports a number of different compression formats. This algorithm allows you to compress textures by 400 percent or more. The format you use is based on image attributes such as whether the image contains transparency information, color-keyed transparency, or color-masking information, as well as whether it's opaque. More and more new 3D accelerators support drivers that allow you to directly pass the compressed data to the card, which saves a great deal of bus transfer time spent getting the data to the card's video memory.

To use compressed textures on the hardware supporting them, simply create a compressed-texture surface and load the texture image into it. You must create this surface by specifying the compressed-texture format you want to use in the dwFlags member of the DDPIXELFORMAT structure. You can load an uncompressed texture to this surface by using the Blt method, or you can load a compressed image that is already in the correct format.

Be aware that DirectX allows you to load and store compressed textures on software and hardware renderers that don't directly support compressed textures. These compressed surfaces need to be blitted to uncompressed surfaces before the textures can be used.



Inside Direct3D
Inside Direct3D (Dv-Mps Inside)
ISBN: 0735606137
EAN: 2147483647
Year: 1999
Pages: 131

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net