GL_LAYER(3G)
π gl_Layer(3G) β the vibe check
okay so bestie, this is a page from section 3G of the manual, and it's all about gl_Layer β the little variable that picks which layer of a multi-layer framebuffer attachment you're rendering into. she's giving "backstage pass coordinator" energy and honestly? iconic.
β¨ NAME β¨
gl_Layer β contains the selected layer of a multi-layer framebuffer attachment π
π DECLARATION π
here's literally how she shows up in each stage, no cap:
// Geometry stage
out int gl_Layer ;
// Fragment stage
in int gl_Layer ;
so in geometry she's an out, in fragment she's an in. same name, different job. main character behavior honestly π¦
π DESCRIPTION π
π§ geometry stage energy
In the geometry language, gl_Layer is used to select a specific layer (or face and layer of cube map) in a multi-layer framebuffer attachment. oh she's choosing. periodt.
The actual layer used will come from one of the vertices in the primitive being shaded. and like... which vertex the layer comes from is undefined β it's giving mystery, it's giving chaos β so the recommendation is to write the same value to gl_Layer for all vertices in the primitive. fr fr, keep it consistent bestie π
If a shader statically assigns a value to gl_Layer, layered rendering mode is enabled. turning it on just by assigning? she's powerful like that.
β οΈ but listen: if a shader statically assigns a value togl_Layer, and there is an execution path through the shader that does not setgl_Layer, then the value ofgl_Layeris undefined for invocations of the shader that take that path. so cover all your paths or you get the void π undefined is not a vibe.
π§ cube map array tea
When used with an array of cube map textures, the gl_Layer 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. she's doing double duty, we love a multitasker π
Setting gl_Layer to the value layer*6+face will render to face of the cube defined in layer. The face values are as follows:
0βGL_TEXTURE_CUBEMAP_POSITIVE_X1βGL_TEXTURE_CUBEMAP_NEGATIVE_X2βGL_TEXTURE_CUBEMAP_POSITIVE_Y3βGL_TEXTURE_CUBEMAP_NEGATIVE_Y4βGL_TEXTURE_CUBEMAP_POSITIVE_Z5βGL_TEXTURE_CUBEMAP_NEGATIVE_Z
For example, to render to the positive y cube map face located in the 5th layer of the cube map array, gl_Layer should be set to 5*6+2. math! ate! β¨
πΈ fragment stage receipts
The input variable gl_Layer in the fragment language will have the same value that was written to the output variable gl_Layer in the geometry language. handoff queen π«Ά
- If the geometry stage does not dynamically assign a value to
gl_Layer, the value ofgl_Layerin the fragment stage will be undefined. - If the geometry stage makes no static assignment to
gl_Layer, the inputgl_Layerin 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. she does not gatekeep, she does not judge, she just passes it along π
π one more thing: if a fragment shader contains a static access to gl_Layer, it will count against the implementation defined limit for the maximum number of inputs to the fragment stage. budget check, bestie β it's not free.
π VERSION SUPPORT π
which OpenGL Shading Language versions have her? let me lay it out, column by column, bc the original table is a whole thing:
gl_Layer (geometry stage) β here's the era-by-era breakdown:
1.10β-(nope)1.20β-(nope)1.30β-(nope)1.40β-(nope)1.50β β (she arrives, entrance: iconic)3.30β β4.00β β4.10β β4.20β β4.30β β4.40β β4.50β β
gl_Layer (fragment stage) β she took her time, honestly:
1.10β-1.20β-1.30β-1.40β-1.50β-3.30β-4.00β-4.10β-4.20β-4.30β β (finally!! the glow-up π)4.40β β4.50β β
π¦ SEE ALSO π¦
gl_ViewportIndex()β go give her a read too, iykyk π«
π COPYRIGHT π
Copyright Β© 2011-2014 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. http://opencontent.org/openpub/.
Copyright Β© 2012-2014 Khronos Group
and that's the whole page bestie π β sourced from [FIXME: source], dated 08/09/2021, and yes she is GL_LAYER(3G) through and through. mwah ππ
π¦ where this page comes from
- centos-stream 9: gl-manpages 1.1-24.20190306.el9 Β· MIT and Open Publication
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms