1Name 2 3 AMD_shader_stencil_value_export 4 5Name Strings 6 7 GL_AMD_shader_stencil_value_export 8 9Contact 10 11 Graham Sellers, AMD (graham.sellers 'at' amd.com) 12 13Status 14 15 Shipping 16 17Version 18 19 Last Modified Date: 12/12/2013 20 Author Revision: 2 21 22Number 23 24 OpenGL Extension #444 25 26Dependencies 27 28 OpenGL 2.0 or ARB_fragment_shader is required. 29 30 The AMD_shader_stencil_export extension affects the definition of this 31 extension. 32 33 The AMD_stencil_operation_extended extension is required. 34 35 This extension is written against the OpenGL Shading Language (GLSL) 36 Specification, Version 4.00.7. 37 38Overview 39 40 OpenGL includes stencil testing functionality that allows an application 41 specified value (the reference value) to be compared against the content 42 of a stencil buffer and fragments kept or discarded based on the results 43 of this test. In addition to updating the stencil buffer with simple 44 operations such as inversion or incrementation, this reference value may be 45 written directly into the stencil buffer. 46 47 AMD_stencil_operation_extended further extended the number of 48 operations that may be performed on the stencil buffer to include logical 49 and arithmetic operations. It also introduced new state, the stencil 50 operation source value, to allow these new operations to be performed on 51 the stencil buffer using an application supplied constant value as a source 52 value, rather than the reference value used in the stencil test. 53 54 The AMD_shader_stencil_export extension allowed the reference value 55 used for the stencil test to be generated and exported from a fragment 56 shader. This extension provides similar functionality for the stencil 57 operation source value, allowing it to be generated in and exported from 58 the fragment shader too. 59 60IP Status 61 62 None. 63 64New Procedures and Functions 65 66 None. 67 68New Tokens 69 70 None. 71 72Modifications to the OpenGL 4.0 (Core Profile) Specification 73 74 None. 75 76Modifications to Chapter 3 of the OpenGL Shading Language Specification, 77Version 4.00.7 78 79 Add new Section 3.3.x, GL_AMD_shader_stencil_value_export Extension, p.15 80 81 3.3.x GL_AMD_shader_stencil_value_export 82 83 To use the GL_AMD_shader_stencil_value_export extension in a shader it must 84 be enabled using the #extension directive. 85 86 The shading language preprocessor #define GL_AMD_shader_stencil_value_export 87 will be defined to 1 if the GL_AMD_shader_stencil_value_export extension is 88 supported. 89 90Modifications to Chapter 7 of the OpenGL Shading Language Specification, 91Version 4.00.7 (Built-in Variables) 92 93 Modify Section 7.1, "Built-in Language Variables": 94 95 Add to the list of built-in special variables for the fragment language, 96 p.86: 97 98 out int gl_FragStencilValueAMD; 99 100 Insert the following paragraph, after the paragraph describing 101 gl_FragStencilRefAMD (as introduced by AMD_shader_stencil_export) on p.89: 102 103 Writing to gl_FragStencilValueAMD will establish the stencil operation 104 source value for the fragment being processed. Only the least significant 105 STENCIL_BITS bits of the integer gl_FragStencilValueAMD are considered and 106 higher order bits are discarded. If stencil buffering is enabled and no 107 shader writes to gl_FragStencilValueAMD, the fixed function value for 108 stencil operation source will be used as the fragment's stencil operation 109 source value. If a shader statically assignes a value to 110 gl_FragStencilValueAMD, and there is an execution path through the shader 111 that does not set gl_FragStencilValueAMD, then the value of the fragment's 112 stencil operation source value may be undefined for executions of the 113 shader that take that path. That is, if the set of linked shaders 114 statically contain a write to gl_FragStencilValueAMD, then it is 115 responsible for always writing it. 116 117 Modify the paragraph on p.89, describing the 'discard' keyword: 118 119 If a shader executes the discard keyword, the fragment is discarded, and 120 the values of any user-defined fragment outputs, gl_FragDepth, 121 gl_FragStencilRefAMD, and gl_FragStencilValueAMD become irrelevant. 122 123Additions to the AGL/GLX/WGL Specifications 124 125 None. 126 127GLX Protocol 128 129 None. 130 131Errors 132 133 None. 134 135New State 136 137 None. 138 139New Implementation Dependent State 140 141 None. 142 143Dependencies on AMD_shader_stencil_export 144 145 If AMD_shader_stencil_export is not supported, remove all references to 146 gl_FragStencilRefAMD. 147 148Issues 149 150 1) What is the behavior of gl_FragStencilValueAMD with respect to masks, 151 significant bits and so on? 152 153 The behavior of the value written to gl_FragStencilValueAMD is the same 154 as that of the fixed function value set through glStencilOpValueAMD. That 155 is, the value is not masked until the result of the operation is written 156 to the stencil buffer. Bits that cannot be represented by the stencil 157 buffer are simply discarded. 158 159Revision History 160 161 Rev. Date Author Changes 162 ---- ---------- -------- ----------------------------------------- 163 2 12/12/2013 gsellers Minor cleanup ready for posting. 164 1 06/10/2010 gsellers Initial revision 165