Rectangle Texture

Revision as of 02:31, 26 November 2012 by Alfonse (Talk | contribs) (Overview)

Jump to: navigation, search
Rectangle Texture
Core in version 4.5
Core since version 2.1
ARB extension ARB_texture_rectangle
Vendor extension NV_texture_rectangle

A Rectangle Texture is a Texture that contains a single 2D image with no mipmaps. It has no power-of-two restrictions on its size. Texture coordinates for accessing this texture must be texel values (floating-point), representing texels within the texture, rather than normalized texture coordinates.


Rectangle textures are very special texture types. They are two-dimensional, but they are not textures of the type GL_TEXTURE_2D. They have their own separate texture type: GL_TEXTURE_RECTANGLE.


Storage for rectangle textures is created in the usual way. Bind the texture to the GL_TEXTURE_RECTANGLE texture target and call an appropriate function that allocates storage. For example:

glTexImage2d({{enum|GL_TEXTURE_RECTANGLE, 0, internalformat​, width​, height​, 0, format​, type​, data​);

The named parameters all work as normal for texture image specification.

Use in shaders

Rectangle textures must use samplers of the form gsampler2DRect​ or gsampler2DRectShadow​, where g represents the type of data the texture stores (float, signed integral, or unsigned integral).

When using rectangle samplers, all texture lookup functions automatically use non-normalized texture coordinates. This means that the values of the texture coordinates refer specifically to texels in texel space. The value 12.5 is halfway between the thirteenth and fourteenth texel (remember: 0-base indices).


Rectangle textures contain exactly one image; they cannot have mipmaps. Therefore, any texture parameters that depend on LODs are irrelevant when used with rectangle textures; attempting to set these parameters to any value other than 0 will result in an error. Similarly, no mipmap filtering is allowed; GL_TEXTURE_MIN_FILTER must be GL_NEAREST or GL_LINEAR. Similarly, they cannot be used with any of the gradient or LOD texture accessing functions.

Also, wrapping modes for each coordinate must be either GL_CLAMP_TO_EDGE or GL_CLAMP_TO_BORDER.


In the days before non-power-of-two textures were available, rectangle textures were the only way to have textures with irregular sizes. This was particularly useful for render targets, which often were intended to be screen-sized images.

From a modern perspective, they seem essentially useless. But even now, they do have some small purpose.

This mainly has to do with their ability to use non-normalized texture coordinates in conjunction with filtering. The texelFetch functions bypass all filtering; they take integer texture coordinates. However, with texture rectangles, you can work directly in texel coordinates, but with floating-point values. This is a useful convenience.

It could certainly be emulated by using the textureSize function to get the size and manually normalize a texture coordinate. But more often than not, rectangle textures will look more natural in the shader code.