PDA

View Full Version : Questions regarding nVidia's Cg toolkit


O.B.
September 20th 04, 05:27 PM
I'm prototyping code to execute a small program on an nVidia GeForce 6800 Ultra
GPU using OpenGL and Cg. However, I'm a bit of newbie in this area and have a
few questions:

1. Is it correct to assume that when cgGLBindProgram is executed that the
CGprogram is executed at that point?

2. Is it correct to assume that when any argument of the CGprogram changes
(after it is binded) that the CGprogram executes again?

3. Is using cgGetNamedParameter the correct operation to access "out" arguments
for the CGprogram?

4. What's the difference between vertex and fragment profiles? Why would you
use one over the other?

5. Where can I find "float3" defined? The Cg manual talks about using it but
never defines it.




Below is my prototype code.

In testProgram.cg:

void testProgram(float3 val1, float3 val2, float returnValue)
{
returnValue = dot(val1, val2);
}

In test.cpp:

int main ()
{
// create context
CGcontext cgContext = cgCreateContext();
if ( 0 == cgContext ) {
return 1;
}

// initialize profiles ... which one is correct to use?
CGprofile vertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);
cgGLSetOptimalOptions(vertexProfile);
// CGprofile fragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
// cgGLSetOptimalOptions(fragmentProfile);

// create program
//
// What's the difference between using a vertextProfile
// and a fragmentProfile?
CGprogram myTestProgram = cgCreateProgramFromFile(
cgContext,
CG_SOURCE,
"testProgram.cg",
vertexProfile,
"testProgram",
0);

// load the program
cgGLLoadProgram(myTestProgram);

// assign parameters
float3 array1 = cgGetNamedParameter(myTestProgram, "val1");
float3 array2 = cgGetNamedParameter(myTestProgram, "val2");

// Is this the correct way for accessing "out" parameters?
float rv = cgGetNamedParameter(myTestProgram, "returnValue");

// set input values
//
// Is it possible to set one element at a time? ie array1[0] = 1.0
array1 = { 1.0, 2.0, 3.0 };
array2 = { 4.5, 5.0, 5.4 };

// Bind the program. I'm assuming this executes testProgram?
//
// Is this a synchronous call? If not, how will I know when the
// computation is complete?
cgGLBindProgram(cgProgram);

// Print returned value
printf("Result = %lf\n", rv);

// Disable profiles
cgGLDisableProfile(vertexProfile);
// cgGLDisableProfile(fragmentProfile);

cgDestroyContext(cgContext);

return 0;
}