15bd8deadSopenharmony_ciName
25bd8deadSopenharmony_ci
35bd8deadSopenharmony_ci    AMD_stencil_operation_extended
45bd8deadSopenharmony_ci
55bd8deadSopenharmony_ciName Strings
65bd8deadSopenharmony_ci
75bd8deadSopenharmony_ci    GL_AMD_stencil_operation_extended
85bd8deadSopenharmony_ci
95bd8deadSopenharmony_ciContact
105bd8deadSopenharmony_ci
115bd8deadSopenharmony_ci    Graham Sellers, AMD (graham.sellers 'at' amd.com)
125bd8deadSopenharmony_ci
135bd8deadSopenharmony_ciStatus
145bd8deadSopenharmony_ci
155bd8deadSopenharmony_ci    Shipping
165bd8deadSopenharmony_ci
175bd8deadSopenharmony_ciVersion
185bd8deadSopenharmony_ci
195bd8deadSopenharmony_ci    Last Modified Date:         01/11/2012
205bd8deadSopenharmony_ci    Author Revision:            4
215bd8deadSopenharmony_ci
225bd8deadSopenharmony_ciNumber
235bd8deadSopenharmony_ci
245bd8deadSopenharmony_ci    413
255bd8deadSopenharmony_ci
265bd8deadSopenharmony_ciDependencies
275bd8deadSopenharmony_ci
285bd8deadSopenharmony_ci    OpenGL 1.0 is required.
295bd8deadSopenharmony_ci
305bd8deadSopenharmony_ci    The definition of this extension is affected by EXT_stencil_wrap and
315bd8deadSopenharmony_ci    OpenGL 2.0.
325bd8deadSopenharmony_ci
335bd8deadSopenharmony_ci    This extension is written against the OpenGL Specification, Version 4.2
345bd8deadSopenharmony_ci    (Core Profile).
355bd8deadSopenharmony_ci
365bd8deadSopenharmony_ciOverview
375bd8deadSopenharmony_ci
385bd8deadSopenharmony_ci    Stencil buffers are special buffers that allow tests to be made against an
395bd8deadSopenharmony_ci    incoming value and action taken based on that value. The stencil buffer is
405bd8deadSopenharmony_ci    updated during rasterization, and the operation used to update the stencil
415bd8deadSopenharmony_ci    buffer is chosen based on whether the fragment passes the stencil test,
425bd8deadSopenharmony_ci    and if it does, whether it passes the depth test. Traditional OpenGL
435bd8deadSopenharmony_ci    includes support for several primitive operations, such as incrementing,
445bd8deadSopenharmony_ci    or clearing the content of the stencil buffer, or replacing it with a
455bd8deadSopenharmony_ci    specified reference value.
465bd8deadSopenharmony_ci
475bd8deadSopenharmony_ci    This extension adds support for an additional set of operations that may
485bd8deadSopenharmony_ci    be performed on the stencil buffer under each circumstance. Additionally,
495bd8deadSopenharmony_ci    this extension separates the value used as the source for stencil
505bd8deadSopenharmony_ci    operations from the reference value, allowing different values to be used
515bd8deadSopenharmony_ci    in the stencil test, and in the update of the stencil buffer.
525bd8deadSopenharmony_ci
535bd8deadSopenharmony_ciIP Status
545bd8deadSopenharmony_ci
555bd8deadSopenharmony_ci    None.
565bd8deadSopenharmony_ci
575bd8deadSopenharmony_ciNew Procedures and Functions
585bd8deadSopenharmony_ci
595bd8deadSopenharmony_ci    void StencilOpValueAMD(enum face, uint value);
605bd8deadSopenharmony_ci
615bd8deadSopenharmony_ciNew Tokens
625bd8deadSopenharmony_ci
635bd8deadSopenharmony_ci    Accepted by the <sfail>, <dpfail> and <dppass> parameters of StencilOp
645bd8deadSopenharmony_ci    and StencilOpSeparate:
655bd8deadSopenharmony_ci
665bd8deadSopenharmony_ci        SET_AMD                                     0x874A
675bd8deadSopenharmony_ci        AND                                         0x1501
685bd8deadSopenharmony_ci        XOR                                         0x1506
695bd8deadSopenharmony_ci        OR                                          0x1507
705bd8deadSopenharmony_ci        NOR                                         0x1508
715bd8deadSopenharmony_ci        EQUIV                                       0x1509
725bd8deadSopenharmony_ci        NAND                                        0x150E
735bd8deadSopenharmony_ci        REPLACE_VALUE_AMD                           0x874B
745bd8deadSopenharmony_ci
755bd8deadSopenharmony_ci    Accepted by the <param> parameter of GetIntegerv, GetFloatv, GetBooleanv
765bd8deadSopenharmony_ci    GetDoublev and GetInteger64v:
775bd8deadSopenharmony_ci
785bd8deadSopenharmony_ci        STENCIL_OP_VALUE_AMD                        0x874C
795bd8deadSopenharmony_ci        STENCIL_BACK_OP_VALUE_AMD                   0x874D
805bd8deadSopenharmony_ci
815bd8deadSopenharmony_ciAdditions to Chapter 2 of the OpenGL 4.2 (Core Profile) Specification
825bd8deadSopenharmony_ci(OpenGL Operation)
835bd8deadSopenharmony_ci
845bd8deadSopenharmony_ci    None.
855bd8deadSopenharmony_ci
865bd8deadSopenharmony_ciAdditions to Chapter 3 of the OpenGL 4.2 (Core Profile) Specification
875bd8deadSopenharmony_ci(Rasterization)
885bd8deadSopenharmony_ci
895bd8deadSopenharmony_ci    None.
905bd8deadSopenharmony_ci
915bd8deadSopenharmony_ciAdditions to Chapter 4 of the OpenGL 4.2 (Core Profile) Specification
925bd8deadSopenharmony_ci(Per-Fragment Operations and the Framebuffer)
935bd8deadSopenharmony_ci
945bd8deadSopenharmony_ci    Add to the functions introduced in Section 4.1.4 "Stencil Test", p.287
955bd8deadSopenharmony_ci
965bd8deadSopenharmony_ci        The stencil test is controlled with
975bd8deadSopenharmony_ci
985bd8deadSopenharmony_ci            <leave existing functions in place>
995bd8deadSopenharmony_ci            void StencilOpValueAMD(enum face, uint value);
1005bd8deadSopenharmony_ci
1015bd8deadSopenharmony_ci    Modify the paragraph beginning "StencilFuncSeparate and StencilOpSeparate
1025bd8deadSopenharmony_ci    take a <face> argument...", p.288
1035bd8deadSopenharmony_ci
1045bd8deadSopenharmony_ci        StencilFuncSeparate, StencilOpSeparate and StencilOpValue take a
1055bd8deadSopenharmony_ci    <face> argument which can be FRONT, BACK or FRONT_AND_BACK and indicates
1065bd8deadSopenharmony_ci    which set of state is affected.
1075bd8deadSopenharmony_ci
1085bd8deadSopenharmony_ci    Replace the second and third paragraphs on p.288, describing StencilOp and
1095bd8deadSopenharmony_ci    StencilOpSeparate with the following three paragraphs:
1105bd8deadSopenharmony_ci
1115bd8deadSopenharmony_ci        StencilOp and StencilOpSeparate take three arguments that indicate what
1125bd8deadSopenharmony_ci    happens to the stored stencil value if this or certain subsequent tests fail
1135bd8deadSopenharmony_ci    or pass. sfail indicates what action is taken if the stencil test fails.
1145bd8deadSopenharmony_ci    The inputs to the stencil operation are the stencil reference value, the
1155bd8deadSopenharmony_ci    stencil operation source value, and the current content of the stencil
1165bd8deadSopenharmony_ci    buffer. The accepted symbolic constants are KEEP, ZERO, SET_AMD, REPLACE,
1175bd8deadSopenharmony_ci    REPLACE_VALUE_AMD, INCR, DECR, INVERT, INCR_WRAP, DECR_WRAP, AND, XOR, OR,
1185bd8deadSopenharmony_ci    NOR, EQUIV, and NAND. These correspond to keeping the current value, setting
1195bd8deadSopenharmony_ci    to zero, setting to the maximum representable value, replacing with the
1205bd8deadSopenharmony_ci    reference value, replacing with the operation source value, incrementing by
1215bd8deadSopenharmony_ci    the operation source  value with saturation, decrementing by the operation
1225bd8deadSopenharmony_ci    source value with saturation, bitwise inverting it, incrementing by the
1235bd8deadSopenharmony_ci    operation source value without saturation, decrementing by the operation
1245bd8deadSopenharmony_ci    source value without saturation, logically ANDing the operation source
1255bd8deadSopenharmony_ci    value value with it, logically XORing the operation source value value with
1265bd8deadSopenharmony_ci    it, logically ORing the operation source value with it, logically NORing
1275bd8deadSopenharmony_ci    the operation source value with it, logically XORing the operation source
1285bd8deadSopenharmony_ci    value with it and replacing the it with the logically inverted result of
1295bd8deadSopenharmony_ci    that computation, and logically NANDing the operation source value with it,
1305bd8deadSopenharmony_ci    respectively.
1315bd8deadSopenharmony_ci
1325bd8deadSopenharmony_ci        For purposes of increment, decrement, the stencil bits are considered
1335bd8deadSopenharmony_ci    as an unsigned integer. Incrementing or decrementing with saturation clamps
1345bd8deadSopenharmony_ci    the stencil value between 0 and the maximum representable value.
1355bd8deadSopenharmony_ci    Incrementing without saturation will wrap such that incrementing the
1365bd8deadSopenharmony_ci    content of the stencil buffer in such a way that overflow occurs will cause
1375bd8deadSopenharmony_ci    the result of the operation to be masked by the number of bits representable
1385bd8deadSopenharmony_ci    by the stencil buffer. Decrementing without saturation will wrap such that
1395bd8deadSopenharmony_ci    decrementing the content of the stencil buffer in a manner such that the
1405bd8deadSopenharmony_ci    result of the subtraction would be negative causes the two's complement
1415bd8deadSopenharmony_ci    result to be interpreted as an unsigned integer and masked to the number of
1425bd8deadSopenharmony_ci    bits representable by the stencil buffer.
1435bd8deadSopenharmony_ci
1445bd8deadSopenharmony_ci        The stencil operation source value is set by calling StencilOpValueAMD
1455bd8deadSopenharmony_ci    with <face> set to GL_FRONT, GL_BACK or GL_FRONT_AND_BACK, and <value> set
1465bd8deadSopenharmony_ci    to the new value of the stencil operation source value.
1475bd8deadSopenharmony_ci
1485bd8deadSopenharmony_ci    Modify the paragraph beginning "If the stencil test fails, the ... ", p.288
1495bd8deadSopenharmony_ci    as follows:
1505bd8deadSopenharmony_ci
1515bd8deadSopenharmony_ci        If the stencil test fails, the incoming fragment is discarded. The state
1525bd8deadSopenharmony_ci    required consists of the most recent values passed to StencilFunc or
1535bd8deadSopenharmony_ci    StencilFuncSeparate, to StencilOp or StencilOpSeparate, and to
1545bd8deadSopenharmony_ci    StencilOpValueAMD, and a bit indicating whether stencil testing is enabled
1555bd8deadSopenharmony_ci    or disabled. In the initial state, stenciling is disabled, the front and
1565bd8deadSopenharmony_ci    back reference values are both zero, the front and back stencil comparison
1575bd8deadSopenharmony_ci    functions are both ALWAYS, the front and back stencil mask are both set to
1585bd8deadSopenharmony_ci    the value 2^S - 1, where S is greater than or equal to the number of bits
1595bd8deadSopenharmony_ci    in the deepest buffer supported by the GL implementation, and the front
1605bd8deadSopenharmony_ci    and back stencil operation values are both 1. Initially, all three front
1615bd8deadSopenharmony_ci    and back stencil operations are KEEP.
1625bd8deadSopenharmony_ci
1635bd8deadSopenharmony_ciAdditions to Chapter 5 of the OpenGL 4.2 (Core Profile) Specification
1645bd8deadSopenharmony_ci(Special Functions)
1655bd8deadSopenharmony_ci
1665bd8deadSopenharmony_ci    None.
1675bd8deadSopenharmony_ci
1685bd8deadSopenharmony_ciAdditions to Chapter 6 of the OpenGL 4.2 (Core Profile) Specification
1695bd8deadSopenharmony_ci(State and State Requests)
1705bd8deadSopenharmony_ci
1715bd8deadSopenharmony_ci    None.
1725bd8deadSopenharmony_ci
1735bd8deadSopenharmony_ciAdditions to the AGL/GLX/WGL Specifications
1745bd8deadSopenharmony_ci
1755bd8deadSopenharmony_ci    None.
1765bd8deadSopenharmony_ci
1775bd8deadSopenharmony_ciGLX Protocol
1785bd8deadSopenharmony_ci
1795bd8deadSopenharmony_ci    None.
1805bd8deadSopenharmony_ci
1815bd8deadSopenharmony_ciErrors
1825bd8deadSopenharmony_ci
1835bd8deadSopenharmony_ci    INVALID_ENUM is generated by StencilOpValueAMD if <face> is not FRONT,
1845bd8deadSopenharmony_ci    BACK or FRONT_AND_BACK.
1855bd8deadSopenharmony_ci
1865bd8deadSopenharmony_ciNew State
1875bd8deadSopenharmony_ci
1885bd8deadSopenharmony_ci    Modify Table 6.20 "Pixel Operations", p.394:
1895bd8deadSopenharmony_ci
1905bd8deadSopenharmony_ci    +--------------------------------+----------+---------------+-----------+-------------------------------------------+--------+
1915bd8deadSopenharmony_ci    |                                |          | Get           | Initial   |                                           |        |
1925bd8deadSopenharmony_ci    | Get Value                      | Type     | Command       | Value     | Description                               | Sec.   |
1935bd8deadSopenharmony_ci    +--------------------------------+----------+---------------+-----------+-------------------------------------------+--------+
1945bd8deadSopenharmony_ci    | STENCIL_FAIL                   | Z16      | GetIntegerv   | KEEP      | Front stencil fail action                 | 4.1.4  |
1955bd8deadSopenharmony_ci    | STENCIL_PASS_DEPTH_FAIL        | Z16      | GetIntegerv   | KEEP      | Front stencil depth buffer fail action    | 4.1.4  |
1965bd8deadSopenharmony_ci    | STENCIL_PASS_DEPTH_PASS        | Z16      | GetIntegerv   | KEEP      | Front stencil depth buffer pass action    | 4.1.4  |
1975bd8deadSopenharmony_ci    | STENCIL_BACK_FAIL              | Z16      | GetIntegerv   | KEEP      | Back stencil fail action                  | 4.1.4  |
1985bd8deadSopenharmony_ci    | STENCIL_BACK_PASS_DEPTH_FAIL   | Z16      | GetIntegerv   | KEEP      | Back stencil depth buffer fail action     | 4.1.4  |
1995bd8deadSopenharmony_ci    | STENCIL_BACK_PASS_DEPTH_PASS   | Z16      | GetIntegerv   | KEEP      | Back stencil depth buffer pass action     | 4.1.4  |
2005bd8deadSopenharmony_ci    | STENCIL_OP_VALUE_AMD           | Z+       | GetIntegerv   | 1         | Front stencil operation value             | 4.1.4  |
2015bd8deadSopenharmony_ci    | STENCIL_BACK_OP_VALUE_AMD      | Z+       | GetIngeterv   | 1         | Back stencil operation value              | 4.1.4  |
2025bd8deadSopenharmony_ci    +--------------------------------+----------+---------------+-----------+-------------------------------------------+--------+
2035bd8deadSopenharmony_ci
2045bd8deadSopenharmony_ci    NOTE: The existing STENCIL{_BACK}_{*} enumerants  change have changed from Z8 to Z16.
2055bd8deadSopenharmony_ci
2065bd8deadSopenharmony_ciDependencies on EXT_stencil_wrap
2075bd8deadSopenharmony_ci
2085bd8deadSopenharmony_ci    If EXT_stencil_wrap is not supported, remove references to INCR_WRAP and
2095bd8deadSopenharmony_ci    DECR_WRAP. Also, change the definition of the STENCIL_{*} state to Z14
2105bd8deadSopenharmony_ci    rather than Z16.
2115bd8deadSopenharmony_ci
2125bd8deadSopenharmony_ciDependencies on OpenGL 2.0
2135bd8deadSopenharmony_ci
2145bd8deadSopenharmony_ci    If the GL version is less than 2.0, remove all references to
2155bd8deadSopenharmony_ci    StencilOpSeparate. Furthermore, the <face> parameter to StencilOpValueAMD
2165bd8deadSopenharmony_ci    must be FRONT_AND_BACK, otherwise an INVALID_ENUM error will be generated.
2175bd8deadSopenharmony_ci
2185bd8deadSopenharmony_ciIssues
2195bd8deadSopenharmony_ci
2205bd8deadSopenharmony_ci    1) Is the stencil mask applied to the stencil operation value?
2215bd8deadSopenharmony_ci
2225bd8deadSopenharmony_ci    RESOLVED: No, only to the reference and current values before the test.
2235bd8deadSopenharmony_ci    The stencil operation is carried out on the full value. The stencil write
2245bd8deadSopenharmony_ci    mask is applied to the result during stencil buffer update, however.
2255bd8deadSopenharmony_ci
2265bd8deadSopenharmony_ci    2) Is this really backwards compatible? Does it break OpenGL?
2275bd8deadSopenharmony_ci
2285bd8deadSopenharmony_ci    RESOLVED: Yes, this is backwards compatible and does not break anything.
2295bd8deadSopenharmony_ci    The INCR{_WRAP} and DECR{_WRAP} operations have been semantically redefined
2305bd8deadSopenharmony_ci    to be generalized add and subtract operations. However, the stencil
2315bd8deadSopenharmony_ci    operation source value is used in the addition operation and its default is
2325bd8deadSopenharmony_ci    1. Therefore, in the default state (assuming the stencil operation source
2335bd8deadSopenharmony_ci    value is not changed), INCR and DECR still increment and decrement by 1.
2345bd8deadSopenharmony_ci
2355bd8deadSopenharmony_ci    3) What if I want to apply a logical operation with the stencil reference
2365bd8deadSopenharmony_ci    value and the current stencil buffer contents?
2375bd8deadSopenharmony_ci
2385bd8deadSopenharmony_ci    RESOLVED: Set the stencil operation source value to the same thing as the
2395bd8deadSopenharmony_ci    stencil reference value.
2405bd8deadSopenharmony_ci
2415bd8deadSopenharmony_ciRevision History
2425bd8deadSopenharmony_ci
2435bd8deadSopenharmony_ci    Rev.    Date      Author    Changes
2445bd8deadSopenharmony_ci    ----  ----------  --------  -----------------------------------------
2455bd8deadSopenharmony_ci    4     01/11/2012  gsellers  Update for OpenGL 4.2. Prepare for posting.
2465bd8deadSopenharmony_ci    3     12/17/2010  yunzhang  update enum definitions
2475bd8deadSopenharmony_ci    2     06/10/2010  gsellers  Add separate stencil op value. Add issues.
2485bd8deadSopenharmony_ci    1     06/08/2010  gsellers  Initial revision
249