Module glium::texture::bindless

source ·
Expand description

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.

Initialization

Before using a bindless texture, you must turn it into a ResidentTexture. This is done by calling resident on the texture you want.

Bindless textures are a very recent feature that is supported only by recent hardware and drivers. resident will return an Err if this feature is not supported.

let texture = texture.resident().unwrap();

In a real application, you will likely manage a Vec<ResidentTexture>.

Usage

You can then use a TextureHandle as if it was a pointer to a texture. A TextureHandle can be built from a &ResidentTexture and can’t outlive it.

#[macro_use]
extern crate glium;

#[derive(Copy, Clone)]
struct UniformBuffer<'a> {
    texture: glium::texture::TextureHandle<'a>,
    some_value: f32,
}

implement_uniform_block!(UniformBuffer<'a>, texture, some_value);

let uniform_buffer = glium::uniforms::UniformBuffer::new(&display, UniformBuffer {
    texture: glium::texture::TextureHandle::new(&texture, &Default::default()),
    some_value: 5.0,
});

Inside your shader, you can refer to the texture with a traditional sampler* variable. Glium currently doesn’t check whether the type of your texture matches the expected type (but it may do in the future). Binding the wrong type of texture may lead to undefined values when sampling the texture.

Structs