[−][src]Module glium::texture
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; |
pub use self::texture1d::Texture1d; |
pub use self::compressed_texture1d::CompressedTexture1d; |
pub use self::srgb_texture1d::SrgbTexture1d; |
pub use self::compressed_srgb_texture1d::CompressedSrgbTexture1d; |
pub use self::integral_texture1d::IntegralTexture1d; |
pub use self::unsigned_texture1d::UnsignedTexture1d; |
pub use self::depth_texture1d::DepthTexture1d; |
pub use self::stencil_texture1d::StencilTexture1d; |
pub use self::depth_stencil_texture1d::DepthStencilTexture1d; |
pub use self::texture2d::Texture2d; |
pub use self::compressed_texture2d::CompressedTexture2d; |
pub use self::srgb_texture2d::SrgbTexture2d; |
pub use self::compressed_srgb_texture2d::CompressedSrgbTexture2d; |
pub use self::integral_texture2d::IntegralTexture2d; |
pub use self::unsigned_texture2d::UnsignedTexture2d; |
pub use self::depth_texture2d::DepthTexture2d; |
pub use self::stencil_texture2d::StencilTexture2d; |
pub use self::depth_stencil_texture2d::DepthStencilTexture2d; |
pub use self::texture2d_multisample::Texture2dMultisample; |
pub use self::integral_texture2d_multisample::IntegralTexture2dMultisample; |
pub use self::srgb_texture2d_multisample::SrgbTexture2dMultisample; |
pub use self::unsigned_texture2d_multisample::UnsignedTexture2dMultisample; |
pub use self::depth_texture2d_multisample::DepthTexture2dMultisample; |
pub use self::stencil_texture2d_multisample::StencilTexture2dMultisample; |
pub use self::depth_stencil_texture2d_multisample::DepthStencilTexture2dMultisample; |
pub use self::texture3d::Texture3d; |
pub use self::compressed_texture3d::CompressedTexture3d; |
pub use self::srgb_texture3d::SrgbTexture3d; |
pub use self::compressed_srgb_texture3d::CompressedSrgbTexture3d; |
pub use self::integral_texture3d::IntegralTexture3d; |
pub use self::unsigned_texture3d::UnsignedTexture3d; |
pub use self::depth_texture3d::DepthTexture3d; |
pub use self::depth_stencil_texture3d::DepthStencilTexture3d; |
pub use self::texture1d_array::Texture1dArray; |
pub use self::compressed_texture1d_array::CompressedTexture1dArray; |
pub use self::srgb_texture1d_array::SrgbTexture1dArray; |
pub use self::compressed_srgb_texture1d_array::CompressedSrgbTexture1dArray; |
pub use self::integral_texture1d_array::IntegralTexture1dArray; |
pub use self::unsigned_texture1d_array::UnsignedTexture1dArray; |
pub use self::depth_texture1d_array::DepthTexture1dArray; |
pub use self::stencil_texture1d_array::StencilTexture1dArray; |
pub use self::depth_stencil_texture1d_array::DepthStencilTexture1dArray; |
pub use self::texture2d_array::Texture2dArray; |
pub use self::compressed_texture2d_array::CompressedTexture2dArray; |
pub use self::srgb_texture2d_array::SrgbTexture2dArray; |
pub use self::compressed_srgb_texture2d_array::CompressedSrgbTexture2dArray; |
pub use self::integral_texture2d_array::IntegralTexture2dArray; |
pub use self::unsigned_texture2d_array::UnsignedTexture2dArray; |
pub use self::depth_texture2d_array::DepthTexture2dArray; |
pub use self::stencil_texture2d_array::StencilTexture2dArray; |
pub use self::depth_stencil_texture2d_array::DepthStencilTexture2dArray; |
pub use self::texture2d_multisample_array::Texture2dMultisampleArray; |
pub use self::srgb_texture2d_multisample_array::SrgbTexture2dMultisampleArray; |
pub use self::integral_texture2d_multisample_array::IntegralTexture2dMultisampleArray; |
pub use self::unsigned_texture2d_multisample_array::UnsignedTexture2dMultisampleArray; |
pub use self::depth_texture2d_multisample_array::DepthTexture2dMultisampleArray; |
pub use self::stencil_texture2d_multisample_array::StencilTexture2dMultisampleArray; |
pub use self::depth_stencil_texture2d_multisample_array::DepthStencilTexture2dMultisampleArray; |
pub use self::cubemap::Cubemap; |
pub use self::compressed_cubemap::CompressedCubemap; |
pub use self::srgb_cubemap::SrgbCubemap; |
pub use self::compressed_srgb_cubemap::CompressedSrgbCubemap; |
pub use self::integral_cubemap::IntegralCubemap; |
pub use self::unsigned_cubemap::UnsignedCubemap; |
pub use self::depth_cubemap::DepthCubemap; |
pub use self::stencil_cubemap::StencilCubemap; |
pub use self::depth_stencil_cubemap::DepthStencilCubemap; |
pub use self::cubemap_array::CubemapArray; |
pub use self::compressed_cubemap_array::CompressedCubemapArray; |
pub use self::srgb_cubemap_array::SrgbCubemapArray; |
pub use self::compressed_srgb_cubemap_array::CompressedSrgbCubemapArray; |
pub use self::integral_cubemap_array::IntegralCubemapArray; |
pub use self::unsigned_cubemap_array::UnsignedCubemapArray; |
pub use self::depth_cubemap_array::DepthCubemapArray; |
pub use self::stencil_cubemap_array::StencilCubemapArray; |
pub use self::depth_stencil_cubemap_array::DepthStencilCubemapArray; |
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 |
compressed_cubemap | Contains the implementation of |
compressed_cubemap_array | Contains the implementation of |
compressed_srgb_cubemap | Contains the implementation of |
compressed_srgb_cubemap_array | Contains the implementation of |
compressed_srgb_texture1d | Contains the implementation of |
compressed_srgb_texture1d_array | Contains the implementation of |
compressed_srgb_texture2d | Contains the implementation of |
compressed_srgb_texture2d_array | Contains the implementation of |
compressed_srgb_texture3d | Contains the implementation of |
compressed_texture1d | Contains the implementation of |
compressed_texture1d_array | Contains the implementation of |
compressed_texture2d | Contains the implementation of |
compressed_texture2d_array | Contains the implementation of |
compressed_texture3d | Contains the implementation of |
cubemap | Contains the implementation of |
cubemap_array | Contains the implementation of |
depth_cubemap | Contains the implementation of |
depth_cubemap_array | Contains the implementation of |
depth_stencil_cubemap | Contains the implementation of |
depth_stencil_cubemap_array | Contains the implementation of |
depth_stencil_texture1d | Contains the implementation of |
depth_stencil_texture1d_array | Contains the implementation of |
depth_stencil_texture2d | Contains the implementation of |
depth_stencil_texture2d_array | Contains the implementation of |
depth_stencil_texture2d_multisample | Contains the implementation of |
depth_stencil_texture2d_multisample_array | Contains the implementation of |
depth_stencil_texture3d | Contains the implementation of |
depth_texture1d | Contains the implementation of |
depth_texture1d_array | Contains the implementation of |
depth_texture2d | Contains the implementation of |
depth_texture2d_array | Contains the implementation of |
depth_texture2d_multisample | Contains the implementation of |
depth_texture2d_multisample_array | Contains the implementation of |
depth_texture3d | Contains the implementation of |
integral_cubemap | Contains the implementation of |
integral_cubemap_array | Contains the implementation of |
integral_texture1d | Contains the implementation of |
integral_texture1d_array | Contains the implementation of |
integral_texture2d | Contains the implementation of |
integral_texture2d_array | Contains the implementation of |
integral_texture2d_multisample | Contains the implementation of |
integral_texture2d_multisample_array | Contains the implementation of |
integral_texture3d | Contains the implementation of |
pixel_buffer | Pixel buffers are buffers that contain two-dimensional texture data. |
srgb_cubemap | Contains the implementation of |
srgb_cubemap_array | Contains the implementation of |
srgb_texture1d | Contains the implementation of |
srgb_texture1d_array | Contains the implementation of |
srgb_texture2d | Contains the implementation of |
srgb_texture2d_array | Contains the implementation of |
srgb_texture2d_multisample | Contains the implementation of |
srgb_texture2d_multisample_array | Contains the implementation of |
srgb_texture3d | Contains the implementation of |
stencil_cubemap | Contains the implementation of |
stencil_cubemap_array | Contains the implementation of |
stencil_texture1d | Contains the implementation of |
stencil_texture1d_array | Contains the implementation of |
stencil_texture2d | Contains the implementation of |
stencil_texture2d_array | Contains the implementation of |
stencil_texture2d_multisample | Contains the implementation of |
stencil_texture2d_multisample_array | Contains the implementation of |
texture1d | Contains the implementation of |
texture1d_array | Contains the implementation of |
texture2d | Contains the implementation of |
texture2d_array | Contains the implementation of |
texture2d_multisample | Contains the implementation of |
texture2d_multisample_array | Contains the implementation of |
texture3d | Contains the implementation of |
unsigned_cubemap | Contains the implementation of |
unsigned_cubemap_array | Contains the implementation of |
unsigned_texture1d | Contains the implementation of |
unsigned_texture1d_array | Contains the implementation of |
unsigned_texture2d | Contains the implementation of |
unsigned_texture2d_array | Contains the implementation of |
unsigned_texture2d_multisample | Contains the implementation of |
unsigned_texture2d_multisample_array | Contains the implementation of |
unsigned_texture3d | Contains the implementation of |
Structs
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. |
TextureAny | A texture whose type isn't fixed at compile-time. |
TextureAnyImage | Represents a specific 2D image of a texture. 1D textures are considered as having a height of 1. |
TextureAnyLayer | Represents a specific layer of an array texture and 3D textures. |
TextureAnyLayerMipmap | Represents a specific layer of a specific mipmap. This is the same as |
TextureAnyMipmap | Represents a specific mipmap of a texture. |
Enums
ClientFormat | List of client-side pixel formats. |
CompressedFormat | List of compressed texture formats. |
CompressedMipmapsOption | Describes what to do about mipmaps during compressed texture creation. |
CompressedSrgbFormat | List of compressed pixel formats in the sRGB color space. |
CubeLayer | Represents a layer of a cubemap. |
DepthFormat | List of formats available for depth textures. |
DepthStencilFormat | List of formats available for depth-stencil textures. |
Dimensions | Type of a texture. |
GetFormatError | Error that can happen when retrieving the internal format of a texture. |
InternalFormat | Internal format of a texture. |
InternalFormatType | Format of a component of an internal format. |
MipmapsOption | Describes what to do about mipmaps during texture creation. |
SrgbFormat | List of uncompressed pixel formats that contain floating-point data in the sRGB color space. |
StencilFormat | List of formats available for stencil textures. |
TextureCreationError | Error that can happen when creating a texture. |
TextureFormat | Format of the internal representation of a texture. |
TextureKind | Represents a kind of texture. |
UncompressedFloatFormat | List of uncompressed pixel formats that contain floating-point-like data. |
UncompressedIntFormat | List of uncompressed pixel formats that contain signed integral data. |
UncompressedUintFormat | List of uncompressed pixel formats that contain unsigned integral data. |
Traits
PixelValue | A trait that must be implemented for any type that can represent the value of a pixel. |
Texture1dDataSink | Trait that describes types that can be built from one-dimensional texture data. |
Texture1dDataSource | Trait that describes data for a one-dimensional texture. |
Texture2dDataSink | Trait that describes types that can be built from two-dimensional texture data. |
Texture2dDataSource | Trait that describes data for a two-dimensional texture. |
Texture3dDataSink | Trait that describes types that can be built from one-dimensional texture data. |
Texture3dDataSource | Trait that describes data for a two-dimensional texture. |
ToClientFormat |
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. |