GLSAMPLERPARAMETER(3G)

🌸 NAME 🌸

glSamplerParameter β€” set sampler parameters. This is the glSamplerParameter(3G) manual page, and yes the original header literally has [FIXME: manual] in it, so we’re respectfully keeping that chaotic energy πŸ’€βœ¨

πŸ’– C SPECIFICATION πŸ’–

okay bestie, here are the actual C signatures, untouched and iconic:

void glSamplerParameterf(GLuint sampler, GLenum pname, GLfloat param);

void glSamplerParameteri(GLuint sampler, GLenum pname, GLint param);

void glSamplerParameterfv(GLuint sampler, GLenum pname,
                          const GLfloat * params);

void glSamplerParameteriv(GLuint sampler, GLenum pname,
                          const GLint * params);

void glSamplerParameterIiv(GLuint sampler, GLenum pname,
                           const GLint *params);

void glSamplerParameterIuiv(GLuint sampler, GLenum pname,
                            const GLuint *params);

🫢 PARAMETERS 🫢

  • sampler β€” specifies the sampler object whose parameter to modify.
  • pname β€” specifies the symbolic name of a sampler parameter. pname can be one of the following: GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T, GL_TEXTURE_WRAP_R, GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER, GL_TEXTURE_BORDER_COLOR, GL_TEXTURE_MIN_LOD, GL_TEXTURE_MAX_LOD, GL_TEXTURE_LOD_BIAS, GL_TEXTURE_COMPARE_MODE, or GL_TEXTURE_COMPARE_FUNC.
  • param β€” for the scalar commands, specifies the value of pname.
  • params β€” for the vector commands (glSamplerParameter*v), specifies a pointer to an array where the value or values of pname are stored.

✨ DESCRIPTION ✨

okay so glSamplerParameter assigns the value or values in params to the sampler parameter specified as pname. The sampler argument specifies the sampler object to be modified, and it must be the name of a sampler object previously returned from a call to glGenSamplers().

bestie, this is not a β€œpick any random number” situation β€” that sampler name has to come from glGenSamplers() first πŸ’…

The following symbols are accepted in pname:

🧚 GL_TEXTURE_MIN_FILTER

The texture minifying function is used whenever the pixel being textured maps to an area greater than one texture element. There are six defined minifying functions, no cap. Two of them use the nearest one or nearest four texture elements to compute the texture value. The other four use mipmaps.

A mipmap is an ordered set of arrays representing the same image at progressively lower resolutions. If the texture has dimensions 2 n Γ— 2 m, there are max ⁑ n m + 1 mipmaps. The first mipmap is the original texture, with dimensions 2 n Γ— 2 m. Each subsequent mipmap has dimensions 2 k - 1 Γ— 2 l - 1, where 2 k Γ— 2 l are the dimensions of the previous mipmap, until either k = 0 or l = 0. At that point, subsequent mipmaps have dimension 1 Γ— 2 l - 1 or 2 k - 1 Γ— 1 until the final mipmap, which has dimension 1 Γ— 1. To define the mipmaps, call glTexImage1D(), glTexImage2D(), glTexImage3D(), glCopyTexImage1D(), or glCopyTexImage2D() with the level argument indicating the order of the mipmaps. Level 0 is the original texture; level max ⁑ n m is the final 1 Γ— 1 mipmap.

params supplies a function for minifying the texture as one of the following:

  • GL_NEAREST β€” returns the value of the texture element that is nearest (in Manhattan distance) to the center of the pixel being textured.
  • GL_LINEAR β€” returns the weighted average of the four texture elements that are closest to the center of the pixel being textured. These can include border texture elements, depending on the values of GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T, and on the exact mapping.
  • GL_NEAREST_MIPMAP_NEAREST β€” chooses the mipmap that most closely matches the size of the pixel being textured and uses the GL_NEAREST criterion (the texture element nearest to the center of the pixel) to produce a texture value.
  • GL_LINEAR_MIPMAP_NEAREST β€” chooses the mipmap that most closely matches the size of the pixel being textured and uses the GL_LINEAR criterion (a weighted average of the four texture elements that are closest to the center of the pixel) to produce a texture value.
  • GL_NEAREST_MIPMAP_LINEAR β€” chooses the two mipmaps that most closely match the size of the pixel being textured and uses the GL_NEAREST criterion (the texture element nearest to the center of the pixel) to produce a texture value from each mipmap. The final texture value is a weighted average of those two values.
  • GL_LINEAR_MIPMAP_LINEAR β€” chooses the two mipmaps that most closely match the size of the pixel being textured and uses the GL_LINEAR criterion (a weighted average of the four texture elements that are closest to the center of the pixel) to produce a texture value from each mipmap. The final texture value is a weighted average of those two values.

As more texture elements are sampled in the minification process, fewer aliasing artifacts will be apparent. While the GL_NEAREST and GL_LINEAR minification functions can be faster than the other four, they sample only one or four texture elements to determine the texture value of the pixel being rendered and can produce moire patterns or ragged transitions. The initial value of GL_TEXTURE_MIN_FILTER is GL_NEAREST_MIPMAP_LINEAR.

🌈 GL_TEXTURE_MAG_FILTER

The texture magnification function is used when the pixel being textured maps to an area less than or equal to one texture element. It sets the texture magnification function to either GL_NEAREST or GL_LINEAR (see below). GL_NEAREST is generally faster than GL_LINEAR, but it can produce textured images with sharper edges because the transition between texture elements is not as smooth. The initial value of GL_TEXTURE_MAG_FILTER is GL_LINEAR.

  • GL_NEAREST β€” returns the value of the texture element that is nearest (in Manhattan distance) to the center of the pixel being textured.
  • GL_LINEAR β€” returns the weighted average of the four texture elements that are closest to the center of the pixel being textured. These can include border texture elements, depending on the values of GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T, and on the exact mapping.

πŸ¦‹ GL_TEXTURE_MIN_LOD

Sets the minimum level-of-detail parameter. This floating-point value limits the selection of highest resolution mipmap (lowest mipmap level). The initial value is -1000.

πŸ“ GL_TEXTURE_MAX_LOD

Sets the maximum level-of-detail parameter. This floating-point value limits the selection of lowest resolution mipmap (highest mipmap level). The initial value is 1000.

πŸŽ€ GL_TEXTURE_WRAP_S

Sets the wrap parameter for texture coordinate s to either GL_CLAMP_TO_EDGE, GL_MIRRORED_REPEAT, GL_REPEAT, or GL_MIRROR_CLAMP_TO_EDGE. GL_CLAMP_TO_BORDER causes the s coordinate to be clamped to the range -1 2N 1 + 1 2N, where N is the size of the texture in the direction of clamping. GL_CLAMP_TO_EDGE causes s coordinates to be clamped to the range 1 2N 1 - 1 2N, where N is the size of the texture in the direction of clamping. GL_REPEAT causes the integer part of the s coordinate to be ignored; the GL uses only the fractional part, thereby creating a repeating pattern. GL_MIRRORED_REPEAT causes the s coordinate to be set to the fractional part of the texture coordinate if the integer part of s is even; if the integer part of s is odd, then the s texture coordinate is set to 1 - frac ⁑ s, where frac ⁑ s represents the fractional part of s. GL_MIRROR_CLAMP_TO_EDGE causes the s coordinate to be repeated as for GL_MIRRORED_REPEAT for one repetition of the texture, at which point the coordinate to be clamped as in GL_CLAMP_TO_EDGE. Initially, GL_TEXTURE_WRAP_S is set to GL_REPEAT.

πŸ’œ GL_TEXTURE_WRAP_T

Sets the wrap parameter for texture coordinate t to either GL_CLAMP_TO_EDGE, GL_MIRRORED_REPEAT, GL_REPEAT, or GL_MIRROR_CLAMP_TO_EDGE. See the discussion under GL_TEXTURE_WRAP_S. Initially, GL_TEXTURE_WRAP_T is set to GL_REPEAT.

🌸 GL_TEXTURE_WRAP_R

Sets the wrap parameter for texture coordinate r to either GL_CLAMP_TO_EDGE, GL_MIRRORED_REPEAT, GL_REPEAT, or GL_MIRROR_CLAMP_TO_EDGE. See the discussion under GL_TEXTURE_WRAP_S. Initially, GL_TEXTURE_WRAP_R is set to GL_REPEAT.

πŸ‘‘ GL_TEXTURE_BORDER_COLOR

The data in params specifies four values that define the border values that should be used for border texels. If a texel is sampled from the border of the texture, the values of GL_TEXTURE_BORDER_COLOR are interpreted as an RGBA color to match the texture’s internal format and substituted for the non-existent texel data. If the texture contains depth components, the first component of GL_TEXTURE_BORDER_COLOR is interpreted as a depth value. The initial value is 0.0 , 0.0 , 0.0 , 0.0.

πŸ”₯ GL_TEXTURE_COMPARE_MODE

Specifies the texture comparison mode for currently bound textures. That is, a texture whose internal format is GL_DEPTH_COMPONENT_*; see glTexImage2D()) Permissible values are:

  • GL_COMPARE_REF_TO_TEXTURE β€” specifies that the interpolated and clamped r texture coordinate should be compared to the value in the currently bound texture. See the discussion of GL_TEXTURE_COMPARE_FUNC for details of how the comparison is evaluated. The result of the comparison is assigned to the red channel.
  • GL_NONE β€” specifies that the red channel should be assigned the appropriate value from the currently bound texture.

πŸ’… GL_TEXTURE_COMPARE_FUNC

okay so this one specifies the comparison operator that gets used when GL_TEXTURE_COMPARE_MODE is set to GL_COMPARE_REF_TO_TEXTURE. That's the whole vibe β€” you're telling it how to compare. πŸŽ€

The permissible values are, and yes, each one comes with its own "Computed result" situation:

  • GL_LEQUAL β€” computed result is 1.0 where r <= D_t, and 0.0 where r > D_t. Iconic little hard flip at the line ✨
result
 1.0 |β€Ύβ€Ύβ€Ύβ€Ύβ€Ύβ€Ύβ€Ύ
     |
 0.0 |_______
      r<=D_t   r>D_t
  • GL_GEQUAL β€” same energy, flipped: computed result is 1.0 where r >= D_t, and 0.0 where r < D_t. it's giving mirror image πŸ’…
result
 1.0 |     β€Ύβ€Ύβ€Ύβ€Ύβ€Ύβ€Ύβ€Ύ
     |
 0.0 |β€Ύβ€Ύβ€Ύβ€Ύβ€Ύβ€Ύβ€Ύ
      r<D_t   r>=D_t
  • GL_LESS β€” computed result is 1.0 on the side where r < D_t, and 0.0 on the other side of the line (ngl the table graphic in this rendering gets cut off right there 😭 but the 1.0 / 0.0 pair is on the same axes, with the boundary drawn at D_t)
result
 1.0 |     β€Ύβ€Ύβ€Ύβ€Ύβ€Ύβ€Ύβ€Ύ
     |
 0.0 |β€Ύβ€Ύβ€Ύβ€Ύβ€Ύβ€Ύβ€Ύ
      r<D_t    …

also bestie, quick vibe check on the axes: the horizontal axis is labeled r, and the marker on it is the one referenced in the comparison (D_t), with the < / <= / >= sitting right at that point. The vertical axis tops out at 1.0 and bottoms out at 0.0 β€” that's it, that's the whole graph. 🌸

okay bestie, we're still in the glow-up chart of comparison functions πŸ’… and here's where it gets good β€” each row is a function, and next to it there's a lil' plot πŸ“ˆ where the y-axis is result (chillin' between 0.0 and 1.0, no other values, that's it, that's the whole range) and the x-axis is r/Dt β€” yup, literally the label on the axis is r, then the comparison operator, then Dt. So the graph is telling you the comparison it's doing. Iconic behaviour honestly πŸŽ€


πŸ¦‹ the rows, one by one

  • GL_GREATER β€” the row plots result against r/Dt, and the comparison written on the axis is r > Dt. The plot marks 1.0 and 0.0 on the result side so you can see the two possible outcomes. That's the whole vibe: does r beat Dt? πŸ‘‘
result
 1.0 ─                     β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
     β”‚                     β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
 0.0 ─ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
     └─────────────────────┬──────────
                          r > Dt

(yes the actual book draws it out too, we're just keeping it cute ✨)

  • GL_EQUAL β€” same setup, same axes, same 1.0 / 0.0 result band, except the comparison on the axis is r = Dt. So this one's the "are they literally the same" check, and the graph shows result sitting at 1.0 right where that's true and 0.0 everywhere else 🫢
result
 1.0 ─           β–ˆβ–ˆ
     β”‚           β–ˆβ–ˆ
 0.0 ─ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
     └───────────┬──────────────
                r = Dt
  • GL_NOTEQUAL β€” the "not like the others" main character πŸ’€ same graph skeleton, result on the y-axis between 0.0 and 1.0, r/Dt on the x-axis, and the operator printed on the axis is r β‰  Dt. So 1.0 is the "nope, different" answer and 0.0 is the "same" answer. Flipped energy. Obsessed 🌸
result
 1.0 ─ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ          β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
     β”‚ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ          β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
 0.0 ─           β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ
     └───────────┬────────────────────
                r β‰  Dt
ngl bestie, the little operator between r and Dt is the entire content of these graphs β€” the shape of the curve just shows you where result lands at 1.0 versus 0.0 for that comparison. Read the operator, that's the ✨tea✨

and yeah β€” the table keeps scrolling, there's more rows below this, so don't close the tab yet 🧚

…and here's where we pick up that comparison table β€” the tail end of it, bestie, the last two rows:

  • GL_ALWAYS β†’ result = 1.0
  • GL_NEVER β†’ result = 0.0

where r is the current interpolated texture coordinate, and D t is the texture value sampled from the currently bound texture. result is assigned to R t. πŸ’…


✨ NOTES ✨

  • glSamplerParameter is available only if the GL version is 3.3 or higher. Like, don't come for her if you're on 3.2, she literally isn't there yet. 🫢
  • Okay so this part is kind of a big deal: if a sampler object is bound to a texture unit and that unit is used to sample from a texture, the parameters in the sampler are used to sample from the texture, rather than the equivalent parameters in the texture object bound to that unit. The sampler ate, no cap. πŸ‘‘

This introduces the possibility of sampling from the same texture object with different sets of sampler state β€” which may lead to a condition where a texture is incomplete with respect to one sampler object and not with respect to another. 😭 So, like, completeness can be considered a function of a sampler object and a texture object bound to a single texture unit, rather than a property of the texture object itself. She's a shared experience, she's not defined by one unit. periodt.

  • GL_MIRROR_CLAMP_TO_EDGE is available only if the GL version is 4.4 or greater. newer-girl privilege fr fr πŸŽ€

πŸ’€ ERRORS πŸ’€

  • GL_INVALID_VALUE is generated if sampler is not the name of a sampler object previously returned from a call to glGenSamplers(). bestie, you can't just make up a name and expect her to answer. πŸ™ˆ
  • GL_INVALID_ENUM is generated if params should have a defined constant value (based on the value of pname) and does not. wrong enum, wrong vibe, blocked. πŸ’…

πŸ” ASSOCIATED GETS πŸ”

  • glGetSamplerParameter()

🌈 VERSION SUPPORT 🌈

So here's the whole mood board of which function slays in which OpenGL version. In every single row: 2.0, 2.1, 3.0 and 3.1 get a big fat - (she was not invited), and then 3.2, 3.3, 4.0, 4.1, 4.2, 4.3, 4.4 and 4.5 all get the βœ” glow-up. ✨

  • glSamplerParameterIiv β€” - in 2.0, 2.1, 3.0, 3.1; βœ” in 3.2, 3.3, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5
  • glSamplerParameterIuiv β€” - in 2.0, 2.1, 3.0, 3.1; βœ” in 3.2, 3.3, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5
  • glSamplerParameterf β€” - in 2.0, 2.1, 3.0, 3.1; βœ” in 3.2, 3.3, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5
  • glSamplerParameterfv β€” - in 2.0, 2.1, 3.0, 3.1; βœ” in 3.2, 3.3, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5
  • glSamplerParameteri β€” - in 2.0, 2.1, 3.0, 3.1; βœ” in 3.2, 3.3, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5
  • glSamplerParameteriv β€” - in 2.0, 2.1, 3.0, 3.1; βœ” in 3.2, 3.3, 4.0, 4.1, 4.2, 4.3, 4.4, 4.5

(the column header for all of that is, obviously, OpenGL Version β€” and the row header is Function / Feature Name, because she contains multitudes πŸ¦‹)


πŸ‘€ SEE ALSO πŸ‘€

Go give these icons a read, they're all in the same group chat:

  • glGenSamplers()
  • glBindSampler()
  • glDeleteSamplers()
  • glIsSampler()
  • glBindTexture()
  • glTexParameter()

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 Β© 2010-2014 KhronosGroup


okay that's the whole page, you made it, I'm so proud of you πŸ«ΆπŸ’– The source line up top is literally just [FIXME: source] (yes, the manpage authors left us on read πŸ™ˆ) and it's dated 08/09/2021, and it's GLSAMPLERPARAMETER(3G) in case you forgot where you were. go bind some samplers bestie, you've got this πŸ’…βœ¨πŸŒΈ

πŸ“¦ where this page comes from