<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "xhtml1-transitional.dtd">
<!-- saved from url=(0013)about:internet -->
<?xml-stylesheet type="text/xsl" href="mathml.xsl"?><html xmlns="http://www.w3.org/1999/xhtml" xmlns:pref="http://www.w3.org/2002/Math/preference" pref:renderer="mathplayer-dl"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><link rel="stylesheet" type="text/css" href="opengl-man.css" /><title>gl_Layer - OpenGL Shading Language (GLSL)</title><meta name="generator" content="DocBook XSL Stylesheets V1.69.1" /></head><body><div class="refentry" lang="en" xml:lang="en"><a id="gl_Layer"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>gl_Layer — contains the selected layer of a multi-layer framebuffer attachment</p></div><div class="refsynopsisdiv"><h2>Declaration</h2><div class="funcsynopsis"><code class="function">out int gl_Layer; // Geometry stage</code></div><div class="funcsynopsis"><code class="function">in int gl_Layer; // Fragment stage</code></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="description"></a><h2>Description</h2><p>
            In the geometry language, <code class="function">gl_Layer</code> is used to select a specific
            layer (or face and layer of cube map) in a multi-layer framebuffer attachment. The actual
            layer used will come from one of the vertices in the primitive being shaded. Which vertex
            the layer comes from is undefined and as such it is recommended to write the same value
            to <code class="function">gl_Layer</code> for all vertices in the primitive. If a shader statically
            assigns a value to <code class="function">gl_Layer</code>, layered rendering mode is enabled.
            If a shader statically assigns a value to <code class="function">gl_Layer</code>, and there is an execution path through
            the shader that does not set <code class="function">gl_Layer</code>, then the value of <code class="function">gl_Layer</code>
            is undefined for invocations of the shader that take that path.
        </p><p>
            When used with an array of cube map textures, the <code class="function">gl_Layer</code> output variable
            takes on a special value. Instead of referring to only the layer, it is used to select a cube map
            face and a layer. Setting <code class="function">gl_Layer</code> to the value
            <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll"><mml:mi>layer</mml:mi><mml:mo>*</mml:mo><mml:mn>6</mml:mn><mml:mo>+</mml:mo><mml:mi>face</mml:mi></mml:math>
            will render to <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll"><mml:mi>face</mml:mi></mml:math>
            of the cube defined in <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll"><mml:mi>layer</mml:mi></mml:math>.
            The face values are as follows:
        </p><div class="informaltable"><table border="1"><colgroup><col align="left" /><col align="center" /></colgroup><thead><tr><th align="left"><span class="bold"><strong>
                        Face Value
                        </strong></span></th><th align="left"><span class="bold"><strong>
                        Resulting Target
                        </strong></span></th></tr><tr><th align="left">
                            0
                        </th><th align="center">
                            <code class="constant">GL_TEXTURE_CUBEMAP_POSITIVE_X</code>
                        </th></tr><tr><th align="left">
                            1
                        </th><th align="center">
                            <code class="constant">GL_TEXTURE_CUBEMAP_NEGATIVE_X</code>
                        </th></tr><tr><th align="left">
                            2
                        </th><th align="center">
                            <code class="constant">GL_TEXTURE_CUBEMAP_POSITIVE_Y</code>
                        </th></tr><tr><th align="left">
                            3
                        </th><th align="center">
                            <code class="constant">GL_TEXTURE_CUBEMAP_NEGATIVE_Y</code>
                        </th></tr><tr><th align="left">
                            4
                        </th><th align="center">
                            <code class="constant">GL_TEXTURE_CUBEMAP_POSITIVE_Z</code>
                        </th></tr><tr><th align="left">
                            5
                        </th><th align="center">
                            <code class="constant">GL_TEXTURE_CUBEMAP_NEGATIVE_Z</code>
                        </th></tr></thead></table></div><p>
        </p><p>
            For example, to render to the positive y cube map face located in the 5<sup>th</sup> layer of the
            cube map array, <code class="function">gl_Layer</code> should be set to
            <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll"><mml:mn>5</mml:mn><mml:mo>*</mml:mo><mml:mn>6</mml:mn><mml:mo>+</mml:mo><mml:mn>2</mml:mn></mml:math>.
        </p><p>
            The input variable <code class="function">gl_Layer</code> in the fragment language will have the same value that was written to the
            output variable <code class="function">gl_Layer</code> in the geometry language. If the geometry stage does not dynamically assign a
            value to <code class="function">gl_Layer</code>, the value of <code class="function">gl_Layer</code> in the fragment stage will be undefined.  If the geometry stage
            makes no static assignment to <code class="function">gl_Layer</code>, the input <code class="function">gl_Layer</code> in the fragment stage will be zero.  Otherwise,
            the fragment stage will read the same value written by the geometry stage, even if that value is out of
            range.  If a fragment shader contains a static access to <code class="function">gl_Layer</code>, it will count against the implementation
            defined limit for the maximum number of inputs to the fragment stage.
        </p></div><div class="refsect1" lang="en" xml:lang="en"><a id="versions"></a><h2>Version Support</h2><div class="informaltable"><table border="1"><colgroup><col align="left" /><col align="center" /><col align="center" /><col align="center" /><col align="center" /><col align="center" /><col align="center" /><col align="center" /><col align="center" /><col align="center" /><col align="center" /></colgroup><thead><tr><th align="left"><span class="bold"><strong>Function</strong></span></th><th align="left"><span class="bold"><strong>Version 1.10</strong></span></th><th align="left"><span class="bold"><strong>Version 1.20</strong></span></th><th align="left"><span class="bold"><strong>Version 1.30</strong></span></th><th align="left"><span class="bold"><strong>Version 1.40</strong></span></th><th align="left"><span class="bold"><strong>Version 1.50</strong></span></th><th align="left"><span class="bold"><strong>Version 3.30</strong></span></th><th align="left"><span class="bold"><strong>Version 4.00</strong></span></th><th align="left"><span class="bold"><strong>Version 4.10</strong></span></th><th align="left"><span class="bold"><strong>Version 4.20</strong></span></th><th align="center"><span class="bold"><strong>Version 4.30</strong></span></th></tr><tr><th align="left">gl_Layer (geometry stage)</th><th align="center"><span class="emphasis"><em>-</em></span></th><th align="center"><span class="emphasis"><em>-</em></span></th><th align="center"><span class="emphasis"><em>-</em></span></th><th align="center"><span class="emphasis"><em>-</em></span></th><th align="center"><span class="emphasis"><em>Y</em></span></th><th align="center"><span class="emphasis"><em>Y</em></span></th><th align="center"><span class="emphasis"><em>Y</em></span></th><th align="center"><span class="emphasis"><em>Y</em></span></th><th align="center"><span class="emphasis"><em>Y</em></span></th><th align="center"><span class="emphasis"><em>Y</em></span></th></tr><tr><th align="left">gl_Layer (fragment stage)</th><th align="center"><span class="emphasis"><em>-</em></span></th><th align="center"><span class="emphasis"><em>-</em></span></th><th align="center"><span class="emphasis"><em>-</em></span></th><th align="center"><span class="emphasis"><em>-</em></span></th><th align="center"><span class="emphasis"><em>-</em></span></th><th align="center"><span class="emphasis"><em>-</em></span></th><th align="center"><span class="emphasis"><em>-</em></span></th><th align="center"><span class="emphasis"><em>-</em></span></th><th align="center"><span class="emphasis"><em>-</em></span></th><th align="center"><span class="emphasis"><em>Y</em></span></th></tr></thead></table></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="seealso"></a><h2>See Also</h2><p>
            <a href="gl_ViewportIndex.xml"><span class="citerefentry"><span class="refentrytitle">gl_ViewportIndex</span></span></a>
        </p></div><div class="refsect1" lang="en" xml:lang="en"><a id="Copyright"></a><h2>Copyright</h2><p>
            Copyright <span class="trademark"></span>© 2011-2012 Khronos Group. 
            This material may be distributed subject to the terms and conditions set forth in 
            the Open Publication License, v 1.0, 8 June 1999.
            <a href="http://opencontent.org/openpub/" target="_top">http://opencontent.org/openpub/</a>.
        </p></div></div></body></html>
