Sign in to follow this  
rumble

OGL CgFx: vertex program from Effect?

Recommended Posts

rumble    118
I hope this is the right forum. I am looking for the function that returns the vertex program/fragment program handles by querying an effect's specific technique and pass. With the program handle, I can send vertices data to float3 positions : POSITION via cgGLSetParameterPointer( cgGetNamedParameter( myVPprogramHandle, "positions"), 3,GL_FLOAT,0, vers ); I load an effect via: CGeffect myCgEffect = cgCreateEffectFromFile(myCgContext, "myEffect.fx", NULL); I can get particular technique and then passes of the effect via: myCgTechnique = cgGetNextTechnique(myCgEffect); myCgPass = cgGetNextPass(myCgTechnique); But I cannot find a function that tells me the VP/FP in myCgPass. The closest I found was: CGprogram prog=cgGetFirstProgram( myCgContext); But this is far from desired. Please let me know if my whole approach is wrong. Thanks.

Share this post


Link to post
Share on other sites
iNsAn1tY    476
I ran across the same problem a couple of weeks ago. I was initially going about it in the same way as you are, but you need to look at the problem from a slightly different perspective to figure out which functions you need to use.

What you're trying to access in the pass are the state assignments: things like ZEnable, VertexProgram and FragmentProgram, etc. So you take your pass, and iterate through all of its state assignments until you find the one with the state name VertexProgram. When you find it, you can use cgGetProgramStateAssignmentValue to get a reference to the vertex program itself, and from there, you can just iterate through its parameters and do whatever you need to with them. Sample code explains this all rather nicely; see below.


CGpass lPass = cgGetFirstPass( mTechnique );

while( lPass )
{
CGstateassignment lCgStateAssignment = cgGetFirstStateAssignment( lPass );

while( lCgStateAssignment )
{
CGstate lCgState = cgGetStateAssignmentState( lCgStateAssignment );

CGtype lCgType = cgGetStateType( lCgState );
std::string lsName = cgGetStateName( lCgState );

// Is this the VertexProgram state assignment?
if( lCgType == CG_PROGRAM_TYPE &&
boost::algorithm::iequals( lsName, "VertexProgram" ) )
{
CGprogram lCgProgram = cgGetProgramStateAssignmentValue( lCgStateAssignment );

lCgParameter = cgGetFirstParameter( lCgProgram, CG_PROGRAM );

while( lCgParameter )
{
CGtype lType = cgGetParameterType( lCgParameter );
std::string lsSemantic = cgGetParameterSemantic( lCgParameter );
std::string lsName = cgGetParameterName( lCgParameter );

// TODO - Process the parameter...

lCgParameter = cgGetNextParameter( lCgParameter );
}
}

lCgStateAssignment = cgGetNextStateAssignment( lCgStateAssignment );
}

lPass = cgGetNextPass( lPass );
}


Share this post


Link to post
Share on other sites
rumble    118
Thank you. Interestingly though not surprisingly, this is turning to be like Collada conditioners with all these meta data.

Quote:
Original post by iNsAn1tY
I ran across the same problem a couple of weeks ago. I was initially going about it in the same way as you are, but you need to look at the problem from a slightly different perspective to figure out which functions you need to use.

What you're trying to access in the pass are the state assignments: things like ZEnable, VertexProgram and FragmentProgram, etc. So you take your pass, and iterate through all of its state assignments until you find the one with the state name VertexProgram. When you find it, you can use cgGetProgramStateAssignmentValue to get a reference to the vertex program itself, and from there, you can just iterate through its parameters and do whatever you need to with them. Sample code explains this all rather nicely; see below.

*** Source Snippet Removed ***

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this