1Name 2 3 AMD_vertex_shader_viewport_index 4 5Name Strings 6 7 GL_AMD_vertex_shader_viewport_index 8 9Contact 10 11 Graham Sellers, AMD (graham.sellers 'at' amd.com) 12 13Contributors 14 15 Graham Sellers 16 17Status 18 19 Shipping. 20 21Version 22 23 Last Modified Date: March 15, 2012 24 Revision: 2 25 26Number 27 28 416 29 30Dependencies 31 32 OpenGL 4.1 or ARB_viewport_array is required. 33 34 The extension is written against the OpenGL 4.2 Specification, Core Profile, 35 January 19, 2011 and the OpenGL Shading Language Specification, 36 version 4.20.11. 37 38Overview 39 40 The gl_ViewportIndex built-in variable was introduced by the 41 ARB_viewport_array extension and OpenGL 4.1. This variable is available 42 in un-extended OpenGL only to the geometry shader. When written in the 43 geometry shader, it causes geometry to be directed to one of an array 44 of several independent viewport rectangles. 45 46 In order to use any viewport other than zero, a geometry shader must be 47 present. Geometry shaders introduce processing overhead and potential 48 performance issues. This extension exposes the gl_ViewportIndex built-in 49 variable to the vertex shader, allowing the functionality introduced by 50 ARB_viewport_array to be accessed without requiring a geometry shader to 51 be present. 52 53New Procedures and Functions 54 55 None. 56 57New Tokens 58 59 None. 60 61Additions to Chapter 2 of the OpenGL 4.2 (Core) Specification (OpenGL Operation) 62 63 Add the following paragraph to the "Output Variables" subsection of 64 section 2.11, "Vertex Shaders" on p. 106. 65 66 The built-in special variable gl_ViewportIndex, if written, is used to 67 direct rendering to one of several viewports and is discussed further in 68 the next section. 69 70 Insert the following subsection after the "Shader Outputs" subsection on 71 p.106. 72 73 "Viewport Selection" 74 75 Vertex shaders can be used to render to one of several different 76 viewport rectangles. The destination viewport rectangle for a primitive 77 may be specified by writing to the built-in output variable 78 gl_ViewportIndex in the vertex shader. This functionality allows a vertex 79 shader to direct rendering to one of several viewport rectangles. The 80 specific vertex of a primitive from which gl_ViewportIndex is taken 81 is implementation defined and may be determined by calling GetIntegerv with 82 the symbolic constant VIEWPORT_INDEX_PROVOKING_VERTEX. 83 84 If the value returned is PROVOKING_VERTEX then vertex selection follows the 85 convention specified to ProvokingVertex (see Section 2.19). If the value 86 returned is FIRST_VERTEX_CONVENTION, selection is always taken from the 87 first vertex of the primitive. If the value returned is 88 LAST_VERTEX_CONVENTION, the selection is always taken from the last vertex 89 of the primitive. If the value returned is UNDEFINED_VERTEX, the selection 90 is not guaranteed to be taken from any specific vertex. The vertex 91 considered the provoking vertex for particular primitive types is given 92 in table 2.15. 93 94 Replace the second paragraph of the "Layer and Viewport Selection" subsection 95 of section 2.13, "Geometry Shaders", p.135 (which describes 96 gl_ViewportIndex) with: 97 98 The special built-in variable gl_ViewportIndex is available to geometry 99 shaders to direct rendering to a specific viewport in an array of 100 viewports and has the same effect as the similarly named variable in the 101 vertex shader. 102 103 Modify section 2.14.1 "Controling the Viewport" as follows: 104 105 Multiple viewports are available and are numbered zero through the value 106 of MAX_VIEWPORTS minus one. If a vertex or geometry shader is active and 107 writes to gl_ViewportIndex, the viewport transformation uses the viewport 108 corresponding to the value assigned to gl_ViewportIndex taken from an 109 implementation-dependent primitive vertex. If the value of the viewport 110 index is outside the range zero to the value of MAX_VIEWPORTS minus one, 111 the results of the viewport transformation are undefined. If the active 112 vertex shaders or geometry shaders (if present) do not write to 113 gl_ViewportIndex, the viewport numbered zero is used by the viewport 114 transformation. 115 116Additions to Chapter 3 of the OpenGL 4.2 (Core) Specification (Rasterization) 117 118 None. 119 120Additions to Chapter 4 of the OpenGL 4.2 (Core) Specification (Per-Fragment Operations 121and the Framebuffer) 122 123 None. 124 125Additions to Chapter 5 of the OpenGL 4.2 (Core) Specification (Special 126Functions) 127 128 None. 129 130Additions to Chapter 6 of the OpenGL 4.2 (Core) Specification (State and 131State Requests) 132 133 None. 134 135Additions to Chapter 7 of the OpenGL Shading Language Specification, Version 4.20 136 137 Add to the list of vertex shader built-in variables, Section 7.1, p. 97: 138 139 out int gl_ViewportIndex; 140 141 Modify the first paragraph on p.101, describing gl_ViewpotIndex as follows: 142 143 The output variable gl_ViewportIndex is available only in the vertex and 144 geometry languages and provides the index of the viewport to which the next 145 primitive assembled from the resulting vertices or emitted from the 146 geometry shader (if present) should be drawn. Primitives generated during 147 primitive assembly will undergo viewport transformation and scissor testing 148 using the viewport transformation and scissor rectangle selected by the 149 value of gl_ViewportIndex. The viewport index used will come from one of 150 the vertices in the primitive being processed. However, which vertex the 151 viewport index comes from is implementation-dependent, so it is best to use 152 the same viewport index for all vertices of the primitive. If a vertex or 153 geometry shader (if present) does not assign a value to gl_ViewportIndex, 154 viewport transform and scissor rectangle zero will be used. If a vertex 155 or geometry shader statically assigns a value to gl_ViewportIndex and there 156 is a path through the shader that does not assign a value to 157 gl_ViewportIndex, the value of gl_ViewportIndex is undefined for executions 158 of the shader that take that path. See section 2.11.11, under "Output 159 Variables" of the OpenGL Graphics System Specification (Core Profile) for 160 more information. 161 162Additions to the AGL/GLX/WGL Specifications 163 164 None. 165 166GLX Protocol 167 168 None. 169 170Errors 171 172 None. 173 174New State 175 176 None. 177 178New Implementation Dependent State 179 180 None. 181 182Issues 183 184 1) What happens when there is a tessellation shader in the pipe? 185 186 RESOVED: gl_ViewportIndex is not exposed to tessellation shaders. The 187 primary motivation for this extension is to allow simple applications using 188 only vertex and fragment shaders to take advantage of multiple viewports. 189 To use vertex-shader specified viewport indices in a program that uses 190 tessellation, the viewport index can be passed from vertex to control to 191 evaluation shader and then a geometry shader can be used to initialize 192 gl_ViewportIndex as would be the case in the absence of this extension. 193 194 2) What happens if gl_ViewportIndex is written in the vertex shader and 195 a geometry shader is present? 196 197 RESOLVED: The value written in the VS is lost. If the GS writes 198 gl_ViewportIndex, that value is used, otherwise the zeroth viewport 199 is used. 200 201 3) Are provoking vertex semantics honored for the purposes of writes to 202 gl_ViewportIndex in the VS? 203 204 RESOLVED: Yes, they are. Query VIEWPORT_INDEX_PROVOKING_VERTEX to determine 205 the 'provokingness' of gl_ViewportIndex. In general, though, it's best 206 practice to ensure that all vertices of a single primitive (including 207 strips, fans and loops) have the same value for gl_ViewportIndex. 208 209Revision History 210 211 Rev. Date Author Changes 212 ---- -------- -------- ----------------------------------------- 213 214 2 03/15/2012 gsellers Finalize for posting in public repository 215 1 04/05/2011 gsellers Initial draft 216