View Full Version : CG Shader & Arrays

12-21-2005, 01:25 PM
I'm attempting to perform an auto-gain process on a 2D image using CG Fragment Shader. Since I'm already am using a fragment program to perform 2D image processing, I want to modify it to recover the color (or grey scale) histogram. I am passing an hirtogram array as a parameter to my CG program which will be filled. All I need to do is get back the array once the rendering is complete. The pseudo-code is simple:

- Reset the histogram array to 0, and pass it to the CG program;
- Render the image;
- Recover the filled-in histogram array from the CG program;

However, when I call cgGLGetParameterArray1f() to recover the array, CG gives an error indicating the the array index is out-of-bounds. Here is a snipit of my code:

float4 PS_HistoProc( in float4 vColor : COLOR
, uniform float afHistogram[256]
// Convert the color into an intensity level
float fIntensity = clamp( vColor.r*0.3086 + vColor.g*0.6094 + vColor.b*0.0820, 0.0f, 1.0f );
afHistogram[int( fIntensity * 255 )] += 1;
return vColor;
I have a feeling that arrays can only be inputs to a CG program. If so, then why is there a GET function?

Any help would be appreciated.

12-21-2005, 05:01 PM
Did you tried PBO (http://oss.sgi.com/projects/ogl-sample/registry/ARB/pixel_buffer_object.txt) ?
You could use your shader to render into a vertex array ...

12-22-2005, 04:40 AM
Thanks for the suggestion. I haven't used PBOs yet. I'll read the doc over the holidays.

Merry Xmas.

12-23-2005, 06:22 AM
Does ayone have an example on how to use a shader to render into a vertex array using VBOs. I read the pixel_buffer_object extension with the C/C++ source code example, but it does not provide the shader code; it's what's missing for me to understand the details.