Module vulkano::pipeline::vertex

source ·
Expand description

Vertex sources definition

When you create a graphics pipeline object, you need to pass an object which indicates the layout of the vertex buffer(s) that will serve as input for the vertex shader. This is done by passing an implementation of the VertexDefinition trait.

In addition to this, the object that you pass when you create the graphics pipeline must also implement the VertexSource trait. This trait has a template parameter which corresponds to the list of vertex buffers.

The vulkano library provides some structs that already implement these traits. The most common situation is a single vertex buffer and no instancing, in which case you can pass a SingleBufferDefinition when you create the pipeline.

Implementing Vertex

The implementations of the VertexDefinition trait that are provided by vulkano (like SingleBufferDefinition) require you to use a buffer whose content is [V] where V implements the Vertex trait.

The Vertex trait is unsafe, but can be implemented on a struct with the impl_vertex! macro.

Example

use vulkano::buffer::BufferAccess;
use vulkano::buffer::BufferUsage;
use vulkano::memory::HostVisible;
use vulkano::pipeline::vertex::;

struct Vertex {
    position: [f32; 2]
}

impl_vertex!(Vertex, position);

let usage = BufferUsage {
    vertex_buffer: true,
    .. BufferUsage::none()
};

let vertex_buffer = BufferAccess::<[Vertex], _>::array(&device, 128, &usage, HostVisible, &queue)
                                                    .expect("failed to create buffer");

// TODO: finish example

Structs

Information about a single attribute within a vertex. TODO: change that API
Implementation of VertexDefinition for drawing with no buffers at all.
Value to be passed as the vertex source for bufferless draw commands.
Implementation of VertexDefinition for a single vertex buffer.
Same as SingleBufferDefinition but advances by instance.
Information about a member of a vertex struct.

Enums

Error that can happen when the vertex definition doesn’t match the input of the vertex shader.
How the vertex source should be unrolled.
Type of a member of a vertex struct.

Traits

Describes an individual Vertex. In other words a collection of attributes that can be read from a vertex shader.
Trait for types that describe the definition of the vertex input used by a graphics pipeline.
Trait for data types that can be used as vertex members. Used by the impl_vertex! macro.
Extension trait of VertexDefinition. The L parameter is an acceptable vertex source for this vertex definition.