I'm reading this tutorial and trying to understand how the depth testing works but I'm not sure I understood it correctly.
Lets say that we have the default comparison method (LESS). Then what is the algorithm that determines if a fragment will be discarded or get draw?
Is it something like this?:
bool DepthTest()
{
//Depth Testing Passes.
if ( depth_buffer[i] < currentFragment[i].z )
{
depth_buffer[i] = currentFragment[i].z;
return true;
}
//Fails.
else
return false;
}
Also I have a hard time figuring out how does openGL for each fragment know's with what value of the depth buffer to compare with (as you can see i used an i index but I didn't determined what this i is). Does it compare each fragment's z value with all the values inside the depth buffer?
The tutorial which I'm reading does not make this enough clear for me.