PDA

View Full Version : Histograms and FBOs



Arkh89
12-23-2010, 08:31 AM
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

KjuEnnDee
12-23-2010, 08:56 AM
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

mhagain
12-23-2010, 09:00 AM
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

Arkh89
12-23-2010, 09:09 AM
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?

Alfonse Reinheart
12-23-2010, 09:38 AM
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."

Arkh89
12-23-2010, 09:47 AM
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?

mhagain
12-23-2010, 10:02 AM
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).

mobeen
12-27-2010, 11:15 PM
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

paratras
12-29-2010, 04:20 AM
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.