PDA

View Full Version : binding semantics for uniforms in CG?



andras
11-15-2006, 06: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?

Toni
11-16-2006, 05: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);

andras
11-16-2006, 06: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..

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

ftp://download.nvidia.com/developer/cg/Cg_Specification.pdf

jra101
11-16-2006, 01: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, ...);