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 METHODDESCRIPTION
LevelCountThis 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.
GenerateMipSubLevelsThis 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.
AutoGenerateFilterTypeThis 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.
LevelOfDetailAnother 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 256×256, the next level in that mipmap would be 128×128, followed then by 64×64, 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 1×1 texture in your mipmap chain. In our example above, using 0 for this parameter on a texture that has an original size of 256×256 will create a chain of nine textures: 256×256, 128×128, 64×64, 32×32, 16×16, 8×8, 4×4, 2×2, and 1×1.

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.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.119.114