1

How does the glGenerateMipmap function create the mipmaps? Does it do some kind of interpolation, does it take the average of 4 pixels (this is what assume), or does it skip every second pixel in the next mipmap level?

And is there a way to influence its underlying algorithm? Or choose the way mipmaps are created?

BDL
  • 21,052
  • 22
  • 49
  • 55

1 Answers1

4

The OpenGL Spec, Section 8.14.4 states about mipmap generation:

No particular filter algorithm is required, though a box filter is recommended as the default filter

It is not possible to modify the algorithm used by glGenerateMipmap, but you can create mipmap levels on your own with any algorithm you like and then upload them to the texture using glTexImage2D(...) with the appropriate level. Level 0 is the full resolution, Level 1 is the one with 1/2 of the original size and so on.

BDL
  • 21,052
  • 22
  • 49
  • 55
  • I assume uploading the mipmaps (and creating them by the cpu) in general is much more expensive, isnt it? – Ferris Mertn Mar 12 '22 at 15:08
  • 2
    The spec doesn't state whether glGenerateMipmap is implemented on the GPU or on the CPU. If you want to use GPU acceleration for your own mipmapping, you can either use render-to-texture and render to a specific mipmap level, or you can use a compute shader. – BDL Mar 12 '22 at 15:58
  • Could it be considered an optimization to generate your own mipmaps ahead of time (not at render time) and then just feed the GPU the correct textures based on object distances from the camera, using glTextImage2D(..)? I feel like object distance is not a hugely complicated calc for the CPU since camera location and object location are known. – michael b Dec 22 '22 at 19:02