Struct glin::vao::Builder[][src]

pub struct Builder { /* fields omitted */ }

Implementations

impl Builder[src]

Builder for a VAO

pub fn bindings_from<T, B, BI>(self, bindings: &BI, from: B) -> Builder where
    T: 'static + VertexFormat,
    B: BufferRange<T> + 'static,
    BI: Bindings
[src]

Specify attribute bindings and vertex buffer bindings

bindings: This is usually a glsl program or a HashMap with predefined bindings from: Some kind of buffer like a Buffer, a SharedBuffer or a range of a buffer

The bindings are used to recover the formats (including location) for each attribute and that + the passed buffer to create the full relation: buffer -> vertex buffer binding point <- attributes

#[macro_use] extern crate glin;
use std::mem;

#[derive(VertexFormat)]
struct Vertex{
    position: [f32;4]
}

fn main(){
    let gl: glin::Context = unsafe{ mem::uninitialized() };
    let vertices: &[Vertex] = &[];
    let buffer: glin::Buffer<Vertex> = gl.new_buffer()
         .from_data(vertices, glin::gl::STATIC_DRAW).unwrap();
    let program: glin::Program = unsafe{ mem::uninitialized() };

    let vao = gl.new_vao()
        .bindings_from(&program, buffer)
        .create()
        .unwrap();
}

Creates a Vao that reads from buffer and binds each vertex element in it’s vertex type to the attribute with the same name in the glsl program

The type of the buffer has to implement VertexFormat

pub fn attributes_from<T, B, I>(self, formats: I, from: B) -> Builder where
    T: 'static,
    B: BufferRange<T> + 'static,
    I: Into<Vec<Format>>, 
[src]

Specify attribute bindings and vertex buffer bindings

Similar to bindings_from but instead of passing a bindings source we pass the attribute formats.

This method is rarely used directly unless we need to specify complex formats or we have vertex types that don’t specify VertexFormat

pub fn instance_bindings_from<T, B, BI>(
    self,
    bindings: &BI,
    from: B,
    divisor: usize
) -> Builder where
    T: 'static,
    T: VertexFormat,
    B: BufferRange<T> + 'static,
    BI: Bindings
[src]

Specify attributes that will be read per instance

#[macro_use] extern crate glin;
extern crate na;
use std::mem;
use glin::VertexFormat;

#[derive(VertexFormat)]
struct Vertex{
   position: na::Vec3,
}

#[derive(VertexFormat)]
struct InstanceAttributes{
   model_matrix: na::Mat4,
}

fn main(){
    let gl: glin::Context = unsafe{ mem::uninitialized() };
    let program: glin::Program = unsafe { mem::uninitialized() };
    let buffer: glin::Buffer<Vertex> = unsafe { mem::uninitialized() };
    let instance_buffer: glin::Buffer<InstanceAttributes> = unsafe { mem::uninitialized() };

    let vao = gl.new_vao()
        .bindings_from(&program, buffer)
        .instance_bindings_from(&program, instance_buffer, 1)
        .create()
        .unwrap();
}

divisor 0 means attribute per vertex, 1 attribute per instance, 2 attribute per 2 instances…

pub fn instance_attributes_from<T, B, I>(
    self,
    formats: I,
    from: B,
    divisor: usize
) -> Builder where
    T: 'static,
    B: BufferRange<T> + 'static,
    I: Into<Vec<Format>>, 
[src]

Specify attributes that will be read per instance

#[macro_use] extern crate glin;
extern crate na;
use std::mem;
use glin::VertexFormat;

#[derive(VertexFormat)]
struct Vertex{
   position: na::Vec3,
}

#[derive(VertexFormat)]
struct InstanceAttributes{
   model_matrix: na::Mat4,
}

fn main(){
    let gl: glin::Context = unsafe{ mem::uninitialized() };
    let program: glin::Program = unsafe { mem::uninitialized() };
    let buffer: glin::Buffer<Vertex> = unsafe { mem::uninitialized() };
    let instance_buffer: glin::Buffer<InstanceAttributes> = unsafe { mem::uninitialized() };
    let vertex_attributes = Vertex::attributes_formats(&program);
    let instance_attributes = InstanceAttributes::attributes_formats(&program);

    let vao = gl.new_vao()
        .attributes_from(vertex_attributes, buffer)
        .instance_attributes_from(instance_attributes, instance_buffer, 1)
        .create()
        .unwrap();
}

divisor 0 means attribute per vertex, 1 attribute per instance, 2 attribute per 2 instances…

pub fn indices<B, I>(self, indices: I) -> Builder where
    B: BufferRangeMut<IndexT> + 'static,
    I: Into<Option<B>>, 
[src]

Add an index buffer to the VAO

pub fn create(self) -> Result<Vao>[src]

Returns the VAO with the specified bindings

Auto Trait Implementations

impl !RefUnwindSafe for Builder

impl !Send for Builder

impl !Sync for Builder

impl Unpin for Builder

impl !UnwindSafe for Builder

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Any for T where
    T: Any
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T[src]

type Init = T

The type for initializers.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.