I would like to copy data from a render buffer where the scene is drawn, to another which size is the half of the first render buffer.(The buffer is a square which size is a power of 2)
I would want it the more efficient as possible because I need to do this until the destination buffer size is 1x1 for each frame. Moreover, I need that the destination buffer colors are the average of the source buffer.
In fact, my goal is to compute the average color in a buffer.
First you have to get the data you rendered into a texture. You can do this by rendering directly into the base level of a mipmap texture using a framebuffer object or use glCopyTexImage with the data you rendered in a renderbuffer.
Once the data is written to the base level of the texture, call glGenerateMipmapEXT(GL_TEXTURE_2D) while the texture is bound to the GL_TEXTURE_2D target.
Finally, read back the texture data value for the mipmap level that corresponds to an image size of 1x1 -> log2(size)
Note that you will have more numerical inaccuracies when performing this operation on channels with a low bit count.
But then, how do I get the 1x1 texture data in the last mipmap level? I need this information in a shader. I know how I can read texture data in a shader (I don’t, with opengl functions), but I don’t know how I can access the last mipmap level of the bound texture.
It’s for performing trilinear filtering when using GL_NEAREST_MIPMAP_LINEAR or GL_LINEAR_MIPMAP_LINEAR. With these parameter settings it interpolates between two mipmaplevels.
If you only care about getting the 1x1 level, you can do it with SGIS_texture_lod.
Set GL_TEXTURE_BASE_LEVEL to the 1x1 level, so mipmap sampling is clamped there.
Then you can sample from it normally in the fragment shader (or fixed function, either way.)
You can’t change the level per pixel though, with those older extensions. You need the new shader *Lod functions to do that.
Also, Radeon X1600 can support ARB_shader_texture_lod. At least, we export it on Mac OS X. So complain to your driver writers if you don’t have the extension.
Thank you arekkusu, I didn’t know GL_TEXTURE_BASE_LEVEL, using this is very simple because yes, I only need the 1x1 level. So I don’t need any extension to do this.
Yes, I have some problem with the latest proprietary drivers on linux…I will look if this extension is available on windows.