Histograms and FBOs

Hi,

I am trying to use the GL native’s histogram function through FBO rendering (to texture) but it still returns me zeros…

What I wrote is :

Initialization : 
   GLuint hist[256][3]
   //...
   glHistogram( GL_HISTOGRAM, 256, GL_RGB, GL_FALSE);
   glEnable(GL_HISTOGRAM);
   //clean hist to 23 (different from 0)


Loop : 
   glResetHistogram(GL_HISTOGRAM);
   //FBO rendering...
   glGetHistogram(GL_HISTOGRAM, GL_TRUE, GL_RGB, GL_UNSIGNED_INT, hist);
   //print... "all zeros"

Any ideas of what I did wrong?
Is FBO rendering considered as valid per-pixel operation (since I am also using Pixel Sahders)? Is histogram computation compatible with it?

Thanks,

Arkh

Hello,

did you check if something went wrong after some call? A quick and dirty method to check this is by placing a
printf(“Error: %s”, gluErrorString(glGetError()));
after every related OpenGL call. You could also check whether your histogram is set to 0s by OpenGL by putting some pattern or random numbers in the array and check whether this pattern is the same after the calls.

Regards

The histogram functions are part of the old imaging subset which well predates FBOs and which - even if supported by your implementation - is rather unlikely to be hardware accelerated anyway. http://www.opengl.org/wiki/Common_Mistakes#Color_Index.2C_The_imaging_subset

Yes, I checked all calls but nothing went wrong…

mhagain, do you mean that there is no way to get hardware accelerated histogram function? I have to write some dirty code based on shaders?

mhagain, do you mean that there is no way to get hardware accelerated histogram function? I have to write some dirty code based on shaders?

“dirty code based on shaders” is hardware acceleration. And yes, odds are that glHistogram is not hardware accelerated; if you want to ensure performance in computing histograms, you will need “dirty code based on shaders.”

I mean “dirty” because the way pixel shaders must be used isn’t compatible with building histogram :

The main histogram algorithm is :

For each pixel do histogram[current_color]++

But there is no way to “stack” values with shaders (two shaders incrementing the same value), isn’t it?

Google for GLSL histogram gives a few candidate approaches. HLSL histogram will likely give a few more (and converting sample HLSL code to GLSL is a complete no-brainer).

Check the nvidia opengl 9.5 sdk ships with a image histogram code sample (this uses occlusion queries) http://developer.download.nvidia.com/SDK/9.5/Samples/samples.html#imgproc_histogram

Wouldn’t it be easier to implement the histogram in OpenCL? If I read the docs correctly, it’s possible to share renderbuffers across OpenGL and OpenCL.