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 to gl_Layer, and there is an execution path through the shader that does not set gl_Layer, then the value of gl_Layer is 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_X
  • 1 β†’ GL_TEXTURE_CUBEMAP_NEGATIVE_X
  • 2 β†’ GL_TEXTURE_CUBEMAP_POSITIVE_Y
  • 3 β†’ GL_TEXTURE_CUBEMAP_NEGATIVE_Y
  • 4 β†’ GL_TEXTURE_CUBEMAP_POSITIVE_Z
  • 5 β†’ 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 of gl_Layer in the fragment stage will be undefined.
  • If the geometry stage makes no static assignment to gl_Layer, the input gl_Layer 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. 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 Β© 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