PDA

View Full Version : sized array of float as parameter to nvidia cg shader



siddharth.cmdz
10-10-2012, 11:14 PM
I am trying to use Cg shaders to blend textures within a fragment shader. I want to set weights for each image that i would like to pass down to the shader as a uniform variable of float arrays. These weights are fixed array of floats that would be reset variably. Is this possible? I see there is a method cgGLSetParameterArray1f(CGparameter, int offset, int nelements, float* values) and a method CgSetActiveSize(CGparameter param, int size).

Even though i use these methods i get errors while creating the shader using CgCreateProgram().

Is it possible to do what i am trying to achieve and can someone give me or point me to a sample code? even rough snippets of code or pointers would do.

If this is accomplishable in glsl, then I surmise that there must be something similar in cg as well..so please let me know how its done in glsl too so that i can search for its counterpart in cg too

thanks a lot..

siddharth.cmdz
10-11-2012, 04:16 PM
Anyone? Am i in the right forum to post?

Dark Photon
10-11-2012, 04:24 PM
This really isn't an OpenGL question. I'd direct you to The Cg Forum (http://developer.nvidia.com/forums/index.php?showforum=14) on NVidia's developer website, ...but I see it's still down.

If you post on this site, the High-level APIs (http://www.opengl.org/discussion_boards/forumdisplay.php/12-High-level-APIs-%28e-g-Inventor-Performer-Optimizer%29) is probably the better spot.

At any rate, I don't know the answer to your question. You might actually post the error message. Might give someone something to go on.

siddharth.cmdz
10-11-2012, 08:34 PM
This really isn't an OpenGL question. I'd direct you to The Cg Forum (http://developer.nvidia.com/forums/index.php?showforum=14) on NVidia's developer website, ...but I see it's still down.

If you post on this site, the High-level APIs (http://www.opengl.org/discussion_boards/forumdisplay.php/12-High-level-APIs-%28e-g-Inventor-Performer-Optimizer%29) is probably the better spot.

At any rate, I don't know the answer to your question. You might actually post the error message. Might give someone something to go on.

Thank you for the reply... yes unfortunately nvidia's forums are down. I will post the error message as soon as possible and post it on the high level apis as well..thank you.

siddharth.cmdz
10-16-2012, 09:33 PM
i figured out how to accomplish what i was seeking...Just in case someone else stumbled into this , heres what i did:

cg runtime actually allows you set a size the size of an array. So you would need to :

* create an array using cgCreateParameterArray{fr}(..)
* get the name of the parameter from the shader program using cgGetParameterName(...)
* set the size of the unsized array variable using cgSetArraySize(..)
* connect the created parameter to the parameter you just got with previous step, using cgConnectParameter(...)
* re-compile the program and load using cgCompileProgram(...) and cgLoadProgram(...).

It is to be noted that most of the operations of resizing the array is done by the cg runtime, so as per the documentation, it is recommended to set the compilation mode in cg to manual using cgSetAutoCompile(...)