Cg newbie questions

Apologies if this isn’t the place for Cg questions, I haven’t found a forum devoted to that yet…

There seems to be very little documentation available for the Cg Standard Library. Anyone know a good reference?

In particular…

  1. If I have a fragment program which needs to access a texture, is it enough to specify the coordinate
    samplerRECT tex : TEXUNIT0
    ? I read somewhere that these parameters have to be uniform, but that doesn’t make sense to me—the glBindTexture call should be all the higher-level code has to do. It shouldn’t need to call cgGLSetTextureParameter as well, or so my sensibility goes.

  2. How does the texRECT function behave when presented with texture coordinates outside the range [0,h]x[0,w]? Is this dependent on the OpenGL texture mode?

  3. How do I retrieve the width and height of a samplerRECT object? If necessary I could pass them as a uniform float2, but that seems like a waste, again…

  4. Can uniform parameters be int2, etc, or just floating-point types? I ask because (again, due to lack of a good reference list) I only see versions of cgGLSetParameter* which take floats and doubles.


  1. The TEXUNITn semantic when specified after a sampler definition specifies which texture unit you are sampling from. You don’t need to use cgGlSetTextureParameter, it is a convenience function.

  2. Depends on the texture wrap mode.

  3. The shader doesn’t have access to this information, you have to pass it in as a uniform value.

  4. You can declare an int2 uniform but for most profiles it will end up being a float2.

Thanks, that’s helpful.