PDA

View Full Version : CgFx: Get handle to program used by pass


01.data
06-14-2007, 06:41 PM
Hi there,

I'm using the Cg API 1.5 and Cg effect files for rendering. Now I need to get the fragment program used by a pass. How am I doing this? I can't find a function in the (damn) API documentation.

So, my effect looks something like:

float4 FP(float3 texCoord : TEXCOORD0) : COLOR
{
return float4(texCoord,1);
}

technique T1
{
pass
{
VertexProgram = NULL;
FragmentProgram = compile arbfp1 FP();
CullFaceEnable = false;
}
}

And I have a CGpass handle in my application. Now I need something that gives me a CGprogram handle for the fragment program. Any ideas?

Cheers,
Felix

Reedbeta
06-14-2007, 07:04 PM
The idea behind CgFX is that you don't need to handle the vertex or fragment program yourself. You just call cgSetPassState and the programs as well as other states (like CullFaceEnable) are set by the Cg runtime.

If you want to get a handle to the program, you can use the regular Cg API (not CgFX) and call cgCreateProgram or cgCreateProgramFromFile.

Kenneth Gorking
06-15-2007, 08:48 AM
It is possible to get to those programs, it just takes some code. I am using it to iterate vertex-programs to get their varying parameters, and I use this information to set up hardware buffers.

// Iterate techniques in effect-file
CGtechnique technique = cgGetFirstTechnique(effect);
while(technique != 0)
{
// Walk passes
CGpass pass = cgGetFirstPass(technique);
while(pass != 0)
{
// Find the fragment program state
CGstateassignment stateAssignment = cgGetNamedStateAssignment(pass, "FragmentProgram");
if(stateAssignment != 0)
{
// Get the program
CGprogram program = cgGetProgramStateAssignmentValue(stateAssignment);
if(program != 0)
{
// Go nuts :)
}
}

// Proceed to the next pass
pass = cgGetNextPass(pass);
}

// Proceed to next technique
technique = cgGetNextTechnique(technique);
}

01.data
06-15-2007, 02:33 PM
cool. thank you!!