Using Texture Resources

All of the texture resources in Managed DirectX derive from a single BaseTexture class, which itself derives from the Resource class. There are a few new methods on the BaseTexture object that are covered in Table 8.2.

Table 8.2. Base Texture Methods

PROPERTY OR METHOD

DESCRIPTION

LevelCount

This read-only property specifies the number of levels this texture has. For example, a mipmapped texture (described in the sidebar "Dissecting Mipmaps") would have the number of mipmaps as its level count.

GenerateMipSubLevels

This method will automatically generate the mipmap sublevels we've just mentioned for you. It will use the next property to determine the filtering mode to use when creating these levels.

AutoGenerateFilterType

This read-write property describes how the mipmap sublevels are generated automatically. It takes a member of the TextureFilter enumeration, and will automatically re-create any mipmap sublevels if the filter type is changed. The default filter type for mipmap level generation is TextureFilter.Linear unless the driver does not support that mode, in which case it will use TextureFilter.Point. If the device does not support the selected filter type, this property set will throw an exception. All filter values are valid with the exception of "None". You can see the TextureFilterCaps member of the Caps structure to determine which filter types are supported by your device.

LevelOfDetail

Another read-write property that determines the most detailed level of detail for managed textures.

SHOP TALK: DISSECTING MIPMAPS

So what is this mipmap we keep talking about? Simply put, a mipmap is a chain of textures, with the first member of that chain being the most highly detailed texture. For each subsequent member of that chain, the size is reduced by one power of 2. For example, assuming that you have an original "high resolution" texture of 256x256, the next level in that mipmap would be 128x128, followed then by 64x64, and so on. Mipmap chains are used by Direct3D to control the quality of the rendered textures, at the expense of needing more memory to store the mipmaps. When objects are up close, the high-quality versions of the textures are used; when objects are far away, the lower-resolution textures are used instead.

When creating a texture, one of the parameters used specifies the number of levels you wish to have in this texture. This number of levels corresponds directly to the mipmap chain. Specifying zero for this parameter will cause Direct3D to automatically create a set of mipmaps from your original texture resolution all the way down to a final 1x1 texture in your mipmap chain. In our example above, using 0 for this parameter on a texture that has an original size of 256x256 will create a chain of nine textures: 256x256, 128x128, 64x64, 32x32, 16x16, 8x8, 4x4, 2x2, and 1x1.

When calling the SetTexture function, Direct3D will automatically filter between the various textured mipmaps, based on the currently set MipFilter property on the sampler states class. If you remember our Dodger game we wrote in Chapter 6, you'll remember we set the minify and magnify filters for our road textures. It is the same concept here for the mipmap filters.



Managed DirectX 9 Graphics and Game Programming, Kick Start
Managed DirectX 9 Kick Start: Graphics and Game Programming
ISBN: B003D7JUW6
EAN: N/A
Year: 2002
Pages: 180
Authors: Tom Miller

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