Module glium::buffer

source ·
Expand description

A buffer is a memory location accessible to the video card.

The purpose of buffers is to serve as a space where the GPU can read from or write data to. It can contain a list of vertices, indices, uniform data, etc.

Buffers management in glium

There are three levels of abstraction in glium:

  • An Alloc corresponds to an OpenGL buffer object and is unsafe to use. This type is not public.
  • A Buffer wraps around an Alloc and provides safety by handling the data type and fences.
  • The VertexBuffer, IndexBuffer, UniformBuffer, PixelBuffer, etc. types are abstractions over a Buffer indicating their specific purpose. They implement Deref for the Buffer. These types are in the vertex, index, etc. modules.

Unsized types

In order to put some data in a buffer, it must implement the Content trait. This trait is automatically implemented on all Sized types and on slices (like [u8]). This means that you can create a Buffer<Foo> (if Foo is sized) or a Buffer<[u8]> for example without worrying about it.

However unsized structs don’t automatically implement this trait and you must call the implement_buffer_content! macro on them. You must then use the empty_unsized constructor.

struct Data {
    data: [f32],        // `[f32]` is unsized, therefore `Data` is unsized too
}

implement_buffer_content!(Data);    // without this, you can't put `Data` in a glium buffer

// creates a buffer of 64 bytes, which thus holds 8 f32s
let mut buffer = glium::buffer::Buffer::<Data>::empty_unsized(&display, BufferType::UniformBuffer,
                                                              64, BufferMode::Default).unwrap();

// you can then write to it like you normally would
buffer.map().data[4] = 2.1;

Structs

  • Represents a view of a buffer.
  • Represents a sub-part of a buffer.
  • Slice of a Buffer without any type info.
  • Represents a sub-part of a buffer.
  • Represents a sub-part of a buffer.
  • DEPRECATED. Only here for backwards compatibility. Represents a view of a buffer.
  • DEPRECATED. Only here for backwards compatibility. Represents a sub-part of a buffer.
  • DEPRECATED. Only here for backwards compatibility. Slice of a Buffer without any type info.
  • DEPRECATED. Only here for backwards compatibility. Represents a sub-part of a buffer.
  • DEPRECATED. Only here for backwards compatibility. Represents a sub-part of a buffer.
  • Allows inserting a fence in the list.
  • A mapping of a buffer for reading and writing.
  • A mapping of a buffer for reading.
  • A mapping of a buffer for write only.

Enums

Traits

  • Trait for types of data that can be put inside buffers.

Functions