0
\$\begingroup\$

So the order between them is important?Or the order just depends on hardware?I have no idea which one needs to come first.

\$\endgroup\$
  • \$\begingroup\$ Can you give an example where the order in which these are performed would result in an observable difference in the output? \$\endgroup\$ – DMGregory Mar 31 at 15:31
1
\$\begingroup\$

The OpenGL specification defines these as happening in the following order:

  • Alpha test
  • Stencil test
  • Depth test

However, this order may not be strictly applied by all hardware or APIs. One example is if using an API that does not have alpha test, you would need to emulate it with discard instructions in your pixel shader. In that case it would still come first, but it would happen at a different (and earlier) pipeline stage - potentially before other operations that come between.

Another, more common, example is early depth testing. Depending on the combination of other states, modern hardware can often do a depth test before the pixel shader stage rather than after it, which can be a significant performance win. In that case the depth test comes much earlier - before the others you're interested in - but if the result would be the same as if it had run later, this is OK.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.