Cubemap Texture

Revision as of 01:34, 17 August 2012 by Alfonse (talk | contribs) (formatting.)

Jump to: navigation, search
Cubemap Texture
Core in version 4.5
Core since version 1.3
ARB extension ARB_texture_cube_map

A Cubemap Texture is a texture composed of 6 2D images. The images are arranged in a cube-shape, hence the name. Each separate face of the cube can have its own mipmaps.


Cubemaps are a texture type, using the type GL_TEXTURE_CUBE_MAP. Cubemaps conceptually contain 6 2D textures, each one representing a particular face of a cube.


To allocate storage for the 6 faces of the cubemap, bind the texture to GL_TEXTURE_CUBE_MAP. Then call glTexImage2D 6 times, using the same size, mipmap level, and image format. The target parameter specifies which of the 6 faces of the cubemap to specify. These faces are:


Cubemaps may have mipmaps, but each face must have the same number of mipmaps. Cubemaps can use any of the filtering modes and other texture parameters.

Texture Access

The sampler type for cubemaps is gsamplerCube. gsamplerCubeShadow can also be used for shadow lookups. The fourth component of the texture coordinate for shadow lookups is the comparison value.

The texture coordinates for cubemaps are 3D vector directions. These are conceptually directions from within the cube defined by the cubemap, pointing in a particular direction. The vectors do not have to be normalized.

Filtering does not take place across cubemap face boundaries. So a visible seam can appear between cubemap face boundaries regardless of the texture filtering modes.

Layered Rendering

Cubemaps can be bound to framebuffer objects for layered rendering. The 6 faces are given a specific order, as defined in the linked article.

Seamless cubemap

Seamless Cubemap Filtering
Core in version 4.5
Core since version 3.2
Core ARB extension ARB_seamless_cube_map

Under the standard filtering rules for cubemaps, filtering does not work across faces of the cubemap. This results in a seam across the faces of a cubemap. This was a hardware limitation in the past, but modern hardware is capable of interpolating across a cube face boundary.

To globally enable this, use glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS). In general, it is not a good idea to enable and disable this within a program. It should be set as part of initialization and never changed.

Cubemap array textures

Cubemap Array Textures
Core in version 4.5
Core since version 4.0
ARB extension ARB_texture_cube_map_array

Array textures can also come in cubemap flavors, in addition to 1D and 2D. They use the texture type GL_TEXTURE_CUBE_MAP_ARRAY.

Uploading to cube map arrays works differently from uploading to regular cubemaps. They are uploaded like array textures, using glTex(Sub)Image3D.

The layers work differently from 1D and 2D array textures. The depth parameter in the glTexImage3D call does not specify how many array layers there are. If you have N array layers in the cubemap array, then depth must be 6*N. Therefore, every group of 6 2D images in the 3D block of data is a single cubemap layer.

The order of the faces within a 6 2D image group is the same as that used for layered rendering of cubemaps.

Cubemap arrays can have mipmaps. They are uploaded in the same way as for other kinds of array textures.


The sampler type for cubemap arrays is gsamplerCubeArray. gsamplerCubeArrayShadow can be used for comparison lookups. The texture coordinates are 4D values; the first three values are the vector direction, and the fourth value is the array layer to use. Note that here, the array layer is a value from 0 to N-1, where there are N layers. Remember that depth, the number of uploaded 2D slices, is 6 times the number of array layers.

For comparison modes, the texture functions take an additional parameter for the comparison value. The parameter always comes immediately after the texture coordinate.