NAME

cgD3D9BindProgram - activate a program with D3D

SYNOPSIS

  #include <Cg/cgD3D9.h>

  HRESULT cgD3D9BindProgram( CGprogram program );

PARAMETERS

program

A CGprogram handle, the program to activate with D3D.

RETURN VALUES

cgD3D9BindProgram returns D3D_OK if the function succeeds.

If the function fails due to a D3D call, that D3D failure code is returned.

DESCRIPTION

cgD3D9BindProgram activates a program with D3D. The program is activated using IDirect3DDevice9::SetVertexShader() or ::SetPixelShader() depending on the program's profile type.

D3D allows only one vertex shader and one pixel shader to be active at any given time, so activating a program of a given type implicitly deactivates any other program of a similar profile.

If parameter shadowing is enabled for program, this call will set the D3D state for all shadowed parameters associated with program. If a parameter associated with program has not been shadowed (using a "Parameter Management" call) when this function is called, the D3D state associated with that parameter is not modified.

If parameter shadowing is disabled, only the D3D shader is activated, and no other D3D state is modified.

EXAMPLES

The following example code illustrates the use of cgD3D9BindProgram:

  // vertexProg and pixelProg are CGprograms initialized elsewhere
  // pDev is an IDirect3DDevice9 interface intialized elsewhere
  ...
  HRESULT hr = cgD3D9BindProgram(vertexProg);
  HRESULT hr2 = cgD3D9BindProgram(pixelProg);
  // Draw a quad using the vertex and pixel shader
  // A vertex and index buffer are set up elsewhere.
  HRESULT hr3 = pDev->DrawIndexedPrimitve(D3DPT_TRIANGLELIST, 0, 4, 0, 2);
        

ERRORS

If the function fails due to a D3D call, that D3D failure code is returned.

The function could also return one of these Cg-specific errors:

CGD3D9ERR_NOTLOADED is generated if to-be-written

CGD3D9ERR_NODEVICE is generated if to-be-written

HISTORY

cgD3D9BindProgram was introduced in Cg to-be-written.

SEE ALSO

function1text, function2text