Added support for stencil tests

For feature request #1081