Download Users Manual

Transcript
Introduction to the Cg Runtime Library
cgGetParameterResource(color)), D3DVSDT_D3DCOLOR),
D3DVSD_STREAM(1),
D3DVSD_SKIP(4),
D3DVSD_REG(cgD3D8ResourceToInputRegister(
cgGetParameterResource(texCoord)), D3DVSDT_FLOAT2),
D3DVSD_END()
};
The size specified as the second argument of the D3DVSD_REG() macro call of a Direct3D 8 declaration does not need to match the size of the corresponding parameter for the vertex declaration to be valid. Those sizes are specified to describe how the data is laid out in the streams, not to perform any type checking with the shader code. The data referred to by a D3DVSD_REG() macro call is expanded to the four floating point values of the corresponding hardware register, and the missing values are set to 0 for x, y, and z, and to 1 for w.
Minimal Interface Type Retrieval
Use cgD3D9TypeToSize() to retrieve the size of a CGtype enumerated type in terms of floating‐point numbers:
DWORD cgD3D9TypeToSize(CGtype type);
More precisely, it is the number of floating‐point values required to store a parameter of type type. This function does not apply to some types, like the sampler types, in which case it returns zero. It is useful because applications can determine how many floating‐point values they have to provide to set the value of a given parameter.
Minimal Interface Program Examples
In this section we provide some code samples that illustrate how and when to use functions from the minimal interface to make Cg programs work with Direct3D. To enhance clarity, the examples do very little error checking, but a production application should check the return values of all Cg functions. The vertex and fragment programs below are referenced in “Direct3D 9 Application” on page 92 and “Direct3D 8 Application” on page 95.
Vertex Program
The following Cg code is assumed to be in a file called VertexProgram.cg. void VertexProgram(
in float4 position
in float4 color
in float4 texCoord
out float4 positionO
808-00504-0000-006
:
:
:
:
POSITION,
COLOR0,
TEXCOORD0,
POSITION,
NVIDIA
91