<refentry id="glStencilFuncSeparate">
    <refmeta>
        <refmetainfo>
            <copyright>
                <year>1991-2006</year>
                <holder>Silicon Graphics, Inc.</holder>
            </copyright>
        </refmetainfo>
        <refentrytitle>glStencilFuncSeparate</refentrytitle>
        <manvolnum>3G</manvolnum>
    </refmeta>
    <refnamediv>
        <refname>glStencilFuncSeparate</refname>
        <refpurpose>set front and/or back function and reference value for stencil testing</refpurpose>
    </refnamediv>
    <!-- eqn: ignoring delim $$ -->
    <refsynopsisdiv><title>C Specification</title>
        <funcsynopsis>
            <funcprototype>
                <funcdef>void <function moreinfo="none">glStencilFuncSeparate</function></funcdef>
                <paramdef>GLenum <parameter moreinfo="none">face</parameter></paramdef>
                <paramdef>GLenum <parameter moreinfo="none">func</parameter></paramdef>
                <paramdef>GLint <parameter moreinfo="none">ref</parameter></paramdef>
                <paramdef>GLuint <parameter moreinfo="none">mask</parameter></paramdef>
            </funcprototype>
        </funcsynopsis>
    </refsynopsisdiv>
    <refsect1 id="parameters"><title>Parameters</title>
        <variablelist>
        <varlistentry>
            <term><parameter moreinfo="none">face</parameter></term>
            <listitem>
                <para>
                    Specifies whether front and/or back stencil state is updated.
                    Three symbolic constants are valid:
                    <constant>GL_FRONT</constant>,
                    <constant>GL_BACK</constant>, and
                    <constant>GL_FRONT_AND_BACK</constant>.
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter moreinfo="none">func</parameter></term>
            <listitem>
                <para>
                    Specifies the test function.
                    Eight symbolic constants are valid:
                    <constant>GL_NEVER</constant>,
                    <constant>GL_LESS</constant>,
                    <constant>GL_LEQUAL</constant>,
                    <constant>GL_GREATER</constant>,
                    <constant>GL_GEQUAL</constant>,
                    <constant>GL_EQUAL</constant>,
                    <constant>GL_NOTEQUAL</constant>, and
                    <constant>GL_ALWAYS</constant>. The initial value is <constant>GL_ALWAYS</constant>.
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter moreinfo="none">ref</parameter></term>
            <listitem>
                <para>
                    Specifies the reference value for the stencil test.
                    <parameter moreinfo="none">ref</parameter> is clamped to the range 
                    <inlineequation><math>
                        <!-- eqn: [0, 2 sup n - 1]:-->
                        <mfenced open="[" close="]">
                            <mn>0</mn>
                            <mrow>
                                <msup><mn>2</mn>
                                <mi mathvariant="italic">n</mi>
                                </msup>
                                <mo>-</mo>
                                <mn>1</mn>
                            </mrow>
                        </mfenced>
                    </math></inlineequation>,
                    where 
                    <inlineequation><math><mi mathvariant="italic">n</mi></math></inlineequation>
                    is the number of bitplanes in the stencil buffer. The
                    initial value is 0.
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter moreinfo="none">mask</parameter></term>
            <listitem>
                <para>
                    Specifies a mask that is ANDed with both the reference value
                    and the stored stencil value when the test is done. The initial value
                    is all 1's.
                </para>
            </listitem>
        </varlistentry>
        </variablelist>
    </refsect1>
    <refsect1 id="description"><title>Description</title>
        <para>
            Stenciling,
            like depth-buffering,
            enables and disables drawing on a per-pixel basis.
            You draw into the stencil planes using GL drawing primitives,
            then render geometry and images,
            using the stencil planes to mask out portions of the screen.
            Stenciling is typically used in multipass rendering algorithms
            to achieve special effects,
            such as decals,
            outlining,
            and constructive solid geometry rendering.
        </para>
        <para>
            The stencil test conditionally eliminates a pixel based on the outcome
            of a comparison between the reference value
            and the value in the stencil buffer.
            To enable and disable the test, call <citerefentry><refentrytitle>glEnable</refentrytitle></citerefentry> and <citerefentry><refentrytitle>glDisable</refentrytitle></citerefentry>
            with argument <constant>GL_STENCIL_TEST</constant>.
            To specify actions based on the outcome of the stencil test, call
            <citerefentry><refentrytitle>glStencilOp</refentrytitle></citerefentry> or 
            <citerefentry><refentrytitle>glStencilOpSeparate</refentrytitle></citerefentry>.
        </para>
        <para>
            There can be two separate sets of <parameter moreinfo="none">func</parameter>, <parameter moreinfo="none">ref</parameter>, and 
            <parameter moreinfo="none">mask</parameter> parameters; one affects back-facing polygons, and the other
            affects front-facing polygons as well as other non-polygon primitives. 
            <citerefentry><refentrytitle>glStencilFunc</refentrytitle></citerefentry> sets both front
            and back stencil state to the same values, as if 
            <citerefentry><refentrytitle>glStencilFuncSeparate</refentrytitle></citerefentry> were called
            with <parameter moreinfo="none">face</parameter> set to <constant>GL_FRONT_AND_BACK</constant>.
        </para>
        <para>
            <parameter moreinfo="none">func</parameter> is a symbolic constant that determines the stencil comparison function.
            It accepts one of eight values,
            shown in the following list.
            <parameter moreinfo="none">ref</parameter> is an integer reference value that is used in the stencil comparison.
            It is clamped to the range 
            <inlineequation><math>
                <!-- eqn: [0, 2 sup n - 1]:-->
                <mfenced open="[" close="]">
                    <mn>0</mn>
                    <mrow>
                        <msup><mn>2</mn>
                        <mi mathvariant="italic">n</mi>
                        </msup>
                        <mo>-</mo>
                        <mn>1</mn>
                    </mrow>
                </mfenced>
            </math></inlineequation>,
            where 
            <inlineequation><math><mi mathvariant="italic">n</mi></math></inlineequation>
            is the number of bitplanes in the stencil buffer.
            <parameter moreinfo="none">mask</parameter> is bitwise ANDed with both the reference value
            and the stored stencil value,
            with the ANDed values participating in the comparison.
        </para>
        <para>
            If <emphasis>stencil</emphasis> represents the value stored in the corresponding
            stencil buffer location,
            the following list shows the effect of each comparison function
            that can be specified by <parameter moreinfo="none">func</parameter>.
            Only if the comparison succeeds is the pixel passed through
            to the next stage in the rasterization process
            (see <citerefentry><refentrytitle>glStencilOp</refentrytitle></citerefentry>).
            All tests treat <emphasis>stencil</emphasis> values as unsigned integers in the range
            <inlineequation><math>
                <!-- eqn: [0, 2 sup n - 1]:-->
                <mfenced open="[" close="]">
                    <mn>0</mn>
                    <mrow>
                        <msup><mn>2</mn>
                        <mi mathvariant="italic">n</mi>
                        </msup>
                        <mo>-</mo>
                        <mn>1</mn>
                    </mrow>
                </mfenced>
            </math></inlineequation>,
            where 
            <inlineequation><math><mi mathvariant="italic">n</mi></math></inlineequation>
            is the number of bitplanes in the stencil buffer.
        </para>
        <para>
            The following values are accepted by <parameter moreinfo="none">func</parameter>:
        </para>
        <variablelist>
            <varlistentry>
                <term><constant>GL_NEVER</constant></term>
                <listitem>
                    <para>
                        Always fails.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term><constant>GL_LESS</constant></term>
                <listitem>
                    <para>
                        Passes if ( <parameter moreinfo="none">ref</parameter> &amp; <parameter moreinfo="none">mask</parameter> ) &lt; ( <emphasis>stencil</emphasis> &amp; <parameter moreinfo="none">mask</parameter> ).
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term><constant>GL_LEQUAL</constant></term>
                <listitem>
                    <para>
                        Passes if ( <parameter moreinfo="none">ref</parameter> &amp; <parameter moreinfo="none">mask</parameter> ) &lt;= ( <emphasis>stencil</emphasis> &amp; <parameter moreinfo="none">mask</parameter> ).
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term><constant>GL_GREATER</constant></term>
                <listitem>
                    <para>
                        Passes if ( <parameter moreinfo="none">ref</parameter> &amp; <parameter moreinfo="none">mask</parameter> ) &gt; ( <emphasis>stencil</emphasis> &amp; <parameter moreinfo="none">mask</parameter> ).
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term><constant>GL_GEQUAL</constant></term>
                <listitem>
                    <para>
                        Passes if ( <parameter moreinfo="none">ref</parameter> &amp; <parameter moreinfo="none">mask</parameter> ) &gt;= ( <emphasis>stencil</emphasis> &amp; <parameter moreinfo="none">mask</parameter> ).
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term><constant>GL_EQUAL</constant></term>
                <listitem>
                    <para>
                        Passes if ( <parameter moreinfo="none">ref</parameter> &amp; <parameter moreinfo="none">mask</parameter> ) = ( <emphasis>stencil</emphasis> &amp; <parameter moreinfo="none">mask</parameter> ).
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term><constant>GL_NOTEQUAL</constant></term>
                <listitem>
                    <para>
                        Passes if ( <parameter moreinfo="none">ref</parameter> &amp; <parameter moreinfo="none">mask</parameter> ) != ( <emphasis>stencil</emphasis> &amp; <parameter moreinfo="none">mask</parameter> ).
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term><constant>GL_ALWAYS</constant></term>
                <listitem>
                    <para>
                        Always passes.
                    </para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsect1>
    <refsect1 id="notes"><title>Notes</title>
	<para>
            <function moreinfo="none">glStencilFuncSeparate</function> is available only if
            the GL version is 2.0 or greater.
        </para>
        <para>
            Initially, the stencil test is disabled.
            If there is no stencil buffer,
            no stencil modification can occur and it is as if
            the stencil test always passes.
        </para>
    </refsect1>
    <refsect1 id="errors"><title>Errors</title>
        <para>
            <constant>GL_INVALID_ENUM</constant> is generated if <parameter moreinfo="none">func</parameter> is not one of the eight
            accepted values.
        </para>
        <para>
            <constant>GL_INVALID_OPERATION</constant> is generated if <function moreinfo="none">glStencilFuncSeparate</function>
            is executed between the execution of <citerefentry><refentrytitle>glBegin</refentrytitle></citerefentry>
            and the corresponding execution of <citerefentry><refentrytitle>glEnd</refentrytitle></citerefentry>.
        </para>
    </refsect1>
    <refsect1 id="associatedgets"><title>Associated Gets</title>
        <para>
            <citerefentry><refentrytitle>glGet</refentrytitle></citerefentry> with argument 
            <constant>GL_STENCIL_FUNC</constant>, <constant>GL_STENCIL_VALUE_MASK</constant>, 
            <constant>GL_STENCIL_REF</constant>, <constant>GL_STENCIL_BACK_FUNC</constant>, 
            <constant>GL_STENCIL_BACK_VALUE_MASK</constant>, <constant>GL_STENCIL_BACK_REF</constant>, 
            or <constant>GL_STENCIL_BITS</constant>
        </para>
        <para>
            <citerefentry><refentrytitle>glIsEnabled</refentrytitle></citerefentry> with argument <constant>GL_STENCIL_TEST</constant>
        </para>
    </refsect1>
    <refsect1 id="seealso"><title>See Also</title>
        <para>
            <citerefentry><refentrytitle>glAlphaFunc</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glBlendFunc</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glDepthFunc</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glEnable</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glLogicOp</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glStencilFunc</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glStencilMask</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glStencilMaskSeparate</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glStencilOp</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glStencilOpSeparate</refentrytitle></citerefentry>
        </para>
    </refsect1>
    
</refentry>
