Device.SetTexture(Int32,BaseTexture) Method (Microsoft.DirectX.Direct3D)

How Do I...?

  • Render Mesh with Texture using HLSL

Assigns a texture to a device stage.


Visual Basic Public Sub SetTexture( _
    ByVal stage As Integer, _
    ByVal texture As BaseTexture _
C# public void SetTexture(
    int stage,
    BaseTexture texture
C++ public:
void SetTexture(
    int stage,
JScript public function SetTexture(
    stage : int,
    texture : BaseTexture


stage System.Int32
Index value for the device stage.
texture Microsoft.DirectX.Direct3D.BaseTexture
A BaseTexture object that represents the texture being set.


This method is not allowed if the texture is created with a pool type of Scratch, nor is it allowed with a pool type of SystemMemory, unless DeviceCaps.SupportsTextureSystemMemory is set to true.



The method call is invalid. For example, a method's parameter might contain an invalid value.

How Do I...?

Render Mesh with Texture using HLSL

This example demonstrates how to render a mesh texture using the high-level shader language (HLSL).

In the following C# code example, the following assumptions are made:

  1. effect is a valid HLSL Effect with its technique set.
  2. The code occurs between calls to Effect.BeginPass and Effect.EndPass.
  3. mesh is a valid Mesh.
  4. meshTextures is a valid array of textures for the mesh.
effect.SetValue("WorldViewProjection", worldMatrix);

// Iterate through each subset and render with its texture
for (int m = 0; m < meshTextures.Length; ++m)
    effect.SetValue("SceneTexture", meshTextures[m]));

See Also