Windows Dev Center

Texture Addressing Modes

Your Microsoft DirectX 9.0 for Managed Code application can assign texture coordinates to any vertex of any primitive. Typically, the u-texture and v-texture coordinates that you assign to a vertex are in the range of 0.0 to 1.0, inclusive. However, by assigning texture coordinates outside of that range, you can create certain special texturing effects.

You control what Microsoft Direct3D does with texture coordinates that are outside of the [0.0, 1.0] range by setting the texture addressing mode. For instance, you can have your application set the texture addressing mode so that a texture is tiled across a primitive.

Direct3D enables applications to perform texture wrapping. It is important to note that setting the texture addressing mode to TextureAddress.Wrap is not the same as performing texture wrapping. Setting the texture addressing mode to TextureAddress.Wrap results in multiple copies of the source texture being applied to the current primitive; enabling texture wrapping changes how the system rasterizes textured polygons.

Enabling texture wrapping effectively makes texture coordinates outside of the [0.0, 1.0] range invalid, and the behavior for rasterizing such delinquent texture coordinates is undefined in this case. When texture wrapping is enabled, texture addressing modes are not used. Ensure that your application does not specify texture coordinates lower than 0.0 or higher than 1.0 when texture wrapping is enabled.

Setting the Addressing Mode

You can set texture addressing modes for individual texture stages by setting the SamplerStateManager object, which is returned in the SamplerStateManagerCollection.SamplerState property that is retrieved from the Device.SamplerState property. The addressing mode can be set to any member of the TextureAddress enumeration. The following C# code example shows how to set and retrieve addressing modes.


          [C#]
          
// For this example, device is a valid Device object.
//
using System;
using Microsoft.DirectX.Direct3D;

// Load a texture.
Texture tx = new Texture(device, 4, 4, 0, 0, Format.X8R8G8B8, Pool.Managed);

// Set the texture in stage 0.
device.SetTexture(0, tx);

// Set some sampler states.
device.SamplerState[0].AddressU = TextureAddress.Clamp;
device.SamplerState[0].AddressV = TextureAddress.Border;

// Retrieve a sampler state.
TextureAddress ta = device.SamplerState[0].AddressU;


Device Limitations

Although the system generally allows texture coordinates outside of the range of 0.0 to 1.0, hardware limitations often affect how far outside of that range texture coordinates can be. A rendering device communicates this limit in the MaxTextureRepeat property of the Caps structure when you retrieve device capabilities. The value in this member describes the full range of texture coordinates the device allows. For instance, if this value is 128, the input texture coordinates must be kept in the range of -128.0 to +128.0. Passing vertices with texture coordinates outside of this range is invalid. The same restriction applies to the texture coordinates generated as a result of automatic texture coordinate generation and texture coordinate transformations.

The interpretation of Caps.MaxTextureRepeat also is affected by the TextureCaps.SupportsTextureRepeatNotScaledBySize property. When this property is set, the value in Caps.MaxTextureRepeat is used precisely as described. However, when TextureCaps.SupportsTextureRepeatNotScaledBySize is not set, texture-repeating limitations depend on the size of the texture indexed by the texture coordinates. In this case, Caps.MaxTextureRepeat must be scaled by the current texture size at the highest level of detail to compute the valid texture coordinate range. For example, given a texture dimension of 32 and a Caps.MaxTextureRepeat value of 512, the actual valid texture coordinate range is 512/32 = 16, so the texture coordinates for this device must be within the range of -16.0 to +16.0.

Additional information about the texture addressing modes is contained in the following topics.

Show:
© 2015 Microsoft