[][src]Module glium::vertex

Contains everything related to vertex sources.

When you draw, you need to pass one or several sources of vertex attributes. This is done with the first parameter to the draw function.

Vertex

The main trait of this module is Vertex, which must be implemented on structs whose instances describe individual vertices. The trait is unsafe to implement, so you are encouraged to use the implement_vertex! macro instead:

#[derive(Copy, Clone)]
struct MyVertex {
    position: [f32; 3],
    texcoords: [f32; 2],
}

// you must pass the list of members to the macro
implement_vertex!(MyVertex, position, texcoords);

Vertex buffer

Once you have a struct that implements the Vertex trait, you can build an array of vertices and upload it to the video memory by creating a VertexBuffer.

let data = &[
    MyVertex {
        position: [0.0, 0.0, 0.4],
        texcoords: [0.0, 1.0]
    },
    MyVertex {
        position: [12.0, 4.5, -1.8],
        texcoords: [1.0, 0.5]
    },
    MyVertex {
        position: [-7.124, 0.1, 0.0],
        texcoords: [0.0, 0.4]
    },
];

let vertex_buffer = glium::vertex::VertexBuffer::new(&display, data);

Drawing

When you draw, you can pass either a single vertex source or a tuple of multiple sources. Each source can be:

// drawing with a single vertex buffer
frame.draw(&vertex_buffer, &indices, &program, &uniforms, &Default::default()).unwrap();

// drawing with two parallel vertex buffers
frame.draw((&vertex_buffer, &vertex_buffer2), &indices, &program,
           &uniforms, &Default::default()).unwrap();

// drawing without a vertex source
frame.draw(glium::vertex::EmptyVertexAttributes { len: 12 }, &indices, &program,
           &uniforms, &Default::default()).unwrap();

// drawing a slice of a vertex buffer
frame.draw(vertex_buffer.slice(6 .. 24).unwrap(), &indices, &program,
           &uniforms, &Default::default()).unwrap();

// drawing slices of two vertex buffers
frame.draw((vertex_buffer.slice(6 .. 24).unwrap(), vertex_buffer2.slice(128 .. 146).unwrap()),
           &indices, &program, &uniforms, &Default::default()).unwrap();

// treating `vertex_buffer2` as a source of attributes per-instance instead of per-vertex
frame.draw((&vertex_buffer, vertex_buffer2.per_instance().unwrap()), &indices,
           &program, &uniforms, &Default::default()).unwrap();

// instancing without any per-instance attribute
frame.draw((&vertex_buffer, glium::vertex::EmptyInstanceAttributes { len: 36 }), &indices,
           &program, &uniforms, &Default::default()).unwrap();

Note that if you use index::EmptyIndices as indices the length of all vertex sources must be the same, or a DrawError::VerticesSourcesLengthMismatch will be produced.

In all situation, the length of all per-instance sources must match, or DrawError::InstancesCountMismatch will be returned.

Transform feedback

Transform feedback allows you to write in a buffer the list of primitives that are generated by the GPU.

To use it, you must first create a TransformFeedbackSession with TransformFeedbackSession::new(). This function requires you to pass a buffer of the correct type and a program. Then you must pass the &TransformFeedbackSession to the draw parameters. The program you use when drawing must be the same as you the one you created the session with, or else you will get an error.

Structs

EmptyInstanceAttributes

Marker that can be passed instead of a buffer to indicate an empty list of buffers.

EmptyVertexAttributes

Marker that can be passed instead of a buffer to indicate an empty list of buffers.

PerInstance

Marker that instructs glium that the buffer is to be used per instance.

TransformFeedbackSession

Transform feedback allows you to obtain in a buffer the list of the vertices generated by the vertex shader, geometry shader, or tessellation evaluation shader of your program. This is usually used to cache the result in order to draw the vertices multiple times with multiple different fragment shaders.

VertexBuffer

A list of vertices loaded in the graphics card's memory.

VertexBufferAny

A list of vertices loaded in the graphics card's memory.

VertexBufferSlice

Represents a slice of a VertexBuffer.

Enums

AttributeType
BufferCreationError

Error that can happen when creating a vertex buffer.

VerticesSource

Describes the source to use for the vertices when drawing.

Traits

Attribute

Trait for types that can be used as vertex attributes.

MultiVerticesSource

Objects that describe multiple vertex sources.

Vertex

Trait for structures that represent a vertex.

Functions

is_transform_feedback_supported

Returns true if transform feedback is supported by the OpenGL implementation.

Type Definitions

VertexFormat

Describes the layout of each vertex in a vertex buffer.