Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: CG Shader & Arrays

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2005
    Posts
    3

    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:

    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.

  2. #2
    Junior Member Regular Contributor execom_rt's Avatar
    Join Date
    Jul 2000
    Location
    Canada
    Posts
    237

    Re: CG Shader & Arrays

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

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2005
    Posts
    3

    Re: CG Shader & Arrays

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

    Merry Xmas.

  4. #4
    Junior Member Newbie
    Join Date
    Dec 2005
    Posts
    3

    Re: CG Shader & Arrays

    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.

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •