glTextureParameteri
Sets one integer setting of a texture (filtering, wrapping…) by its ID.
Signature
void glTextureParameteri(GLuint texture, GLenum pname, GLint param);
How it works
The DSA form of glTexParameteri: the same names and values, but the texture is the first argument, so nothing has to be bound to a target first. Settings belong to the texture and stay until you change them; set them once after creating it.
The two settings almost every texture needs are the filters. The default minification filter, GL_NEAREST_MIPMAP_LINEAR, expects mipmaps: without them (or without glGenerateTextureMipmap) the texture is incomplete and samples as black.
Parameters
The texture (from glCreateTextures).
Which setting.
Common values
- GL_TEXTURE_MIN_FILTER
- Filter when the texture is shrunk: GL_LINEAR_MIPMAP_LINEAR (smooth, needs mipmaps), GL_LINEAR, GL_NEAREST.
- GL_TEXTURE_MAG_FILTER
- Filter when it is enlarged: GL_LINEAR (smooth) or GL_NEAREST (pixel art).
- GL_TEXTURE_WRAP_S / _T / _R
- What happens outside 0..1: GL_REPEAT, GL_MIRRORED_REPEAT, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_BORDER.
- GL_TEXTURE_BASE_LEVEL / GL_TEXTURE_MAX_LEVEL
- Range of mip levels the sampler may use.
- GL_TEXTURE_COMPARE_MODE
- GL_COMPARE_REF_TO_TEXTURE turns a depth texture into a shadow sampler (sampler2DShadow).
The new value, usually an enum such as GL_LINEAR.
Tips & pitfalls
Direct State Access (GL 4.5): the object is passed as a parameter, so nothing needs to be bound and no global state is disturbed.
A separate sampler object (glBindSampler) overrides these settings while it is bound to the unit.
Errors
When the call is invalid it does nothing and sets an error, which glGetError returns:
- GL_INVALID_ENUM
- pname or param is not accepted.
- GL_INVALID_OPERATION
- texture is not the name of an existing texture.
Example
1glTextureParameteri(tex, GL_TEXTURE_WRAP_S, GL_REPEAT);
2glTextureParameteri(tex, GL_TEXTURE_WRAP_T, GL_REPEAT);
3glTextureParameteri(tex, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
4glTextureParameteri(tex, GL_TEXTURE_MAG_FILTER, GL_LINEAR);