# OGL CgFx: vertex program from Effect?

This topic is 4115 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 on other sites
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 on other sites
Thank you. Interestingly though not surprisingly, this is turning to be like Collada conditioners with all these meta data.

Quote:
 Original post by iNsAn1tYI 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 ***

1. 1
2. 2
3. 3
4. 4
Rutin
16
5. 5

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631419
• Total Posts
2999977
×