Question

I've dabbled with basic shader programming before, using the GLSL way. Now I've come back to it, using Cg shaders. Following the tutorial at Josh Beam's website I've achieved the desired functionality, was able to change my shader around, however I couldn't manipulate the uniforms in it on the OpenGL side.

GLuint handle;
::glGenProgramsARB(1, &handle);
::glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, handle);
::glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(pSource), pSource);

while(true)
{
  ::glEnable(GL_FRAGMENT_PROGRAM_ARB);
  ::glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, handle);
  // render
  ::glDisable(GL_FRAGMENT_PROGRAM_ARB);
  // present backbuffer
}

Works perfectly. If I try to ::glGetUniformLocationARB(handle, pUniformName), I get a GL_INVALID_VALUE error. Tried to do this both after creating the shader, and after binding, to the same outcome. I have also tried to ::glUseProgramObjectARB(handle), as different sources suggested, however this didn't work either, and seems to belong to the GLSL way (Lighthouse3D tutorials).

I have double-checked that the uniform name is correct.

I have also found an approach (NeHe tutorials), that involves #include-ing Cg headers and calling cg APIs. Is this not doable using OpenGL API-s? (The reason for this is minimalism; I want to make this functionality a part of a static library, and I'm all for minimising the number of compiling / linking dependencies.)

Was it helpful?

Solution

You are confusing different extensions.

The term "uniform" refers to GLSL global variables declared with the uniform keyword. ARB assembly shaders do not have uniforms. They have a similar concept, but they don't call them "uniforms". glGetUniformLocationARB is a GLSL function. The ARB assembly term for them is "program local parameter". These are naturally set by the glProgramLocalParameterARB series of functions.

Oh, and you should never use any GLSL functions that end in ARB. Ever.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top