Manual glGenerateMipMap generation in C++


I am considering replacing glGenerateMipMap with a manual C++ based mipmap generation when
loading normal maps (since I read it makes sense to normalize them for each mip map level
EVEN when the normals will be anyway normalized in the shader later).

Anyone knows code examples for this? Probably a simple box filter should do the trick.


This might help.

Thanks for the link!

For non power of two textures it seems to be more complicated to achieve good results:

So for now I restrict my normal maps to power of two dimensions.

I have implemented it this way:

For each pixel:

  1. Read 4x RGB values from parent level and convert them to 4 normals
  2. Add the 4 normals together and normalize the result
  3. Convert the normalized result to RGB again and store it in the current level

Hope that is ok?