in openGL, we can use glTexParameter() to set the Mag or Min filter parameter, but in actural implementation, how does it work? For example, if i set Mag = Linear and Min = Nearest, when drawing a pixel, how do i need to do to detect which mode to use? Is the filter’s unit a polygon or a pixel? Thx
If you want the nitty gritty, read the spec . Go to the rasterization->texturing
section and you’ll find more than you ever wanted to know.
I have read the spec but there are still few things that i don’t understand. How do i need to do to calculate the value du/dx. If i don’t have texture translation, u = kx. Could you give me an example to calculate the value?
Thank you very much.
I think for such answers a look at the source code of Mesa will surely help :
Graphics adapters draw each 2x2 pixel block in parallel to get the derivatives from neighboring pixels.
du/dx would then be proprotional (u from left pixels - u from right pixels)
du/dy = (v from upper pixel - u from lower pixels)
and the same for dv/dx etc.
it all boils down to know how much the texcoords are changing wrt screenspace and selecting your LOD accordingly.
Whether the minification or magnification filter is used depends on whether lamba (the texture level of detail) is less than or greater than a threshold value. The threshold is either 0.0 or 0.5 depending on the minification filter setting (see the spec).
lambda is computed from the texture coordinate derivatives (ds/dx, ds/dy, dt/dx, dt/dy, etc). The derivatives are easily computed during triangle rasterization. You don’t have to be concerned with that though.