T texelFetch(sampler2D samp, ivec2 coord, int lod = 0)
The texelFetch function allows explicit texture accesses and returns the texel (texture element) value from the texture unit samp at the texture coordinates coord. The texture coordinates coord are given in integer coordinates and represent the location of the texel in the texture.
The type T of the returned value depends on the texture's internal format. For example, if the texture is a sampler2D with an internal format of GL_RGBA8, T would be vec4.
The optional parameter lod specifies the level-of-detail to use for the texture access. If lod is not specified or set to 0, the base level-of-detail is used.
sampA sampler2D texture unit to sample from.
coordAn ivec2 vector specifying the integer texture coordinates of the texel to fetch.
lodAn optional int value indicating the level of detail to use. Default is 0.
The function returns the texel value at the specified coord in the format specified by the samp texture unit. The returned value has a type of T, which is dependent on the texture's internal format.
uniform sampler2D tex;
ivec2 coord = ivec2(2, 3);
vec3 texel = texelFetch(tex, coord).rgb;
The above code fetches the texel value at integer texture coordinates (2, 3) from the tex texture and assigns its RGB components to the texel variable.