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 integer values, representing texels within the texture, rather than normalized texture coordinates.

+

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.

== Overview ==

== Overview ==

−

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.

+

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

=== Creation ===

=== Creation ===

−

Storage for rectangle textures is created by binding a texture name to the GL_TEXTURE_RECTANGLE texture target and calling glTexImage2d:

+

Storage for rectangle textures is [[Texture Storage|created in the usual way]]. Bind the texture to the {{enum|GL_TEXTURE_RECTANGLE}} texture target and call an appropriate function that allocates storage. For example:

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

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

Line 22:

Line 22:

=== Use in shaders ===

=== Use in shaders ===

−

Rectangle textures must use [[GLSL Sampler|samplers]] of the form <code>''g''sampler2DRect</code> or <code>''g''sampler2DRectShadow</code>, where ''g'' represents the type of data the texture stores (float, signed integral, or unsigned integral).

+

Rectangle textures must use [[GLSL Sampler|samplers]] of the form {{code|''g''sampler2DRect}} or {{code|''g''sampler2DRectShadow}}, where ''g'' represents the type of data the texture stores (float, signed integral, or unsigned integral).

−

When using rectangle samplers, all [[GLSL Sampler#Texture lookup functions|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 twelfth and thirteenth texel.

+

When using rectangle samplers, all [[Sampler (GLSL)#Texture lookup functions|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).

== Limitations ==

== Limitations ==

−

Rectangle textures contain exactly one image; they cannot have [[Textures#Mip maps|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.

+

Rectangle textures contain exactly one image; they cannot have [[Textures#Mip maps|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; {{enum|GL_TEXTURE_MIN_FILTER}} must be {{enum|GL_NEAREST}} or {{enum|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.

+

Also, wrapping modes for each coordinate must be either {{enum|GL_CLAMP_TO_EDGE}} or {{enum|GL_CLAMP_TO_BORDER}}.

== Purpose ==

== Purpose ==

Revision as of 19:19, 13 February 2013

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.

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).

Limitations

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.

Purpose

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.