GLBINDTEXTURE(3G)

πŸ’… GLBINDTEXTURE β€” it's giving texture binding, bestie

okay so real talk, this is the 3G girlies' manual page for glBindTexture, and it's honestly one of the most main-character functions in all of OpenGL. Let's get into it ✨


🌸 NAME

glBindTexture β€” bind a named texture to a texturing target


πŸŽ€ C SPECIFICATION

void glBindTexture(GLenum target, GLuint texture);

literally the whole signature. no notes. πŸ’…


✨ PARAMETERS

  • target β€” tells GL where you're binding the texture. Has to be one of: GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D, GL_TEXTURE_1D_ARRAY, GL_TEXTURE_2D_ARRAY, GL_TEXTURE_RECTANGLE, GL_TEXTURE_CUBE_MAP, GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_BUFFER, GL_TEXTURE_2D_MULTISAMPLE or GL_TEXTURE_2D_MULTISAMPLE_ARRAY. pick one, queen 🫢
  • texture β€” the name of a texture. yes, just the name β€” not the whole texture, the name. it's a whole thing.

πŸ”₯ DESCRIPTION

so glBindTexture lets you create or use a named texture. πŸ¦‹

when you call glBindTexture with target set to GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D, GL_TEXTURE_1D_ARRAY, GL_TEXTURE_2D_ARRAY, GL_TEXTURE_RECTANGLE, GL_TEXTURE_CUBE_MAP, GL_TEXTURE_CUBE_MAP_ARRAY, GL_TEXTURE_BUFFER, GL_TEXTURE_2D_MULTISAMPLE or GL_TEXTURE_2D_MULTISAMPLE_ARRAY, and texture set to the name of the new texture, it binds that texture name to that target. and the moment a texture is bound to a target, the previous binding for that target is automatically broken β€” like, no ceremony, it's just over πŸ’€

okay now the lore:

Texture names are unsigned integers. The value zero is reserved to represent the default texture for each texture target. Texture names and the corresponding texture contents are local to the shared object space of the current GL rendering context β€” and two rendering contexts only share texture names if they explicitly enable sharing between contexts through the appropriate GL windows interfaces functions. iykyk. πŸ‘‘

you must use glGenTextures() to generate a set of new texture names. no DIY names, bestie, that's not the vibe.

When a texture is first bound, it assumes the specified target. this is genuinely the most iconic part, so buckle up:

  • a texture first bound to GL_TEXTURE_1D becomes one-dimensional texture
  • a texture first bound to GL_TEXTURE_2D becomes two-dimensional texture
  • a texture first bound to GL_TEXTURE_3D becomes three-dimensional texture
  • a texture first bound to GL_TEXTURE_1D_ARRAY becomes one-dimensional array texture
  • a texture first bound to GL_TEXTURE_2D_ARRAY becomes two-dimensional array texture
  • a texture first bound to GL_TEXTURE_RECTANGLE becomes rectangle texture
  • a texture first bound to GL_TEXTURE_CUBE_MAP becomes a cube-mapped texture
  • a texture first bound to GL_TEXTURE_CUBE_MAP_ARRAY becomes a cube-mapped array texture
  • a texture first bound to GL_TEXTURE_BUFFER becomes a buffer texture
  • a texture first bound to GL_TEXTURE_2D_MULTISAMPLE becomes a two-dimensional multisampled texture
  • a texture first bound to GL_TEXTURE_2D_MULTISAMPLE_ARRAY becomes a two-dimensional multisampled array texture

periodt. 🌈

and listen β€” the state of a one-dimensional texture immediately after it is first bound is equivalent to the state of the default GL_TEXTURE_1D at GL initialization, and similarly for the other texture types. so it's a clean slate, it's a fresh start, it's a new semester. 🧚

While a texture is bound, GL operations on the target to which it is bound affect the bound texture, and queries of the target to which it is bound return state from the bound texture. in effect: the texture targets become aliases for the textures currently bound to them, and the texture name zero refers to the default textures that were bound to them at initialization. it's giving identity theft but make it legal. πŸ™ˆ

a texture binding created with glBindTexture remains active until a different texture is bound to the same target, or until the bound texture is deleted with glDeleteTextures(). those are the only two ways out, fr fr.

and once created, a named texture may be re-bound to its same original target as often as needed. plus β€” and this is the tip that ate β€” it is usually much faster to use glBindTexture to bind an existing named texture to one of the texture targets than it is to reload the texture image using glTexImage1D(), glTexImage2D(), glTexImage3D() or another similar function. so stop reloading, start rebinding, your framerate will thank you πŸ”₯


πŸ’œ NOTES

the GL_TEXTURE_2D_MULTISAMPLE and GL_TEXTURE_2D_MULTISAMPLE_ARRAY targets are available only if the GL version is 3.2 or higher. no 3.2, no multisample, that's the rule πŸŽ€


😭 ERRORS

  • GL_INVALID_ENUM is generated if target is not one of the allowable values. pick a real target bestie.
  • GL_INVALID_VALUE is generated if texture is not a name returned from a previous call to glGenTextures(). like I said β€” glGenTextures(), always.
  • GL_INVALID_OPERATION is generated if texture was previously created with a target that doesn't match that of target. the target said what it said πŸ’€

🌟 ASSOCIATED GETS

glGet() with argument GL_TEXTURE_BINDING_1D, GL_TEXTURE_BINDING_2D, GL_TEXTURE_BINDING_3D, GL_TEXTURE_BINDING_1D_ARRAY, GL_TEXTURE_BINDING_2D_ARRAY, GL_TEXTURE_BINDING_RECTANGLE, GL_TEXTURE_BINDING_BUFFER, GL_TEXTURE_BINDING_CUBE_MAP, GL_TEXTURE_BINDING_CUBE_MAP, GL_TEXTURE_BINDING_CUBE_MAP_ARRAY, GL_TEXTURE_BINDING_2D_MULTISAMPLE, or GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY.

yes, GL_TEXTURE_BINDING_CUBE_MAP really is listed twice up there. that's the page, not me. I don't make the rules, I just vibe with them 🫢

πŸ‘‘ VERSION SUPPORT

the whole grid, but make it a list β€” glBindTexture is supported (βœ”) in every single one of these OpenGL versions:

  1. 2.0 βœ”
  2. 2.1 βœ”
  3. 3.0 βœ”
  4. 3.1 βœ”
  5. 3.2 βœ”
  6. 3.3 βœ”
  7. 4.0 βœ”
  8. 4.1 βœ”
  9. 4.2 βœ”
  10. 4.3 βœ”
  11. 4.4 βœ”
  12. 4.5 βœ”

all checks, no notes, she's been booked and busy since 2.0 πŸ’…βœ¨


πŸ¦‹ SEE ALSO

glDeleteTextures(), glGenTextures(), glGet(), glGetTexParameter(), glIsTexture(), glTexImage1D(), glTexImage2D(), glTexImage2DMultisample(), glTexImage3D(), glTexImage3DMultisample(), glTexBuffer(), glTexParameter()

go read those next, bestie, they're all part of the same friend group 🌸


Copyright Β© 1991-2006 Silicon Graphics, Inc. Copyright Β© 2010-2014 Khronos Group. This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB/.

Copyright Β© 1991-2006 Silicon Graphics, Inc. Copyright Β© 2010-2014 Khronos Group


okay that's the whole page, mwah πŸ’‹ β€” this little drop came from [FIXME: source] and it's dated 08/09/2021, so if you're reading this in the future, know that your girl was out here binding textures with the 2021 energy. stay iconic, go bind something πŸŽ€βœ¨πŸ«Ά

πŸ“¦ where this page comes from