Expand description
A texture is an image loaded in video memory, which can be sampled in your shaders.
§Texture kinds
One thing that is important to understand when it comes to textures is that the way a texture is accessed (in other words, its “public API”) is disconnected from the internal representation of the data.
When it comes to accessing a texture, there are six kinds of textures:
- Floating-point textures.
- Integral textures (that contain signed integers).
- Unsigned textures (that contain unsigned integers).
- Depth textures (that contain depth information).
- Stencil textures (that contain stencil information).
- Depth-stencil textures (that contain at the same time depth and stencil information).
Textures have a different API depending on their kind. For example a integral texture can only
be sampled in GLSL through a sampler type which is prefixed with i
.
The internal format can only be chosen when the texture is created, and then can never be touched again. Integral and unsigned textures can only contain signed integers and unsigned integers.
Floating-point textures can contain either floating-points or integers. If integers are used,
then the maximum value corresponds to the floating-point value 1.0
and the minimal value to 0.0
.
For example if a texture contains u8
s and internally contains the value 128
, reading from the
texture will yield the value 0.5
.
§Dimensions
Textures come in nine different dimensions:
- Textures with one dimension.
- Textures with two dimensions.
- Textures with two dimensions and multisampling enabled.
- Textures with three dimensions.
- Cube textures, which are arrays of six two-dimensional textures corresponding to the six faces of a cube.
- Arrays of one-dimensional textures.
- Arrays of two-dimensional textures.
- Arrays of two-dimensional textures with multisampling enabled.
- Arrays of cube textures.
The difference between a 3D texture and a 2D textures array (and between a 2D texture and a 1D
textures array) is that texture arrays can only be accessed by individual layers. That is, you can
only access layer 0, or layer 1, or layer 2, and so on. Whereas if you use 3D textures you can
access layer 0.5
for example.
All textures except depth, stencil and depth-stencil textures have mipmaps. A mipmap is a smaller version of the texture whose purpose is to be used during rendering when the texture will be small on the screen.
§Texture types in glium
In addition to the nine different dimensions types, there are nine kinds of texture formats:
- The texture contains floating-point data,
with either the
Compressed
prefix or no prefix at all. - The texture contains floating-point data in the sRGB color space, with either the
Compressed
prefix or not. - The texture contains signed integers, with the
Integral
prefix. - The texture contains unsigned integers, with the
Unsigned
prefix. - The texture contains depth information, with the
Depth
prefix. - The texture contains stencil information, with the
Stencil
prefix. - The texture contains depth and stencil information, with the
DepthStencil
prefix.
Each combination of dimensions and format corresponds to a sampler type in GLSL and in glium.
For example, an IntegralTexture3d
can only be bound to an isampler3D
uniform in GLSL.
The difference between compressed textures and uncompressed textures is that you can’t do render-to-texture on the former.
The most common types of textures are CompressedSrgbTexture2d
, SrgbTexture2d
and Texture2d
(the two dimensions being the width and height). These are what you will use most of the time.
§Buffer textures
A BufferTexture
is a special kind of one-dimensional texture that gets its data from a buffer.
Buffer textures have very limited capabilities (you can’t draw to them for example). They are an
alternative to uniform buffers and SSBOs.
See the buffer_textures
module for more infos.
§About sRGB
For historical reasons, the color data contained in almost all image files are not in RGB but in sRGB. sRGB colors are slightly brighter than linear RGB in order to compensate for the fact that screens darken some values that they receive.
When you load image files, you are encouraged to create sRGB textures (with SrgbTexture2d
instead
of Texture2d
for example).
By default, glium enables the GL_FRAMEBUFFER_SRGB
trigger, which expects the output of your
fragment shader to be in linear RGB and then turns it into sRGB before writing in the framebuffer.
Sampling from an sRGB texture will convert the texture colors from sRGB to RGB. If you create a
regular RGB texture and put sRGB data in it, then the result will be too bright.
§Bindless textures
Bindless textures are a very recent feature that is supported only by recent hardware and drivers.
Without bindless textures, using a texture in a shader requires binding the texture to a specific bind point before drawing. This not only slows down rendering, but may also prevent you from grouping multiple draw calls into one because of the limitation to the number of available texture units.
Instead, bindless textures allow you to manually manipulate pointers to textures in video memory. You can use thousands of textures if you want.
Re-exports§
pub use self::bindless::ResidentTexture;
pub use self::bindless::TextureHandle;
pub use self::bindless::BindlessTexturesNotSupportedError;
Modules§
- bindless
- Without bindless textures, using a texture in a shader requires binding the texture to a specific bind point before drawing. This not only slows down rendering, but may also prevent you from grouping multiple draw calls into one because of the limitation to the number of available texture units.
- buffer_
texture - A
BufferTexture
is a special kind of one-dimensional texture that gets its data from a buffer. Buffer textures have very limited capabilities compared to other texture types. - compressed_
cubemap - Contains the implementation of
CompressedCubemap
. - compressed_
cubemap_ array - Contains the implementation of
CompressedCubemapArray
. - compressed_
srgb_ cubemap - Contains the implementation of
CompressedSrgbCubemap
. - compressed_
srgb_ cubemap_ array - Contains the implementation of
CompressedSrgbCubemapArray
. - compressed_
srgb_ texture1d - Contains the implementation of
CompressedSrgbTexture1d
. - compressed_
srgb_ texture1d_ array - Contains the implementation of
CompressedSrgbTexture1dArray
. - compressed_
srgb_ texture2d - Contains the implementation of
CompressedSrgbTexture2d
. - compressed_
srgb_ texture2d_ array - Contains the implementation of
CompressedSrgbTexture2dArray
. - compressed_
srgb_ texture3d - Contains the implementation of
CompressedSrgbTexture3d
. - compressed_
texture1d - Contains the implementation of
CompressedTexture1d
. - compressed_
texture1d_ array - Contains the implementation of
CompressedTexture1dArray
. - compressed_
texture2d - Contains the implementation of
CompressedTexture2d
. - compressed_
texture2d_ array - Contains the implementation of
CompressedTexture2dArray
. - compressed_
texture3d - Contains the implementation of
CompressedTexture3d
. - cubemap
- Contains the implementation of
Cubemap
. - cubemap_
array - Contains the implementation of
CubemapArray
. - depth_
cubemap - Contains the implementation of
DepthCubemap
. - depth_
cubemap_ array - Contains the implementation of
DepthCubemapArray
. - depth_
stencil_ cubemap - Contains the implementation of
DepthStencilCubemap
. - depth_
stencil_ cubemap_ array - Contains the implementation of
DepthStencilCubemapArray
. - depth_
stencil_ texture1d - Contains the implementation of
DepthStencilTexture1d
. - depth_
stencil_ texture1d_ array - Contains the implementation of
DepthStencilTexture1dArray
. - depth_
stencil_ texture2d - Contains the implementation of
DepthStencilTexture2d
. - depth_
stencil_ texture2d_ array - Contains the implementation of
DepthStencilTexture2dArray
. - depth_
stencil_ texture2d_ multisample - Contains the implementation of
DepthStencilTexture2dMultisample
. - depth_
stencil_ texture2d_ multisample_ array - Contains the implementation of
DepthStencilTexture2dMultisampleArray
. - depth_
stencil_ texture3d - Contains the implementation of
DepthStencilTexture3d
. - depth_
texture1d - Contains the implementation of
DepthTexture1d
. - depth_
texture1d_ array - Contains the implementation of
DepthTexture1dArray
. - depth_
texture2d - Contains the implementation of
DepthTexture2d
. - depth_
texture2d_ array - Contains the implementation of
DepthTexture2dArray
. - depth_
texture2d_ multisample - Contains the implementation of
DepthTexture2dMultisample
. - depth_
texture2d_ multisample_ array - Contains the implementation of
DepthTexture2dMultisampleArray
. - depth_
texture3d - Contains the implementation of
DepthTexture3d
. - integral_
cubemap - Contains the implementation of
IntegralCubemap
. - integral_
cubemap_ array - Contains the implementation of
IntegralCubemapArray
. - integral_
texture1d - Contains the implementation of
IntegralTexture1d
. - integral_
texture1d_ array - Contains the implementation of
IntegralTexture1dArray
. - integral_
texture2d - Contains the implementation of
IntegralTexture2d
. - integral_
texture2d_ array - Contains the implementation of
IntegralTexture2dArray
. - integral_
texture2d_ multisample - Contains the implementation of
IntegralTexture2dMultisample
. - integral_
texture2d_ multisample_ array - Contains the implementation of
IntegralTexture2dMultisampleArray
. - integral_
texture3d - Contains the implementation of
IntegralTexture3d
. - pixel_
buffer - Pixel buffers are buffers that contain two-dimensional texture data.
- srgb_
cubemap - Contains the implementation of
SrgbCubemap
. - srgb_
cubemap_ array - Contains the implementation of
SrgbCubemapArray
. - srgb_
texture1d - Contains the implementation of
SrgbTexture1d
. - srgb_
texture1d_ array - Contains the implementation of
SrgbTexture1dArray
. - srgb_
texture2d - Contains the implementation of
SrgbTexture2d
. - srgb_
texture2d_ array - Contains the implementation of
SrgbTexture2dArray
. - srgb_
texture2d_ multisample - Contains the implementation of
SrgbTexture2dMultisample
. - srgb_
texture2d_ multisample_ array - Contains the implementation of
SrgbTexture2dMultisampleArray
. - srgb_
texture3d - Contains the implementation of
SrgbTexture3d
. - stencil_
cubemap - Contains the implementation of
StencilCubemap
. - stencil_
cubemap_ array - Contains the implementation of
StencilCubemapArray
. - stencil_
texture1d - Contains the implementation of
StencilTexture1d
. - stencil_
texture1d_ array - Contains the implementation of
StencilTexture1dArray
. - stencil_
texture2d - Contains the implementation of
StencilTexture2d
. - stencil_
texture2d_ array - Contains the implementation of
StencilTexture2dArray
. - stencil_
texture2d_ multisample - Contains the implementation of
StencilTexture2dMultisample
. - stencil_
texture2d_ multisample_ array - Contains the implementation of
StencilTexture2dMultisampleArray
. - texture1d
- Contains the implementation of
Texture1d
. - texture1d_
array - Contains the implementation of
Texture1dArray
. - texture2d
- Contains the implementation of
Texture2d
. - texture2d_
array - Contains the implementation of
Texture2dArray
. - texture2d_
multisample - Contains the implementation of
Texture2dMultisample
. - texture2d_
multisample_ array - Contains the implementation of
Texture2dMultisampleArray
. - texture3d
- Contains the implementation of
Texture3d
. - unsigned_
cubemap - Contains the implementation of
UnsignedCubemap
. - unsigned_
cubemap_ array - Contains the implementation of
UnsignedCubemapArray
. - unsigned_
texture1d - Contains the implementation of
UnsignedTexture1d
. - unsigned_
texture1d_ array - Contains the implementation of
UnsignedTexture1dArray
. - unsigned_
texture2d - Contains the implementation of
UnsignedTexture2d
. - unsigned_
texture2d_ array - Contains the implementation of
UnsignedTexture2dArray
. - unsigned_
texture2d_ multisample - Contains the implementation of
UnsignedTexture2dMultisample
. - unsigned_
texture2d_ multisample_ array - Contains the implementation of
UnsignedTexture2dMultisampleArray
. - unsigned_
texture3d - Contains the implementation of
UnsignedTexture3d
.
Structs§
- Compressed
Cubemap - A compressed cube texture containing floating-point data.
- Compressed
Cubemap Array - An array of compressed cube textures containing floating-point data.
- Compressed
Srgb Cubemap - A compressed cube texture containing sRGB floating-point data.
- Compressed
Srgb Cubemap Array - An array of compressed cube textures containing sRGB floating-point data.
- Compressed
Srgb Texture1d - A compressed one-dimensional texture containing sRGB floating-point data.
- Compressed
Srgb Texture1d Array - An array of compressed one-dimensional textures containing sRGB floating-point data.
- Compressed
Srgb Texture2d - A compressed two-dimensional texture containing sRGB floating-point data.
- Compressed
Srgb Texture2d Array - An array of compressed two-dimensional textures containing sRGB floating-point data.
- Compressed
Srgb Texture3d - A compressed three-dimensional texture containing sRGB floating-point data.
- Compressed
Texture1d - A compressed one-dimensional texture containing floating-point data.
- Compressed
Texture1d Array - An array of compressed one-dimensional textures containing floating-point data.
- Compressed
Texture2d - A compressed two-dimensional texture containing floating-point data.
- Compressed
Texture2d Array - An array of compressed two-dimensional textures containing floating-point data.
- Compressed
Texture3d - A compressed three-dimensional texture containing floating-point data.
- Cubemap
- A cube texture containing floating-point data.
- Cubemap
Array - An array of cube textures containing floating-point data.
- Depth
Cubemap - A cube texture containing depth data.
- Depth
Cubemap Array - An array of cube textures containing depth data.
- Depth
Stencil Cubemap - A cube texture containing both depth and stencil data.
- Depth
Stencil Cubemap Array - An array of cube textures containing both depth and stencil data.
- Depth
Stencil Texture1d - A one-dimensional texture containing both depth and stencil data.
- Depth
Stencil Texture1d Array - An array of one-dimensional textures containing both depth and stencil data.
- Depth
Stencil Texture2d - A two-dimensional texture containing both depth and stencil data.
- Depth
Stencil Texture2d Array - An array of two-dimensional textures containing both depth and stencil data.
- Depth
Stencil Texture2d Multisample - A two-dimensional texture containing both depth and stencil data.
- Depth
Stencil Texture2d Multisample Array - An array of two-dimensional textures containing both depth and stencil data.
- Depth
Stencil Texture3d - A three-dimensional texture containing both depth and stencil data.
- Depth
Texture1d - A one-dimensional texture containing depth data.
- Depth
Texture1d Array - An array of one-dimensional textures containing depth data.
- Depth
Texture2d - A two-dimensional texture containing depth data.
- Depth
Texture2d Array - An array of two-dimensional textures containing depth data.
- Depth
Texture2d Multisample - A two-dimensional texture containing depth data.
- Depth
Texture2d Multisample Array - An array of two-dimensional textures containing depth data.
- Depth
Texture3d - A three-dimensional texture containing depth data.
- Import
Parameters - Contains parameters needed to import a texture created in an external API into OpenGL. Must match with parameters used by external memory.
- Integral
Cubemap - A cube texture containing signed integral data.
- Integral
Cubemap Array - An array of cube textures containing signed integral data.
- Integral
Texture1d - A one-dimensional texture containing signed integral data.
- Integral
Texture1d Array - An array of one-dimensional textures containing signed integral data.
- Integral
Texture2d - A two-dimensional texture containing signed integral data.
- Integral
Texture2d Array - An array of two-dimensional textures containing signed integral data.
- Integral
Texture2d Multisample - A two-dimensional texture containing signed integral data.
- Integral
Texture2d Multisample Array - An array of two-dimensional textures containing signed integral data.
- Integral
Texture3d - A three-dimensional texture containing signed integral data.
- RawImage1d
- Represents raw data for a two-dimensional image.
- RawImage2d
- Represents raw data for a two-dimensional image.
- RawImage3d
- Represents raw data for a two-dimensional image.
- Srgb
Cubemap - A cube texture containing sRGB floating-point data.
- Srgb
Cubemap Array - An array of cube textures containing sRGB floating-point data.
- Srgb
Texture1d - A one-dimensional texture containing sRGB floating-point data.
- Srgb
Texture1d Array - An array of one-dimensional textures containing sRGB floating-point data.
- Srgb
Texture2d - A two-dimensional texture containing sRGB floating-point data.
- Srgb
Texture2d Array - An array of two-dimensional textures containing sRGB floating-point data.
- Srgb
Texture2d Multisample - A two-dimensional texture containing sRGB floating-point data.
- Srgb
Texture2d Multisample Array - An array of two-dimensional textures containing sRGB floating-point data.
- Srgb
Texture3d - A three-dimensional texture containing sRGB floating-point data.
- Stencil
Cubemap - A cube texture containing stencil data.
- Stencil
Cubemap Array - An array of cube textures containing stencil data.
- Stencil
Texture1d - A one-dimensional texture containing stencil data.
- Stencil
Texture1d Array - An array of one-dimensional textures containing stencil data.
- Stencil
Texture2d - A two-dimensional texture containing stencil data.
- Stencil
Texture2d Array - An array of two-dimensional textures containing stencil data.
- Stencil
Texture2d Multisample - A two-dimensional texture containing stencil data.
- Stencil
Texture2d Multisample Array - An array of two-dimensional textures containing stencil data.
- Texture1d
- A one-dimensional texture containing floating-point data.
- Texture1d
Array - An array of one-dimensional textures containing floating-point data.
- Texture2d
- A two-dimensional texture containing floating-point data.
- Texture2d
Array - An array of two-dimensional textures containing floating-point data.
- Texture2d
Multisample - A two-dimensional texture containing floating-point data.
- Texture2d
Multisample Array - An array of two-dimensional textures containing floating-point data.
- Texture3d
- A three-dimensional texture containing floating-point data.
- Texture
Any - A texture whose type isn’t fixed at compile-time.
- Texture
AnyImage - Represents a specific 2D image of a texture. 1D textures are considered as having a height of 1.
- Texture
AnyLayer - Represents a specific layer of an array texture and 3D textures.
- Texture
AnyLayer Mipmap - Represents a specific layer of a specific mipmap. This is the same as
TextureAnyImage
, except for 3D textures, cubemaps and cubemap arrays. - Texture
AnyMipmap - Represents a specific mipmap of a texture.
- Unsigned
Cubemap - A cube texture containing unsigned integral data.
- Unsigned
Cubemap Array - An array of cube textures containing unsigned integral data.
- Unsigned
Texture1d - A one-dimensional texture containing unsigned integral data.
- Unsigned
Texture1d Array - An array of one-dimensional textures containing unsigned integral data.
- Unsigned
Texture2d - A two-dimensional texture containing unsigned integral data.
- Unsigned
Texture2d Array - An array of two-dimensional textures containing unsigned integral data.
- Unsigned
Texture2d Multisample - A two-dimensional texture containing unsigned integral data.
- Unsigned
Texture2d Multisample Array - An array of two-dimensional textures containing unsigned integral data.
- Unsigned
Texture3d - A three-dimensional texture containing unsigned integral data.
Enums§
- Client
Format - List of client-side pixel formats.
- Compressed
Format - List of compressed texture formats.
- Compressed
Mipmaps Option - Describes what to do about mipmaps during compressed texture creation.
- Compressed
Srgb Format - List of compressed pixel formats in the sRGB color space.
- Cube
Layer - Represents a layer of a cubemap.
- Depth
Format - List of formats available for depth textures.
- Depth
Stencil Format - List of formats available for depth-stencil textures.
- Dimensions
- Type of a texture.
- External
Tiling Mode - Describes a tiling mode used in texture storage by an external API
- GetFormat
Error - Error that can happen when retrieving the internal format of a texture.
- Internal
Format - Internal format of a texture.
- Internal
Format Type - Format of a component of an internal format.
- Mipmaps
Option - Describes what to do about mipmaps during texture creation.
- Srgb
Format - List of uncompressed pixel formats that contain floating-point data in the sRGB color space.
- Stencil
Format - List of formats available for stencil textures.
- Texture
Creation Error - Error that can happen when creating a texture.
- Texture
Format - Format of the internal representation of a texture.
- Texture
Import Error - Error that can happen when importing a texture.
- Texture
Kind - Represents a kind of texture.
- Uncompressed
Float Format - List of uncompressed pixel formats that contain floating-point-like data.
- Uncompressed
IntFormat - List of uncompressed pixel formats that contain signed integral data.
- Uncompressed
Uint Format - List of uncompressed pixel formats that contain unsigned integral data.
Traits§
- Pixel
Value - A trait that must be implemented for any type that can represent the value of a pixel.
- Texture1d
Data Sink - Trait that describes types that can be built from one-dimensional texture data.
- Texture1d
Data Source - Trait that describes data for a one-dimensional texture.
- Texture2d
Data Sink - Trait that describes types that can be built from two-dimensional texture data.
- Texture2d
Data Source - Trait that describes data for a two-dimensional texture.
- Texture3d
Data Sink - Trait that describes types that can be built from one-dimensional texture data.
- Texture3d
Data Source - Trait that describes data for a two-dimensional texture.
- ToClient
Format
Functions§
- is_
cubemap_ arrays_ supported - Returns true is cubemap arrays are supported.
- is_
cubemaps_ supported - Returns true is cubemaps are supported.
- is_
texture_ 1d_ array_ supported - Returns true is one-dimensional texture arrays are supported.
- is_
texture_ 1d_ supported - Returns true is one-dimensional textures are supported.
- is_
texture_ 2d_ array_ supported - Returns true is two-dimensional texture arrays are supported.
- is_
texture_ 2d_ multisample_ array_ supported - Returns true is two-dimensional multisample texture arrays are supported.
- is_
texture_ 2d_ multisample_ supported - Returns true is two-dimensional multisample textures are supported.
- is_
texture_ 2d_ supported - Returns true is two-dimensional textures are supported.
- is_
texture_ 3d_ supported - Returns true is three-dimensional textures are supported.