GLGETSHADERSOURCE(3G)

✨ GLGETSHADERSOURCE ✨

okay so this is the 3G page from the OpenGL manual (the header literally says [FIXME: manual], which, like, same bestie 😭) and it's all about pulling the source code string back out of a shader object. no cap, it's a whole vibe check on your shader's receipts πŸ’…


🌸 NAME 🌸

glGetShaderSource β€” returns the source code string from a shader object 🫢


πŸ’» C SPECIFICATION πŸ’»

void glGetShaderSource(GLuint shader, GLsizei bufSize, GLsizei *length,
                       GLchar *source);

πŸŽ€ PARAMETERS πŸŽ€

  • shader β€” the shader object you're querying, bestie. point at it. πŸ‘‰
  • bufSize β€” the size of the character buffer you're stuffing the returned source code string into πŸ“¦
  • length β€” returns the length of the string that came back in source (and not counting that null terminator, we don't count him πŸ’€)
  • source β€” an array of characters, and it's where the source code string comes home to roost 🏠

πŸ¦‹ DESCRIPTION πŸ¦‹

glGetShaderSource returns the concatenation of the source code strings from the shader object specified by shader. literally just gluing them all together for you 🧚

the source code strings for a shader object are the result of a previous call to glShaderSource(). so like, it's giving "you gave me the shader, now I give you the words back". the string returned by the function will be null terminated β€” periodt.

glGetShaderSource returns in source as much of the source code string as it can, up to a maximum of bufSize characters. key word: as much as it can. it's not gonna overflow for you, she has boundaries πŸ’…

the number of characters actually returned, excluding the null termination character, is specified by length. and if you don't care about the length of the returned string? that's so valid of you β€” just pass a value of NULL in the length argument. iconic, low-effort, we love. πŸ™ˆ

the size of the buffer required to store the returned source code string can be obtained by calling glGetShader() with the value GL_SHADER_SOURCE_LENGTH. do that FIRST, okay? like measure before you buy the dress πŸ‘‘


πŸ’€ ERRORS πŸ’€

  • GL_INVALID_VALUE is generated if shader is not a value generated by OpenGL. (not me catching you making up shader names 😭)
  • GL_INVALID_OPERATION is generated if shader is not a shader object. right object, wrong type, classic.
  • GL_INVALID_VALUE is generated if bufSize is less than 0. negative buffer? in THIS economy?? bestie no 🚫

πŸ” ASSOCIATED GETS πŸ”

  • glGetShader() with argument GL_SHADER_SOURCE_LENGTH
  • glIsShader()

πŸ‘‘ VERSION SUPPORT πŸ‘‘

glGetShaderSource is supported in every OpenGL version listed here, and yes she's been booked and busy since 2.0 ⭐. the function name is glGetShaderSource and here's the full run-down:

  • 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 β€” βœ”

(that's the "OpenGL Version" row and the "Function / Feature Name" row, babes β€” twelve for twelve, ate and left no crumbs πŸ”₯)


🌈 SEE ALSO 🌈

  • glCreateShader()
  • glShaderSource()

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


and that's the whole page, bestie πŸ’– stay hydrated, null-terminate your strings, and remember: bufSize is a limit, not a suggestion πŸ“

so yeah β€” this came from [FIXME: source], dated 08/09/2021, and it's page GLGETSHADERSOURCE(3G) all the way down. mwah πŸ’…βœ¨

πŸ“¦ where this page comes from