GLBINDATTRIBLOCATION(3G)

πŸ’… GLBINDATTRIBLOCATION (3G) β€” the glBindAttribLocation glow-up

okay so bestie, this is the glBindAttribLocation page from the 3G manual set β€” yes, the OpenGL one, the one that lets your vertex shader have cute names instead of sad little numbers. sit down, hydrate, let's get into it 🫢


✨ NAME ✨

glBindAttribLocation β€” associates a generic vertex attribute index with a named attribute variable. that's it, that's the whole vibe.


🧾 C SPECIFICATION 🧾

void glBindAttribLocation(GLuint program, GLuint index,
                          const GLchar *name);

literally the whole signature, no notes, copy it exactly girl πŸ’…


πŸŽ€ PARAMETERS πŸŽ€

  • program β€” the handle of the program object where you're making this association happen. the one getting the makeover.
  • index β€” the index of the generic vertex attribute you're binding. a number, bestie.
  • name β€” a null terminated string holding the name of the vertex shader attribute variable that index is gonna be bound to. null terminated, don't forget, iykyk.

🌸 DESCRIPTION 🌸

so glBindAttribLocation is used to associate a user-defined attribute variable in the program object specified by program with a generic vertex attribute index. the name of that user-defined attribute variable gets passed as a null terminated string in name, and the generic vertex attribute index to be bound to this variable is specified by index. when program is made part of current state, values provided via the generic vertex attribute index will modify the value of the user-defined attribute variable specified by name. slay, that's the whole mechanic πŸ’–

now if name refers to a matrix attribute variable, index refers to the first column of the matrix. the other matrix columns are then automatically bound to locations, and here's the receipts:

  • index+1 for a matrix of type mat2
  • index+1 and index+2 for a matrix of type mat3
  • index+1, index+2, and index+3 for a matrix of type mat4

this command makes it possible for vertex shaders to use descriptive names for attribute variables rather than generic variables that are numbered from zero to the value of GL_MAX_VERTEX_ATTRIBS minus one. no cap, descriptive names are the main character energy here. the values sent to each generic attribute index are part of current state. and if a different program object is made current by calling glUseProgram(), the generic vertex attributes are tracked in such a way that the same values will be observed by attributes in the new program object that are also bound to index. continuity! we love her 🌈

attribute variable name-to-generic attribute index bindings for a program object can be explicitly assigned at any time by calling glBindAttribLocation. but β€” and this is the important part β€” attribute bindings do not go into effect until glLinkProgram() is called. after a program object has been linked successfully, the index values for generic attributes remain fixed (and their values can be queried) until the next link command occurs.

and any attribute binding that occurs after the program object has been linked will not take effect until the next time the program object is linked. timing is everything bestie, the linker is the one who decides ⭐


πŸ’€ NOTES πŸ’€

glBindAttribLocation can be called before any vertex shader objects are bound to the specified program object. it's also permissible to bind a generic attribute index to an attribute variable name that is never used in a vertex shader. ghost attribute? allowed. iconic.

if name was bound previously, that information is lost. so you cannot bind one user-defined attribute variable to multiple indices, but you can bind multiple user-defined attribute variables to the same index. balance πŸ’…

applications are allowed to bind more than one user-defined attribute variable to the same generic vertex attribute index. this is called aliasing, and it is allowed only if just one of the aliased attributes is active in the executable program, or if no path through the shader consumes more than one attribute of a set of attributes aliased to the same location. the compiler and linker are allowed to assume that no aliasing is done and are free to employ optimizations that work only in the absence of aliasing. and OpenGL implementations are not required to do error checking to detect aliasing. so yeah, that's on you 🫠

active attributes that are not explicitly bound will be bound by the linker when glLinkProgram() is called. the locations assigned can be queried by calling glGetAttribLocation().

OpenGL copies the name string when glBindAttribLocation is called, so an application may free its copy of the name string immediately after the function returns. free it and move on, she has her own copy now ✨

generic attribute locations may be specified in the shader source text using a location layout qualifier. in this case, the location of the attribute specified in the shader's source takes precedence and may be queried by calling glGetAttribLocation(). shader source wins the argument, periodt πŸ‘‘


πŸ™ˆ ERRORS πŸ™ˆ

  • GL_INVALID_VALUE is generated if index is greater than or equal to GL_MAX_VERTEX_ATTRIBS.
  • GL_INVALID_OPERATION is generated if name starts with the reserved prefix "gl_". that prefix is taken, bestie, it's not yours.
  • GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.
  • GL_INVALID_OPERATION is generated if program is not a program object.

πŸ” ASSOCIATED GETS πŸ”

  • glGet() with argument GL_MAX_VERTEX_ATTRIBS
  • glGetActiveAttrib() with argument program
  • glGetAttribLocation() with arguments program and name
  • glIsProgram()

πŸ‘‘ VERSION SUPPORT πŸ‘‘

glBindAttribLocation shows up in every OpenGL version listed, no skips, no gaps β€” she ate and left no crumbs πŸ”₯

  • Function / Feature Name: glBindAttribLocation
  • OpenGL 2.0 β€” βœ”
  • OpenGL 2.1 β€” βœ”
  • OpenGL 3.0 β€” βœ”
  • OpenGL 3.1 β€” βœ”
  • OpenGL 3.2 β€” βœ”
  • OpenGL 3.3 β€” βœ”
  • OpenGL 4.0 β€” βœ”
  • OpenGL 4.1 β€” βœ”
  • OpenGL 4.2 β€” βœ”
  • OpenGL 4.3 β€” βœ”
  • OpenGL 4.4 β€” βœ”
  • OpenGL 4.5 β€” βœ”

thirteen for thirteen, flawless sweep 🧚


πŸ¦‹ SEE ALSO πŸ¦‹

  • glDisableVertexAttribArray
  • glEnableVertexAttribArray()
  • glUseProgram()
  • glVertexAttrib()
  • glVertexAttribPointer()

go read those next, i'm obsessed with you for actually following the cross-references πŸ’œ


Copyright Β© 2003-2005 3Dlabs Inc. Ltd. Copyright Β© 2010-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 Β© 2003-2005 3Dlabs Inc. Ltd. Copyright Β© 2010-2014 Khronos Group


okay that's the whole page bestie, you're officially versed in attribute binding πŸ’–

and for the sign-off: this glorious text came from [FIXME: source], dated 08/09/2021, living under the GLBINDATTRIBLOCATION(3G) manual header β€” take care of her, she's iconic πŸŽ€πŸŒΈπŸ«Ά

πŸ“¦ where this page comes from