average color of float buffer

I’d like some opinions on the fastest way to find the average color of a single channel 16 bit float rectangular pbuffer on the 6800 series cards.

My first thought was to use GL_GENERATE_MIPMAP_HINT_SGIS and then glGetTexImage to get the smallest mipmap, but it looks like the auto mipmap generation is incompatible with the rectangular textures. Or maybe I was doing something else wrong?

Next I tried glCopyTexSubImage2D to copy this pbuffer to a 2D 16 bit float texture with GL_GENERATE_MIPMAP_HINT_SGIS enabled, but the copy call is quite slow (maybe 1 frame per second). I couldn’t find a format for the 2D texture that would make it fast either. Maybe it’s slow because auto-mipmapping of 16 bit float textures is not enabled in hardware yet? These 2 threads seem to contradict eachother on the issue:
http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=3;t=012490
http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=3;t=012762

There is a small constraint in that I can’t modify the main screen-size pbuffer itself during this operation, so is my only option to make 2 more 16 bit pbuffers of 1/2 and 1/4 the size of the original and start ping ponging until I have only 1 pixel? I’d like to avoid this option as it is not very elegant, but if it’s my only option…

Thanks :slight_smile:

In general, we’re told that the 6800 supports MIP map generation of floating point and rectangular textures, so what you’re suggesting would be the fastest way.

In fact, if you don’t read back, but instead just use the lowest-level MIP map (using explicit MIP map reading) in your shader, you can totally avoid any CPU/GPU stalls.

If it doesn’t work with rectangle textures in current GL drivers, could you use a pow2 texture with black in the parts where it’s not drawn, and scale the resulting output by the appropriate ratio? You can CopyTexSubImage() from a rectangular render are to a pow2 texture target, for example.

Originally posted by jwatte:
In general, we’re told that the 6800 supports MIP map generation of floating point and rectangular textures, so what you’re suggesting would be the fastest way.
Well, that sounds promising. I was getting a crash when I added the mipmap generation parameter after the pbuffer was created so I assumed it didn’t work. I’ll look into it further tomorrow.

In fact, if you don’t read back, but instead just use the lowest-level MIP map (using explicit MIP map reading) in your shader, you can totally avoid any CPU/GPU stalls.
Unfortunately, I do need to read back the average.

If it doesn’t work with rectangle textures in current GL drivers, could you use a pow2 texture with black in the parts where it’s not drawn, and scale the resulting output by the appropriate ratio? You can CopyTexSubImage() from a rectangular render are to a pow2 texture target, for example.
Oops, when I said 2D texture above, I meant power-of-two texture (as opposed to RECT texture). I am getting slow copies (~1 second) from the 16 bit float RECT pbuffer to the 16 bit float 2D texture, so either I’m falling off the fast path somehow or it’s not supported by hardware.

Sounds like you’re falling off the fast path.

Did you try with WGL_ARB_render_texture, to compare?

Yea, I’ve tried render_to_texture and copy_to_texture. I can’t find anything that works other than copying the pbuffer to another 2D float texture which is slow…I hate the pbuffer interface.

I hate to ask this, but would you (or someone) be willing to post the attribute lists one would use for wglChoosePixelFormat and wglCreatePbuffer as well as the texture type and dimension restrictions that give you a 16 bit float backbuffer that supports automatic mipmap generation? I can’t seem to find the magic combination.

Thanks for the help so far…