Jump to content


CgFx: Get handle to program used by pass


3 replies to this topic

#1 01.data

    New Member

  • Members
  • Pip
  • 4 posts

Posted 15 June 2007 - 01:41 AM

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

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 15 June 2007 - 02:04 AM

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.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 911 posts

Posted 15 June 2007 - 03:48 PM

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);

}


"Stupid bug! You go squish now!!" - Homer Simpson

#4 01.data

    New Member

  • Members
  • Pip
  • 4 posts

Posted 15 June 2007 - 09:33 PM

cool. thank you!!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users