Download Users Manual
Transcript
Introduction to CgFX
Alternatively, the mapping of texture parameters to hardware units can be handled explicitly by the application, using the routine cgGLEnableTextureParameter(): CGparameter progParam = cgGetNamedParameter(prog, "sampler");
cgGLEnableTextureParameter(progParam);
However, note that it is not possible to call cgGLEnableTextureParameter() with a handle to an effect’s sampler parameter; the handle must be to an actual program parameter.
In general, the first approach is to be preferred for its simplicity.
Interfaces and Unsized Arrays
CgFX also supports Cg’s interfaces and unsized arrays features. Given an effect file with Cg programs that use these features, the compile statement can be used in two different ways to resolve the interfaces and unsized arrays so that the program can be compiled. The abstract types may be resolved using Cg code itself, or they may be resolved using the Cg runtime.
Consider the following example: a Light interface has been defined with SpotLight implementing the interface. The main() program takes an unsized array of Light interface objects, loops over them, and returns the sum of the values returned by their respective value() methods. interface Light {
float4 value();
};
struct SpotLight : Light {
float4 value() { return float4(1,2,3,4); }
};
float4 main(uniform Light l[]) : COLOR {
float4 v = float4(0,0,0,0);
for (int i = 0; i < l.length; ++l)
v += l[i].value();
return v;
}
Recall that all uniform parameters to the program must have expressions in the parenthesized list in the compile statement, and therefore one expression is necessary here for the l parameter.
808-00504-0000-006
NVIDIA
125