CG Shader & Arrays

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]
                    ) : COLOR
    // 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.

Did you tried PBO ?
You could use your shader to render into a vertex array …

Thanks for the suggestion. I haven’t used PBOs yet. I’ll read the doc over the holidays.

Merry Xmas.

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.


This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.