Is sampler2DRect really necessary ?

According to GLSL 1.4 spec, all texture lookup functions (including texelFetch) which works with sampler2DRect also work with sampler2D.

IMHO, the only advantage in using sampler2DRect is that we can sample texels using non-normalized uv coordinates. I think sampler2D supersedes sampler2DRect, and sampler2DRect seems unnecessary because it has various disadvantages like no mipmap filtering or restricted texture wrap modes which sampler2D doesn’t (Am I missing something ?)

I want to know in what case sampler2DRect is fit more than sampler2D and what the advantage of sampler2DRect over sampler2D is.

With rectangle textures the GPU has more options for optimizations, because their capabilities are clearly limited, whereas with NPOT 2D textures the GPU must actually use additional computations to achieve the same thing. The driver COULD analyze what settings are used on a 2D texture (e.g. no mipmapping, etc.) and then choose a fast-path similar to rectangle textures, but this is cumbersome for the driver AND the developer and thus error-prone (the developer would need to very carefully select the states to actually get the fast-path, instead of just saying “this is a rectangle texture”).

However the real advantage is, that when you work in screen-space for post-processing effects it gets much easier for the programmer to work with non-normalized texture coordinates. Especially with deferred rendering many shaders work in screen-space.

Rectangle textures where supposed to be removed in GL 3.0, but after more consideration and a lot of complaints from developers that like this convenient format, it was kept. In my opinion it is better to have this convenience feature, than to remove it.

Jan.

With texel fetches in core, I cant think of any real difference between the two.

<pedantic>
There are a couple of differences:

  • Rect samplers support CLAMP, CLAMP_TO_EDGE, CLAMP_TO_BORDER wrapping. Fetch samplers return undefined results for border texels.

  • Rect samplers support filtering, including min/mag crossover (even though there is only one LOD, the switchover may change from nearest to linear filtering.) Fetch samplers only support nearest filtering.

  • Rect samplers support shadow comparison. Fetch samplers don’t.

Each of those have real-world applications (clamp to border for alpha discard, bilinear filtering on any stretchblit, projected shadows.) Each can be manually emulated with fetch samplers, but that’s more code you have to write in the shader, and you’re not using the native hardware.