Search code examples
openglglslfragment-shadertexture2drender-to-texture

GLSL texelFetchOffset works with isampler2D but not usampler2D?


In a fragment shader, the following compiles fine:

uniform isampler2D testTexture;
/* in main() x, y, xoff and yoff are declared as int and assigned here, then... */
int tmp = texelFetchOffset(testTexture, ivec2(x, y), 0, ivec2(xoff, yoff)).r;

However, the following does not compile:

uniform usampler2D testTexture;
/* in main() x, y, xoff and yoff are declared as uint and assigned here, then... */
uint tmp = texelFetchOffset(testTexture, uvec2(x, y), 0, uvec2(xoff, yoff)).r;

The OpenGL 4.2 driver gives the following compiler error message:

error C1115: unable to find compatible overloaded function "texelFetchOffset(usampler2D, uvec2, int, uvec2)

This is Nvidia's Linux driver 290.* for a Quadro 5010M -- but I'm wondering if I made a (beginner) mistake and was not working to spec somehow here?


Solution

  • The texelFetchOffset function that takes a usampler2D still takes an ivec2 as its texture coordinates and offset. The u only applies to the sampler type and return value; not everything about the function becomes unsigned.

    And remember: OpenGL doesn't allow implicit conversions between unsigned and signed integer types.