15bd8deadSopenharmony_ciName 25bd8deadSopenharmony_ci 35bd8deadSopenharmony_ci EXT_stencil_two_side 45bd8deadSopenharmony_ci 55bd8deadSopenharmony_ciName Strings 65bd8deadSopenharmony_ci 75bd8deadSopenharmony_ci GL_EXT_stencil_two_side 85bd8deadSopenharmony_ci 95bd8deadSopenharmony_ciContact 105bd8deadSopenharmony_ci 115bd8deadSopenharmony_ci Mark J. Kilgard, NVIDIA Corporation (mjk 'at' nvidia.com) 125bd8deadSopenharmony_ci 135bd8deadSopenharmony_ciNotice 145bd8deadSopenharmony_ci 155bd8deadSopenharmony_ci Copyright NVIDIA Corporation, 2001-2002. 165bd8deadSopenharmony_ci 175bd8deadSopenharmony_ciStatus 185bd8deadSopenharmony_ci 195bd8deadSopenharmony_ci Implemented in CineFX (NV30) Emulation driver, August 2002. 205bd8deadSopenharmony_ci Shipping in Release 40 NVIDIA driver for CineFX hardware, January 2003. 215bd8deadSopenharmony_ci 225bd8deadSopenharmony_ciVersion 235bd8deadSopenharmony_ci 245bd8deadSopenharmony_ci Last Modified Date: 09/15/2005 255bd8deadSopenharmony_ci Revision: 2 265bd8deadSopenharmony_ci 275bd8deadSopenharmony_ciNumber 285bd8deadSopenharmony_ci 295bd8deadSopenharmony_ci 268 305bd8deadSopenharmony_ci 315bd8deadSopenharmony_ciDependencies 325bd8deadSopenharmony_ci 335bd8deadSopenharmony_ci Written based on the OpenGL 1.3 specification. 345bd8deadSopenharmony_ci 355bd8deadSopenharmony_ci NV_packed_depth_stencil affects the definition of this extension. 365bd8deadSopenharmony_ci 375bd8deadSopenharmony_ci OpenGL 2.0 affects the definition of this extension. 385bd8deadSopenharmony_ci 395bd8deadSopenharmony_ciOverview 405bd8deadSopenharmony_ci 415bd8deadSopenharmony_ci This extension provides two-sided stencil testing where the 425bd8deadSopenharmony_ci stencil-related state (stencil operations, reference value, compare 435bd8deadSopenharmony_ci mask, and write mask) may be different for front- and back-facing 445bd8deadSopenharmony_ci polygons. Two-sided stencil testing may improve the performance 455bd8deadSopenharmony_ci of stenciled shadow volume and Constructive Solid Geometry (CSG) 465bd8deadSopenharmony_ci rendering algorithms. 475bd8deadSopenharmony_ci 485bd8deadSopenharmony_ciIssues 495bd8deadSopenharmony_ci 505bd8deadSopenharmony_ci Is this sufficient for shadow volume stencil update in a single pass? 515bd8deadSopenharmony_ci 525bd8deadSopenharmony_ci RESOLUTION: Yes. 535bd8deadSopenharmony_ci 545bd8deadSopenharmony_ci An application that wishes to increment the stencil value for 555bd8deadSopenharmony_ci rasterized depth-test passing fragments of front-facing polygons and 565bd8deadSopenharmony_ci decrement the stencil value for rasterized fragments of depth-test 575bd8deadSopenharmony_ci passing back-facing polygons in a single pass can use the following 585bd8deadSopenharmony_ci configuration: 595bd8deadSopenharmony_ci 605bd8deadSopenharmony_ci glDepthMask(0); 615bd8deadSopenharmony_ci glColorMask(0,0,0,0); 625bd8deadSopenharmony_ci glDisable(GL_CULL_FACE); 635bd8deadSopenharmony_ci glEnable(GL_STENCIL_TEST); 645bd8deadSopenharmony_ci glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT); 655bd8deadSopenharmony_ci 665bd8deadSopenharmony_ci glActiveStencilFaceEXT(GL_BACK); 675bd8deadSopenharmony_ci glStencilOp(GL_KEEP, // stencil test fail 685bd8deadSopenharmony_ci GL_KEEP, // depth test fail 695bd8deadSopenharmony_ci GL_DECR_WRAP_EXT); // depth test pass 705bd8deadSopenharmony_ci glStencilMask(~0); 715bd8deadSopenharmony_ci glStencilFunc(GL_ALWAYS, 0, ~0); 725bd8deadSopenharmony_ci 735bd8deadSopenharmony_ci glActiveStencilFaceEXT(GL_FRONT); 745bd8deadSopenharmony_ci glStencilOp(GL_KEEP, // stencil test fail 755bd8deadSopenharmony_ci GL_KEEP, // depth test fail 765bd8deadSopenharmony_ci GL_INCR_WRAP_EXT); // depth test pass 775bd8deadSopenharmony_ci glStencilMask(~0); 785bd8deadSopenharmony_ci glStencilFunc(GL_ALWAYS, 0, ~0); 795bd8deadSopenharmony_ci 805bd8deadSopenharmony_ci renderShadowVolumePolygons(); 815bd8deadSopenharmony_ci 825bd8deadSopenharmony_ci Notice the use of EXT_stencil_wrap to avoid saturating decrements 835bd8deadSopenharmony_ci losing the shadow volume count. An alternative, using the 845bd8deadSopenharmony_ci conventional GL_INCR and GL_DECR operations, is to clear the stencil 855bd8deadSopenharmony_ci buffer to one half the stencil buffer value range, say 128 for an 865bd8deadSopenharmony_ci 8-bit stencil buffer. In the case, a pixel is "in shadow" if the 875bd8deadSopenharmony_ci final stencil value is greater than 128 and "out of shadow" if the 885bd8deadSopenharmony_ci final stencil value is 128. This does still create a potential 895bd8deadSopenharmony_ci for stencil value overflow if the stencil value saturates due 905bd8deadSopenharmony_ci to an increment or decrement. However saturation is less likely 915bd8deadSopenharmony_ci with two-sided stencil testing than the conventional two-pass 925bd8deadSopenharmony_ci approach because front- and back-facing polygons are mixed together, 935bd8deadSopenharmony_ci rather than processing batches of front-facing then back-facing 945bd8deadSopenharmony_ci polygons. 955bd8deadSopenharmony_ci 965bd8deadSopenharmony_ci Contrast the two-sided stencil testing approach with the more 975bd8deadSopenharmony_ci or less equivalent approach using facingness-independent stencil 985bd8deadSopenharmony_ci testing: 995bd8deadSopenharmony_ci 1005bd8deadSopenharmony_ci glDepthMask(0); 1015bd8deadSopenharmony_ci glColorMask(0,0,0,0); 1025bd8deadSopenharmony_ci glEnable(GL_CULL_FACE); 1035bd8deadSopenharmony_ci glEnable(GL_STENCIL_TEST); 1045bd8deadSopenharmony_ci 1055bd8deadSopenharmony_ci glStencilMask(~0); 1065bd8deadSopenharmony_ci glStencilFunc(GL_ALWAYS, 0, ~0); 1075bd8deadSopenharmony_ci 1085bd8deadSopenharmony_ci // Increment for front faces 1095bd8deadSopenharmony_ci glCullFace(GL_BACK); 1105bd8deadSopenharmony_ci glStencilOp(GL_KEEP, // stencil test fail 1115bd8deadSopenharmony_ci GL_KEEP, // depth test fail 1125bd8deadSopenharmony_ci GL_INCR); // depth test pass 1135bd8deadSopenharmony_ci 1145bd8deadSopenharmony_ci renderShadowVolumePolygons(); 1155bd8deadSopenharmony_ci 1165bd8deadSopenharmony_ci // Decrement for back faces 1175bd8deadSopenharmony_ci glCullFace(GL_FRONT); 1185bd8deadSopenharmony_ci glStencilOp(GL_KEEP, // stencil test fail 1195bd8deadSopenharmony_ci GL_KEEP, // depth test fail 1205bd8deadSopenharmony_ci GL_DECR); // depth test pass 1215bd8deadSopenharmony_ci 1225bd8deadSopenharmony_ci renderShadowVolumePolygons(); 1235bd8deadSopenharmony_ci 1245bd8deadSopenharmony_ci Notice that all the render work implicit 1255bd8deadSopenharmony_ci in renderShadowVolumePolygons is performed twice with the 1265bd8deadSopenharmony_ci conventional approach, but only once with the two-sided stencil 1275bd8deadSopenharmony_ci testing approach. 1285bd8deadSopenharmony_ci 1295bd8deadSopenharmony_ci Should there be just front and back stencil test state, or should 1305bd8deadSopenharmony_ci the stencil write mask also have a front and back state? 1315bd8deadSopenharmony_ci 1325bd8deadSopenharmony_ci RESOLUTION: Both the stencil test and stencil write mask state 1335bd8deadSopenharmony_ci should have front and back versions. 1345bd8deadSopenharmony_ci 1355bd8deadSopenharmony_ci The shadow volume application for two-sided stencil testing does 1365bd8deadSopenharmony_ci not require differing front and back versions of the stencil write 1375bd8deadSopenharmony_ci mask, but we anticipate other applications where front and back 1385bd8deadSopenharmony_ci write masks may be useful. 1395bd8deadSopenharmony_ci 1405bd8deadSopenharmony_ci For example, it may be useful to draw a convex polyhedra such that 1415bd8deadSopenharmony_ci (assuming the stencil bufer is cleared to the binary value 1010): 1425bd8deadSopenharmony_ci 1435bd8deadSopenharmony_ci 1) front-facing polygons that pass the depth test set stencil bit 0 1445bd8deadSopenharmony_ci 1455bd8deadSopenharmony_ci 2) front-facing polygons that fail the depth test zero stencil bit 1 1465bd8deadSopenharmony_ci 1475bd8deadSopenharmony_ci 3) back-facing polygons that pass the depth test set stencil bit 2 1485bd8deadSopenharmony_ci 1495bd8deadSopenharmony_ci 4) back-facing polygons that fail the depth test zero stencil bit 3 1505bd8deadSopenharmony_ci 1515bd8deadSopenharmony_ci This could be accomplished in a single rendering pass using: 1525bd8deadSopenharmony_ci 1535bd8deadSopenharmony_ci glStencilMask(~0); 1545bd8deadSopenharmony_ci glStencilClear(0xA); 1555bd8deadSopenharmony_ci glClear(GL_STENCIL_BUFFER_BIT); 1565bd8deadSopenharmony_ci 1575bd8deadSopenharmony_ci glDepthMask(0); 1585bd8deadSopenharmony_ci glColorMask(0,0,0,0); 1595bd8deadSopenharmony_ci glDisable(GL_CULL_FACE); 1605bd8deadSopenharmony_ci glEnable(GL_STENCIL_TEST); 1615bd8deadSopenharmony_ci glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT); 1625bd8deadSopenharmony_ci 1635bd8deadSopenharmony_ci glActiveStencilFaceEXT(GL_BACK); 1645bd8deadSopenharmony_ci glStencilOp(GL_KEEP, // stencil test fail 1655bd8deadSopenharmony_ci GL_ZERO, // depth test fail 1665bd8deadSopenharmony_ci GL_REPLACE); // depth test pass 1675bd8deadSopenharmony_ci glStencilMask(0xC); 1685bd8deadSopenharmony_ci glStencilFunc(GL_ALWAYS, 0x4, ~0); 1695bd8deadSopenharmony_ci 1705bd8deadSopenharmony_ci glActiveStencilFaceEXT(GL_FRONT); 1715bd8deadSopenharmony_ci glStencilOp(GL_KEEP, // stencil test fail 1725bd8deadSopenharmony_ci GL_ZERO, // depth test fail 1735bd8deadSopenharmony_ci GL_REPLACE); // depth test pass 1745bd8deadSopenharmony_ci glStencilMask(0x3); 1755bd8deadSopenharmony_ci glStencilFunc(GL_ALWAYS, 0x1, ~0); 1765bd8deadSopenharmony_ci 1775bd8deadSopenharmony_ci renderConvexPolyhedra(); 1785bd8deadSopenharmony_ci 1795bd8deadSopenharmony_ci Is there a performance advantage to using two-sided stencil testing? 1805bd8deadSopenharmony_ci 1815bd8deadSopenharmony_ci RESOLUTION: It depends. 1825bd8deadSopenharmony_ci 1835bd8deadSopenharmony_ci In a fill-rate limited situation, rendering front-facing primitives, 1845bd8deadSopenharmony_ci then back-facing primitives in two passes will generate the same 1855bd8deadSopenharmony_ci number of rasterized fragments as rendering front- and back-facing 1865bd8deadSopenharmony_ci primitives in a single pass. 1875bd8deadSopenharmony_ci 1885bd8deadSopenharmony_ci However, in other situations that are CPU-limited, 1895bd8deadSopenharmony_ci transform-limited, or setup-limited, two-sided stencil testing can 1905bd8deadSopenharmony_ci be faster than the conventional two-pass face culling rendering 1915bd8deadSopenharmony_ci approaches. For example, if a lengthy vertex program is executed 1925bd8deadSopenharmony_ci for every shadow volume vertex, rendering the shadow volume with 1935bd8deadSopenharmony_ci a single two-sided stencil testing pass is advantageous. 1945bd8deadSopenharmony_ci 1955bd8deadSopenharmony_ci Often applications using stencil shadow volume techniques require 1965bd8deadSopenharmony_ci substantial CPU resources to determine potential silhouette 1975bd8deadSopenharmony_ci boundaries to project shadow volumes from. If the shadow volume 1985bd8deadSopenharmony_ci geometry generated by the CPU is only required to be sent to the GL 1995bd8deadSopenharmony_ci once per-frame (rather than twice with the conventional technique), 2005bd8deadSopenharmony_ci that can ease the CPU burden required to implement stenciled shadow 2015bd8deadSopenharmony_ci volumes. 2025bd8deadSopenharmony_ci 2035bd8deadSopenharmony_ci Should GL_FRONT_AND_BACK be accepted by glActiveStencilFaceEXT? 2045bd8deadSopenharmony_ci 2055bd8deadSopenharmony_ci RESOLUTION: No. 2065bd8deadSopenharmony_ci 2075bd8deadSopenharmony_ci GL_FRONT_AND_BACK is useful when materials are being updated for 2085bd8deadSopenharmony_ci two-sided lighting because the front and back material are often 2095bd8deadSopenharmony_ci identical and may change frequently (glMaterial calls are allowed 2105bd8deadSopenharmony_ci within glBegin/glEnd pairs). 2115bd8deadSopenharmony_ci 2125bd8deadSopenharmony_ci Two-sided stencil has no similiar performance justification. 2135bd8deadSopenharmony_ci 2145bd8deadSopenharmony_ci It is also likely that forcing implementations to support this mode 2155bd8deadSopenharmony_ci would increase the amount of overhead required to set stencil 2165bd8deadSopenharmony_ci state, even for applications that don't use two-sided stencil. 2175bd8deadSopenharmony_ci 2185bd8deadSopenharmony_ci How should the two-sided stencil enable operate? 2195bd8deadSopenharmony_ci 2205bd8deadSopenharmony_ci RESOLUTION: It should be modeled after the way two-sided lighting 2215bd8deadSopenharmony_ci works. There is a GL_LIGHTING enable and then an additional 2225bd8deadSopenharmony_ci two-sided lighting mode. Unlike two-sided lighting which is a 2235bd8deadSopenharmony_ci light model boolean, the two-sided stencil testing is a standard 2245bd8deadSopenharmony_ci enable named GL_STENCIL_TEST_TWO_SIDE_EXT. 2255bd8deadSopenharmony_ci 2265bd8deadSopenharmony_ci Here is the pseudo-code for the stencil testing enables: 2275bd8deadSopenharmony_ci 2285bd8deadSopenharmony_ci if (glIsEnabled(GL_STENCIL_TEST)) { 2295bd8deadSopenharmony_ci if (glIsEnabled(GL_STENCIL_TEST_TWO_SIDE_EXT) && primitiveType == polygon) { 2305bd8deadSopenharmony_ci use two-sided stencil testing 2315bd8deadSopenharmony_ci } else { 2325bd8deadSopenharmony_ci use conventional stencil testing 2335bd8deadSopenharmony_ci } 2345bd8deadSopenharmony_ci } else { 2355bd8deadSopenharmony_ci no stencil testing 2365bd8deadSopenharmony_ci } 2375bd8deadSopenharmony_ci 2385bd8deadSopenharmony_ci How should the two-sided stencil interact with glPolygonMode? 2395bd8deadSopenharmony_ci 2405bd8deadSopenharmony_ci RESOLUTION: Primitive type is determined by the begin mode 2415bd8deadSopenharmony_ci so GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_QUAD_STRIP, GL_QUADS, 2425bd8deadSopenharmony_ci GL_TRIANGLE_FAN, and GL_POLYGON generate polygon primitives. If the 2435bd8deadSopenharmony_ci polygon mode is set such that lines or points are rasterized, 2445bd8deadSopenharmony_ci two-sided stencil testing still operates based on the original 2455bd8deadSopenharmony_ci polygon facingness if stencil testing and two-sided stencil testing 2465bd8deadSopenharmony_ci are enabled. 2475bd8deadSopenharmony_ci 2485bd8deadSopenharmony_ci This is consistent with how two-sided lighting and face culling 2495bd8deadSopenharmony_ci interact with glPolygonMode. 2505bd8deadSopenharmony_ci 2515bd8deadSopenharmony_ciNew Procedures and Functions 2525bd8deadSopenharmony_ci 2535bd8deadSopenharmony_ci void ActiveStencilFaceEXT(enum face); 2545bd8deadSopenharmony_ci 2555bd8deadSopenharmony_ciNew Tokens 2565bd8deadSopenharmony_ci 2575bd8deadSopenharmony_ci Accepted by the <cap> parameter of Enable, Disable, and IsEnabled, 2585bd8deadSopenharmony_ci and by the <pname> parameter of GetBooleanv, GetIntegerv, 2595bd8deadSopenharmony_ci GetFloatv, and GetDoublev: 2605bd8deadSopenharmony_ci 2615bd8deadSopenharmony_ci STENCIL_TEST_TWO_SIDE_EXT 0x8910 2625bd8deadSopenharmony_ci 2635bd8deadSopenharmony_ci Accepted by the <face> parameter of ActiveStencilFaceEXT: 2645bd8deadSopenharmony_ci 2655bd8deadSopenharmony_ci FRONT 2665bd8deadSopenharmony_ci BACK 2675bd8deadSopenharmony_ci 2685bd8deadSopenharmony_ci Accepted by the <pname> parameters of GetBooleanv, GetIntegerv, 2695bd8deadSopenharmony_ci GetFloatv, and GetDoublev: 2705bd8deadSopenharmony_ci 2715bd8deadSopenharmony_ci ACTIVE_STENCIL_FACE_EXT 0x8911 2725bd8deadSopenharmony_ci 2735bd8deadSopenharmony_ciAdditions to Chapter 2 of the GL Specification (OpenGL Operation) 2745bd8deadSopenharmony_ci 2755bd8deadSopenharmony_ci None 2765bd8deadSopenharmony_ci 2775bd8deadSopenharmony_ciAdditions to Chapter 3 of the GL Specification (Rasterization) 2785bd8deadSopenharmony_ci 2795bd8deadSopenharmony_ci None 2805bd8deadSopenharmony_ci 2815bd8deadSopenharmony_ciAdditions to Chapter 4 of the GL Specification (Per-Fragment Operations 2825bd8deadSopenharmony_ciand the Framebuffer) 2835bd8deadSopenharmony_ci 2845bd8deadSopenharmony_ci -- Section 4.1.5 "Stencil test" 2855bd8deadSopenharmony_ci 2865bd8deadSopenharmony_ci Replace the first paragraph in the section with: 2875bd8deadSopenharmony_ci 2885bd8deadSopenharmony_ci "The stencil test conditionally discards a fragment based on the 2895bd8deadSopenharmony_ci outcome of a comparison between the value in the stencil buffer at 2905bd8deadSopenharmony_ci location (xw,yw) and a reference value. 2915bd8deadSopenharmony_ci 2925bd8deadSopenharmony_ci The test is enabled or disabled with the Enable and Disable commands, 2935bd8deadSopenharmony_ci using the symbolic constant STENCIL_TEST. When disabled, the stencil 2945bd8deadSopenharmony_ci test and associated modifications are not made, and the fragment is 2955bd8deadSopenharmony_ci always passed. 2965bd8deadSopenharmony_ci 2975bd8deadSopenharmony_ci Stencil testing may operate in a two-sided mode. Two-sided stencil 2985bd8deadSopenharmony_ci testing is enabled or disabled with the Enable and Disable commands, 2995bd8deadSopenharmony_ci using the symbolic constant STENCIL_TEST_TWO_SIDE_EXT. When stencil 3005bd8deadSopenharmony_ci testing is disabled, the state of two-sided stencil testing does 3015bd8deadSopenharmony_ci not affect fragment processing. 3025bd8deadSopenharmony_ci 3035bd8deadSopenharmony_ci There are two sets of stencil-related state, the front stencil 3045bd8deadSopenharmony_ci state set and the back stencil state set. When two-sided stencil 3055bd8deadSopenharmony_ci testing is enabled, stencil tests and writes use the front set of 3065bd8deadSopenharmony_ci stencil state when processing fragments rasterized from non-polygon 3075bd8deadSopenharmony_ci primitives (points, lines, bitmaps, image rectangles) and front-facing 3085bd8deadSopenharmony_ci polygon primitives while the back set of stencil state is used when 3095bd8deadSopenharmony_ci processing fragments rasterized from back-facing polygon primitives. 3105bd8deadSopenharmony_ci For the purposes of two-sided stencil testing, a primitive is still 3115bd8deadSopenharmony_ci considered a polygon even if the polygon is to be rasterized as 3125bd8deadSopenharmony_ci points or lines due to the current polygon mode. Whether a polygon 3135bd8deadSopenharmony_ci is front- or back-facing is determined in the same manner used for 3145bd8deadSopenharmony_ci two-sided lighting and face culling (see sections 2.13.1 and 3.5.1). 3155bd8deadSopenharmony_ci When two-sided stencil testing is disabled, the front set of stencil 3165bd8deadSopenharmony_ci state is always used when stencil testing fragments. 3175bd8deadSopenharmony_ci 3185bd8deadSopenharmony_ci The active stencil face determines whether stencil-related commands 3195bd8deadSopenharmony_ci update the front or back stencil state. The active stencil face is 3205bd8deadSopenharmony_ci set with: 3215bd8deadSopenharmony_ci 3225bd8deadSopenharmony_ci void ActiveStencilFace(enum face); 3235bd8deadSopenharmony_ci 3245bd8deadSopenharmony_ci where face is either FRONT or BACK. Stencil commands (StencilFunc, 3255bd8deadSopenharmony_ci StencilOp, and StencilMask) that update the stencil state update the 3265bd8deadSopenharmony_ci front stencil state if the active stencil face is FRONT and the back 3275bd8deadSopenharmony_ci stencil state if the active stencil face is BACK. Additionally, 3285bd8deadSopenharmony_ci queries of stencil state return the front or back stencil state 3295bd8deadSopenharmony_ci depending on the current active stencil face. 3305bd8deadSopenharmony_ci 3315bd8deadSopenharmony_ci The stencil test state is controlled with 3325bd8deadSopenharmony_ci 3335bd8deadSopenharmony_ci void StencilFunc(enum func, int ref, uint mask); 3345bd8deadSopenharmony_ci void StencilOp(enum sfail, enum dpfail, enum dppass);" 3355bd8deadSopenharmony_ci 3365bd8deadSopenharmony_ci Replace the third and second to the last sentence in the last 3375bd8deadSopenharmony_ci paragraph in section 4.1.5 with: 3385bd8deadSopenharmony_ci 3395bd8deadSopenharmony_ci "In the initial state, stencil testing and two-sided stencil testing 3405bd8deadSopenharmony_ci are both disabled, the front and back stencil reference values are 3415bd8deadSopenharmony_ci both zero, the front and back stencil comparison functions are ALWAYS, 3425bd8deadSopenharmony_ci and the front and back stencil mask are both all ones. Initially, 3435bd8deadSopenharmony_ci both the three front and the three back stencil operations are KEEP." 3445bd8deadSopenharmony_ci 3455bd8deadSopenharmony_ci -- Section 4.2.2 "Fine Control of Buffer Updates" 3465bd8deadSopenharmony_ci 3475bd8deadSopenharmony_ci Replace the last sentence of the third paragraph with: 3485bd8deadSopenharmony_ci 3495bd8deadSopenharmony_ci "The initial state is for both the front and back stencil plane mask 3505bd8deadSopenharmony_ci to be all ones. The clear operation always uses the front stencil 3515bd8deadSopenharmony_ci write mask when clearing the stencil buffer." 3525bd8deadSopenharmony_ci 3535bd8deadSopenharmony_ci -- Section 4.3.1 "Writing to the Stencil Buffer or to the Depth and 3545bd8deadSopenharmony_ci Stencil Buffers" 3555bd8deadSopenharmony_ci 3565bd8deadSopenharmony_ci Replace the final sentence in the first paragraph with: 3575bd8deadSopenharmony_ci 3585bd8deadSopenharmony_ci "Finally, each stencil index is written to its indicated location 3595bd8deadSopenharmony_ci in the framebuffer, subject to the current front stencil mask state 3605bd8deadSopenharmony_ci (set with StencilMask), and if a depth component is present, if the 3615bd8deadSopenharmony_ci setting of DepthMask is not FALSE, it is also written to the 3625bd8deadSopenharmony_ci framebuffer; the setting of DepthTest is ignored." 3635bd8deadSopenharmony_ci 3645bd8deadSopenharmony_ciAdditions to Chapter 5 of the GL Specification (Special Functions) 3655bd8deadSopenharmony_ci 3665bd8deadSopenharmony_ci None 3675bd8deadSopenharmony_ci 3685bd8deadSopenharmony_ciAdditions to Chapter 6 of the GL Specification (State and State Requests) 3695bd8deadSopenharmony_ci 3705bd8deadSopenharmony_ci None 3715bd8deadSopenharmony_ci 3725bd8deadSopenharmony_ciAdditions to the GLX, WGL, and AGL Specification 3735bd8deadSopenharmony_ci 3745bd8deadSopenharmony_ci None 3755bd8deadSopenharmony_ci 3765bd8deadSopenharmony_ciGLX Protocol 3775bd8deadSopenharmony_ci 3785bd8deadSopenharmony_ci A new GL rendering command is added. The following command is sent to the 3795bd8deadSopenharmony_ci server as part of a glXRender request: 3805bd8deadSopenharmony_ci 3815bd8deadSopenharmony_ci ActiveStencilFaceEXT 3825bd8deadSopenharmony_ci 2 8 rendering command length 3835bd8deadSopenharmony_ci 2 4220 rendering command opcode 3845bd8deadSopenharmony_ci 4 ENUM face 3855bd8deadSopenharmony_ci 3865bd8deadSopenharmony_ciInteractions with OpenGL 2.0 3875bd8deadSopenharmony_ci 3885bd8deadSopenharmony_ci OpenGL 2.0 provides similar "separate stencil" functionality with an API 3895bd8deadSopenharmony_ci based on the ATI_separate_stencil extension. In the OpenGL 2.0 API, there 3905bd8deadSopenharmony_ci is no enable; instead, new functions are provided that set both front and 3915bd8deadSopenharmony_ci back state simultaneously. Non-separate stencil functions (e.g., 3925bd8deadSopenharmony_ci StencilFunc, StencilOp) set *both* back and front state. In this 3935bd8deadSopenharmony_ci extension, they set either front or back state depending on the active 3945bd8deadSopenharmony_ci stencil face. 3955bd8deadSopenharmony_ci 3965bd8deadSopenharmony_ci Implementations supporting both this extension and OpenGL 2.0 will need to 3975bd8deadSopenharmony_ci support both styles of two-sided stencil usage without API modification, 3985bd8deadSopenharmony_ci which is ugly since the OpenGL 2.0 API does not have an enable for 3995bd8deadSopenharmony_ci two-sided functionality -- it's always on. To achieve this, we provide 4005bd8deadSopenharmony_ci three different sets of stencil state: 4015bd8deadSopenharmony_ci 4025bd8deadSopenharmony_ci - front state 4035bd8deadSopenharmony_ci - "OpenGL 2.0" back state 4045bd8deadSopenharmony_ci - "EXT_stencil_two_side" back state 4055bd8deadSopenharmony_ci 4065bd8deadSopenharmony_ci OpenGL 2.0 separate stencil functions set the front and "OpenGL 2.0" back 4075bd8deadSopenharmony_ci state. Non-separate stencil functions use the stencil face selector to 4085bd8deadSopenharmony_ci determine what to set: FRONT (the default) sets both front and "OpenGL 4095bd8deadSopenharmony_ci 2.0" back state; BACK sets "EXT_stencil_two_side" back state. 4105bd8deadSopenharmony_ci 4115bd8deadSopenharmony_ci If the two-sided stencil enable in this extension is set, implying 4125bd8deadSopenharmony_ci EXT_stencil_two_side usage, we choose between the front state and the 4135bd8deadSopenharmony_ci EXT_stencil_two_side back state. Those two sets of state are set 4145bd8deadSopenharmony_ci appropriately when using the active stencil face selector provided by this 4155bd8deadSopenharmony_ci extension. 4165bd8deadSopenharmony_ci 4175bd8deadSopenharmony_ci If the two-sided stencil enable in this extension is not set, implying 4185bd8deadSopenharmony_ci either OpenGL 2.0 or "one-sided" EXT_stencil_two_side usage, we choose 4195bd8deadSopenharmony_ci between the front state and the OpenGL 2.0 back state. In OpenGL 2.0 4205bd8deadSopenharmony_ci usage, the separate stencil functions set either of these two pieces of 4215bd8deadSopenharmony_ci state appropriately, and the non-separate stencil functions set both. In 4225bd8deadSopenharmony_ci "one-sided" EXT_stencil_two_side usage, the separate stencil functions 4235bd8deadSopenharmony_ci from OpenGL 2.0 will not be used. Any time the non-separate functions set 4245bd8deadSopenharmony_ci the front state (active face == FRONT), they also set the OpenGL 2.0 back 4255bd8deadSopenharmony_ci state, so the front and back state used will always be identical in this 4265bd8deadSopenharmony_ci case. 4275bd8deadSopenharmony_ci 4285bd8deadSopenharmony_ci The relevant spec language changes in the OpenGL 2.0 specification are: 4295bd8deadSopenharmony_ci 4305bd8deadSopenharmony_ci (modify 2nd paragraph, p. 202) There are three sets of stencil-related 4315bd8deadSopenharmony_ci state, the front stencil state set, the OpenGL 2.0 back stencil state set, 4325bd8deadSopenharmony_ci and the EXT_stencil_two_side back stencil state set. Stencil tests and 4335bd8deadSopenharmony_ci writes use the front set of stencil state when processing fragments 4345bd8deadSopenharmony_ci rasterized from non-polygon primitives (points, lines, bitmaps, image 4355bd8deadSopenharmony_ci rectangles) and front-facing polygon primitives. When processing 4365bd8deadSopenharmony_ci fragments rasterized from back-facing polygon primitives, stencil tests 4375bd8deadSopenharmony_ci and writes use the OpenGL 2.0 back stencil state set when 4385bd8deadSopenharmony_ci STENCIL_TEST_TWO_SIDE_EXT is disabled and the EXT_stencil_two_side back 4395bd8deadSopenharmony_ci stencil state set otherwise. ... 4405bd8deadSopenharmony_ci 4415bd8deadSopenharmony_ci (modify 3rd paragraph, p. 202) StencilFuncSeparate and StencilOpSeparate 4425bd8deadSopenharmony_ci take a face argument which can be FRONT, BACK, or FRONT_AND_BACK and 4435bd8deadSopenharmony_ci indicates which set of state is affected. If <face> is BACK or 4445bd8deadSopenharmony_ci FRONT_AND_BACK, the OpenGL 2.0 back stencil state is modified, but the 4455bd8deadSopenharmony_ci EXT_stencil_two_side state is not. StencilFunc and StencilOp set state 4465bd8deadSopenharmony_ci based on the active stencil face. If the active stencil face is FRONT, 4475bd8deadSopenharmony_ci the corresponding front and OpenGL 2.0 back stencil state are set to 4485bd8deadSopenharmony_ci identical values. If the active stencil face is BACK, the corresponding 4495bd8deadSopenharmony_ci EXT_stencil_two_side back state is set. 4505bd8deadSopenharmony_ci 4515bd8deadSopenharmony_ciErrors 4525bd8deadSopenharmony_ci 4535bd8deadSopenharmony_ci None 4545bd8deadSopenharmony_ci 4555bd8deadSopenharmony_ciNew State 4565bd8deadSopenharmony_ci 4575bd8deadSopenharmony_ci(table 6.15, page 205) amend the following entries: 4585bd8deadSopenharmony_ci 4595bd8deadSopenharmony_ciGet Value Type Get Command Initial Value Description Sec Attribute 4605bd8deadSopenharmony_ci------------------------- ---- ----------- ------------- ------------------- ----- -------------- 4615bd8deadSopenharmony_ciSTENCIL_FUNC 2xZ8 GetIntegerv ALWAYS Stencil function 4.1.4 stencil-buffer 4625bd8deadSopenharmony_ciSTENCIL_VALUE_MASK 2xZ+ GetIntegerv 1's Stencil mask 4.1.4 stencil-buffer 4635bd8deadSopenharmony_ciSTENCIL_REF 2xZ+ GetIntegerv 0 Stencil reference 4.1.4 stencil-buffer 4645bd8deadSopenharmony_ci value 4655bd8deadSopenharmony_ciSTENCIL_FAIL 2xZ6 GetIntegerv KEEP Stencil fail action 4.1.4 stencil-buffer 4665bd8deadSopenharmony_ciSTENCIL_PASS_DEPTH_FAIL 2xZ6 GetIntegerv KEEP Stencil depth 4.1.4 stencil-buffer 4675bd8deadSopenharmony_ci buffer fail action 4685bd8deadSopenharmony_ciSTENCIL_PASS_DEPTH_PASS 2xZ6 GetIntegerv KEEP Stencil depth 4.1.4 stencil-buffer 4695bd8deadSopenharmony_ci buffer pass action 4705bd8deadSopenharmony_ci 4715bd8deadSopenharmony_ci[Type field is amended with "2x" prefix.] 4725bd8deadSopenharmony_ci 4735bd8deadSopenharmony_ci(table 6.15, page 205) add the following entries: 4745bd8deadSopenharmony_ci 4755bd8deadSopenharmony_ciGet Value Type Get Command Initial Value Description Sec Attribute 4765bd8deadSopenharmony_ci------------------------- ---- ----------- ------------- ----------------- ------ --------------------- 4775bd8deadSopenharmony_ciSTENCIL_TEST_TWO_SIDE_EXT B IsEnabled False Two-sided stencil 4.1.4 stencil-buffer/enable 4785bd8deadSopenharmony_ci test enable 4795bd8deadSopenharmony_ciACTIVE_STENCIL_FACE_EXT Z2 GetIntegerv FRONT Active stencil 4.1.4 stencil-buffer 4805bd8deadSopenharmony_ci face selector 4815bd8deadSopenharmony_ci 4825bd8deadSopenharmony_ci(table 6.16, page 205) ammend the following entry: 4835bd8deadSopenharmony_ci 4845bd8deadSopenharmony_ciGet Value Type Get Command Initial Value Description Sec Attribute 4855bd8deadSopenharmony_ci------------------------- ---- ----------- ------------- ----------------- ------ -------------- 4865bd8deadSopenharmony_ciSTENCIL_WRITE_MASK 2xZ+ GetIntegerv 1's Stencil buffer 4.2.2 stencil-buffer 4875bd8deadSopenharmony_ci writemask 4885bd8deadSopenharmony_ci 4895bd8deadSopenharmony_ci[Type field is amended with "2x" prefix.] 4905bd8deadSopenharmony_ci 4915bd8deadSopenharmony_ci 4925bd8deadSopenharmony_ciRevision History 4935bd8deadSopenharmony_ci 4945bd8deadSopenharmony_ci Rev. Date Author Changes 4955bd8deadSopenharmony_ci ---- -------- -------- -------------------------------------------- 4965bd8deadSopenharmony_ci 2 09/15/05 pbrown Clarified interaction with OpenGL 2.0 two- 4975bd8deadSopenharmony_ci sided stencil. 4985bd8deadSopenharmony_ci 4995bd8deadSopenharmony_ci 1 01/08/03 mjk Initial revision. 500