As promised by a previous post entitled, “How to Turn Off Bilinear Filtering in OpenGL,” I’m going to explain the various texture filtering combinations behind these two very common OpenGL calls:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, <texture shrinkage filter>);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, <texture expansion filter>);
The value of parameter number three depends on whether you are setting a GL_TEXTURE_MIN_FILTER variable or a GL_TEXTURE_MAG_FILTER variable. Here are the possible combinations:
-
When the second parameter is GL_TEXTURE_MIN_FILTER, parameter three can be:
-
GL_NEAREST_MIPMAP_NEAREST
-
GL_LINEAR_MIPMAP_NEAREST
-
GL_NEAREST_MIPMAP_LINEAR
-
GL_LINEAR_MIPMAP_LINEAR
-
GL_NEAREST
-
GL_LINEAR
-
-
When the second parameter is GL_TEXTURE_MAG_FILTER, parameter three can be:
-
GL_LINEAR
-
GL_NEAREST
-
The filter value set for GL_TEXTURE_MIN_FILTER is used whenever a surface is rendered with smaller dimensions than its corresponding texture bitmap (far away objects). Whereas the filter value for GL_TEXTURE_MAG_FILTER is used in the exact opposite case – a surface is bigger than the texture being applied (near objects).
There are more options for the min filter because it can potentially have mipmapping. However, it wouldn’t make sense to apply mipmapping to the mag filter since close-up objects don’t need it in the first place. Here’s a list of all the possible combinations and how they impact what is rendered (first constant in the left-most column is the near object filter [mag]; second constant is the far object filter [min]):
Filter Combination (MAG_FILTER/MIN_FILTER) | Bilinear Filtering (Near) | Bilinear Filtering (Far) | Mipmapping |
GL_NEAREST / GL_NEAREST_MIPMAP_NEAREST | Off | Off | Standard |
GL_NEAREST / GL_LINEAR_MIPMAP_NEAREST | Off | On | Standard |
GL_NEAREST / GL_NEAREST_MIPMAP_LINEAR | Off | Off | Use trilinear filtering |
GL_NEAREST / GL_LINEAR_MIPMAP_LINEAR | Off | On | Use trilinear filtering |
GL_NEAREST / GL_NEAREST | Off | Off | None |
GL_NEAREST / GL_LINEAR | Off | On | None |
GL_LINEAR / GL_NEAREST_MIPMAP_NEAREST | On | Off | Standard |
GL_LINEAR / GL_LINEAR_MIPMAP_NEAREST | On | On | Standard |
GL_LINEAR / GL_NEAREST_MIPMAP_LINEAR | On | Off | Use trilinear filtering |
GL_LINEAR / GL_LINEAR_MIPMAP_LINEAR | On | On | Use trilinear filtering |
GL_LINEAR / GL_NEAREST | On | Off | None |
GL_LINEAR / GL_LINEAR | On | On | None |
Not all of these combinations make sense to use. For example, there’s no point in applying GL_NEAREST with GL_LINEAR_MIPMAP_LINEAR because you’ll still see a sharp “break” between the trilinear filtered portion of a surface and the non-filtered portion. You should use whichever combination makes sense visually without compromising performance.
-Greg Dolley
*Get new posts automatically! Subscribe via RSS here . Want email updates instead? Click here.