Buffer Texture

From OpenGL Wiki
Jump to navigation Jump to search
Buffer Texture
Core in version 4.6
Core since version 3.0
ARB extension ARB_texture_buffer_object
EXT extension EXT_texture_buffer_object

A Buffer Texture is a one-dimensional Texture whose storage comes from a Buffer Object. They are used to allow a shader to access a large table of memory that is managed by a buffer object.

Creation and Management

When creating a regular texture, the user calls glGenTextures, binds the texture object to a particular texture type glBindTexture, and then calls glTexImage* one or more times to create the storage for the data. Creating buffer textures is very similar.

glGenTextures is still used to create the texture object. And glBindTexture is still used to bind the texture. For buffer textures, the texture is bound to the GL_TEXTURE_BUFFER target. Creating the storage for the buffer object is the main difference.

Buffer textures are defined by the fact that the storage for the texels comes directly from a buffer object. Therefore, glTexImage calls are not appropriate for buffer textures; calling any of the gl*Image functions on the GL_TEXTURE_BUFFER will result in an error.

Instead of creating storage for a buffer texture, the user associates a buffer texture with an already existing buffer object. This association is made by binding the buffer texture to the GL_TEXTURE_BUFFER target and then calling this function:

void glTexBuffer(GLenum target, GLenum internalFormat, GLuint buffer);

The target parameter can only be GL_TEXTURE_BUFFER. The internalFormat is the Image Format describing how the pixel data is stored in the buffer object. The buffer is a previously created buffer object. 0 can be used to detatch a buffer from a buffer texture.

The buffer object can be created as normal. The buffer object target GL_TEXTURE_BUFFER can be used as a bind point for creating and modifying such buffer objects, but as stated in the Buffer Object article, this is not required.

The storage comes from the beginning of the buffer object. The user cannot allocate a large buffer object and allow multiple texture buffers to use different pieces of them. Unless the user passes an offset into the shader that is applied to the texture coordinate before the fetch.

Image Formats

Normal textures hide the internal binary representation of image data from the user. Since buffer objects are unformatted memory, this is not possible for buffer textures. Therefore, the user is somewhat limitted in the Image Formats that are allowed for use with buffer textures.

Only color formats are acceptable in buffer textures. These formats can be 1, 2, and 4 channels (with 3 channels in OpenGL 4.0 or with ARB_texture_buffer_object_rgb32), so only RED, RG, and RGBA (or RGB with GL 4.0) are acceptable.

Only formats with an explicit size are allowed. GL_RGBA is not sufficient for a buffer texture; the user must use GL_RGBA8 or GL_RGBA16. The sizes can only be 8, 16, or 32; smaller per-component sizes are not allowed. Also, the more unusual formats like GL_RGB10_A2 are not supported in buffer textures.

The format can be any of the various types, like unsigned normalized, floating-point, signed integral, etc. GL_RGBA8UI would be 4-bytes per color, with

The byte-order for each component is native for the CPU platform in use. So if the user's code is running on a little-endian, then the floats, 32-bit integers, or 16-bit integers are stored in little-endian order. However the byte-order among components is always RGBA in memory, regarldess of the endianess.

Texture Size

Every texture has a size. For buffer textures, the size of the texture is the size of the buffer object divided by the byte size of a component (based on the internal format. GL_RED32F takes up 4 bytes, while GL_RGBA16 takes 8). This is clamped to the implementation-defined limit on the size of all buffer textures (see Limitations below).

Texture Parameters

No texture parameters are legal to set on buffer textures.

Access in Shaders

In GLSL, buffer textures can only be accessed with the texelFetch function. This function takes pixel offsets into the texture rather than normalized texture coordinates.


Buffer textures have a size limit, separate from the standard one-dimensional texture size. The buffer texture size limit is typically much larger than that of one-dimesnional texture. This size is queried with the GL_MAX_TEXTURE_BUFFER_SIZE_ARB token. The smallest number this will return is 65536, and the actual value may well be a good deal larger.

Buffer textures are not mip-mapped; they can only store a single image. They also cannot use any filtering. In essence, a buffer texture is simply a way for the shader to directly access a large array of data.