> ## Name

> cgD3D9SetTexture - set the texture for a sampler parameter

> ## Synopsis

>     #include <Cg/cgD3D9.h>

>     HRESULT cgD3D9SetTexture( CGparameter param,
>                               IDirect3DBaseTexture9 * texture );

> ## Parameters

> param
>   The sampler parameter whose values are to be set.
> texture
>   Pointer to an IDirect3DBaseTexture9, the texture to set for param.

> ## Return Values

> Returns D3D_OK if the function succeeds.

> Returns the D3D failure code if the function fails due to a D3D call.

> ## Description

> cgD3D9SetTexture sets the texture for a sampler parameter.

> When parameter shadowing is enabled, the D3D runtime will maintain a reference (via AddRef) to texture, so care must be taken to set the parameter back to NULL when the texture is no longer needed. Otherwise the reference count will not reach zero and the texture's resources will not get destroyed. When destroying the program that the parameter is associated with, all references to these textures are automatically removed.

> ## Examples

>     // param is a CGparameter handle of type sampler
>     // tex is an IDirect3DTexture9* intialized elswhere
>     ...
>     cgD3D9SetTexture(param, tex);

> ## Errors

> cgD3D9Failed is generated if a D3D function returns an error.

> CGD3D9ERR_INVALIDPROFILE is returned if params's profile is not a supported D3D profile.

> CGD3D9ERR_NODEVICE is returned if a required D3D device is NULL. This usually occurs when an expanded interface routine is called but a D3D device has not been set with cgD3D9SetDevice.

> CGD3D9ERR_NOTLOADED is returned if program was not loaded with the cgD3D9LoadProgram.

> CGD3D9ERR_NOTSAMPLER is returned if param is not a sampler.

> CGD3D9ERR_NOTUNIFORM is returned if param is not a uniform parameter.

> CGD3D9ERR_INVALIDPARAM is returned if the parameter fails to set for any other reason.

> ## History

> cgD3D9SetTexture was introduced in Cg 1.1.

> ## See Also

> cgD3D9SetSamplerState, cgD3D9SetTextureWrapMode