View Full Version : binding semantics for uniforms in CG?

11-15-2006, 05:25 PM
The docs says that I can use binding semantics on uniforms like this:

float4 main(const uniform color : C0) : COLOR { return color; }But how can I set a uniform using the semantics? It seems like I still have to call cgGetNamedProgramParameter, but then what's the point?

11-16-2006, 04:18 AM
To get the texture unit binding semantic i do something like this, it might work for you, but check the name for color :)

CGparameter paramStruct = cgGetFirstStructParameter(mParam);

if(0 == strcmp("texunit 0",cgGetResourceString(cgGetParameterResource(paramS truct))))
samplers[0] = paramStruct;
} Anyway i think you have function in the API definition, am i right?

const char* value = cgGetParameterSemantic(paramStruct);

11-16-2006, 05:37 AM
I think you misunderstood. I don't want to use names in the code. I would like to use semantics in the shader to bind a uniform to a register location, and then just set the value of that location.

For example, with vertex attributes, I can use the semantics ATTR0, and then in the code, I just say glVertexAttrib4fv(0, pos)... Unfortunately I coulnd't figure out how to do the same with uniforms. There are similar semantics allright (C0 - C15), but they don't seem to work..

11-16-2006, 08:03 AM
There are tables listing the binding semantics for the various profiles in the Cg 1.5 specification:


11-16-2006, 12:02 PM
You can set the uniform using the profile specific uniform function:

arbvp1/vp40: glProgramLocalParameter4fARB(GL_VERTEX_PROGRAM_ARB , 0, ...);
vp20/vp30: glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 0, ...);
arbfp1/fp40: glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_A RB, 0, ...);
fp30: glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_N V, 0, ...);