Imagination Blog

Why you really should be using mipmapping in your graphics applications - Imagination

Written by Benjamin Anuworakarn | Aug 15, 2019 6:19:38 PM

The new PowerVR developer documentation website has been up and running for a few weeks now. We’re really pleased to see how it’s been helping people get the most out of their applications, as well as learn new things about graphics programming and PowerVR.

If you still haven’t taken the time to check it out (you really should!) and you need to be convinced, here’s a quick preview of a topic you will find in our PowerVR Performance Recommendations.

Along with our documentation for advanced graphics developers, we’ve recently been taking more time to help those new to graphics programming, as evidenced by our new “Getting Started” guides to both Vulkan® and OpenGL® ES. So the topic today is all about mipmapping – you’ll get a very quick introduction, and also some top tips including some specific to PowerVR.

Introduction to mipmapping

In a nutshell, for almost all graphics applications, mipmapping is incredibly useful as it increases cache efficiency and reduces bandwidth usage, all for only a modest increase in texture file size.

However, for the uninitiated…

What is mipmapping?

Mipmaps are smaller, pre-filtered versions of a texture image, representing different levels of detail (LOD) of the texture. They are often stored in sequences of progressively smaller textures called mipmap chains with each level half as small as the previous one.

They are used for situations where the distance between an object and the camera can change. As the object gets further from the camera, the object’s texture will eventually appear smaller on-screen than its actual resolution, in other words, there will be more than one texel (pixels of a texture map) per screen pixel. The texture will have to be scaled down in a process called minification filtering, which often requires the application to sample multiple texels to decide on the colour of a pixel. This becomes a problem when you need to sample the entire texture at runtime for an object that could only be a single pixel wide.

This is where mipmaps come in. Instead of sampling a single texture, the application can be set up to switch between any of the lower resolution mipmaps in the chain depending on the distance from the camera.

Can you explain the benefits in a bit more detail?

I’m glad you asked, as there are two main advantages:

  1. Improved image quality – Using mipmapping can help to eliminate aliasing effects caused by oversampling textures. These effects can potentially ruin the visual quality of the application.
  2. Increased performance Mipmapping increases cache efficiency as full-size textures will not be needed as often, and the lower resolution mipmaps will fit more easily in the texture cache. This means texture data doesn’t have to be fetched as often, reducing bandwidth usage and increasing application performance.

What’s the catch? Well, the only notable drawback for most applications is the increase in texture file size, as the full mipmap chain has to be stored alongside the full resolution texture. This increases file sizes by about 33%, but with the increase in rendering speeds and image quality, this really doesn’t matter much.

There are also some situations where mipmapping isn’t very useful, for example:

  • Objects which will never change their distance from the camera, for example many UI elements. The LOD of these elements is never going to change, so in this case, mipmapping is pointless.
  • Circumstances where filtering cannot be applied sensibly, such as for index and depth textures which contain non-image data.

Generating mipmaps

Mipmaps can either be created offline or during runtime. The decision comes down to a balance between the storage cost of offline generation and the increased workload of runtime generation. In most cases, however, offline is best.

Our very popular texture-processing utility PVRTexTool (included with the PowerVR SDK) can be used to generate a mipmap chain for a texture, with only a couple of clicks. The mipmapped image can then be saved using our proprietary compressed PVRTC texture format, or a wide range of other formats.

If you really want to generate mipmaps at runtime (and lose the benefit of PVRTC or other compressed formats), OpenGL ES provides the function glGenerateMipmap. Unfortunately, Vulkan doesn’t have any built-in function for this, so you’ll need to implement it yourself.

And finally…

For more PowerVR performance recommendations and other useful developer information, please visit our new, regularly-updated website at docs.imgtec.com.

Do feel free to leave feedback through our forum.