pub fn build<B>(
        &self,
        queue: QueueId,
        factory: &mut Factory<B>,
    ) -> Result<Mesh<B>, failure::Error>
    where
        B: gfx_hal::Backend,
    {
        let mut len = u32::max_value();
        Ok(Mesh {
            vbufs: self
                .vertices
                .iter()
                .map(|(vertices, format)| {
                    len = min(len, vertices.len() as u32 / format.stride);
                    Ok(VertexBuffer {
                        buffer: {
                            let mut buffer =
                                factory.create_buffer(1, vertices.len() as _, UsageVertexBuffer)?;
                            unsafe {
                                // New buffer can't be touched by device yet.
                                factory.upload_buffer(
                                    &mut buffer,
                                    0,
                                    vertices,
                                    None,
                                    BufferState::new(queue)
                                        .with_access(gfx_hal::buffer::Access::VERTEX_BUFFER_READ),
                                )?;
                            }
                            buffer
                        },
                        format: format.clone(),
                    })
                })
                .collect::<Result<_, failure::Error>>()?,
            ibuf: match self.indices {
                None => None,
                Some((ref indices, index_type)) => {
                    let stride = match index_type {
                        gfx_hal::IndexType::U16 => size_of::<u16>(),
                        gfx_hal::IndexType::U32 => size_of::<u32>(),
                    };
                    len = indices.len() as u32 / stride as u32;
                    Some(IndexBuffer {
                        buffer: {
                            let mut buffer =
                                factory.create_buffer(1, indices.len() as _, UsageIndexBuffer)?;
                            unsafe {
                                // New buffer can't be touched by device yet.
                                factory.upload_buffer(
                                    &mut buffer,
                                    0,
                                    indices,
                                    None,
                                    BufferState::new(queue)
                                        .with_access(gfx_hal::buffer::Access::INDEX_BUFFER_READ),
                                )?;
                            }
                            buffer
                        },
                        index_type,
                    })
                }
            },
            prim: self.prim,
            len,
        })
    }
/// Builds and returns the new mesh.
Builds and returns the new mesh.
Builds and returns the new mesh .
pub fn build<B>(
        &self,
        queue: QueueId,
        factory: &mut Factory<B>,
    ) -> Result<Mesh<B>, failure::Error>
    where
        B: gfx_hal::Backend,
    {
        let mut len = u32::max_value();
        Ok(Mesh {
            vbufs: self
                .vertices
                .iter()
                .map(|(vertices, format)| {
                    len = min(len, vertices.len() as u32 / format.stride);
                    Ok(VertexBuffer {
                        buffer: {
                            let mut buffer =
                                factory.create_buffer(1, vertices.len() as _, UsageVertexBuffer)?;
                            unsafe {
                                // New buffer can't be touched by device yet.
                                factory.upload_buffer(
                                    &mut buffer,
                                    0,
                                    vertices,
                                    None,
                                    BufferState::new(queue)
                                        .with_access(gfx_hal::buffer::Access::VERTEX_BUFFER_READ),
                                )?;
                            }
                            buffer
                        },
                        format: format.clone(),
                    })
                })
                .collect::<Result<_, failure::Error>>()?,
            ibuf: match self.indices {
                None => None,
                Some((ref indices, index_type)) => {
                    let stride = match index_type {
                        gfx_hal::IndexType::U16 => size_of::<u16>(),
                        gfx_hal::IndexType::U32 => size_of::<u32>(),
                    };
                    len = indices.len() as u32 / stride as u32;
                    Some(IndexBuffer {
                        buffer: {
                            let mut buffer =
                                factory.create_buffer(1, indices.len() as _, UsageIndexBuffer)?;
                            unsafe {
                                // New buffer can't be touched by device yet.
                                factory.upload_buffer(
                                    &mut buffer,
                                    0,
                                    indices,
                                    None,
                                    BufferState::new(queue)
                                        .with_access(gfx_hal::buffer::Access::INDEX_BUFFER_READ),
                                )?;
                            }
                            buffer
                        },
                        index_type,
                    })
                }
            },
            prim: self.prim,
            len,
        })
    }
pub fn build < B > ( & self , queue : QueueId , factory : & mut Factory < B > , ) -> Result < Mesh < B > , failure :: Error > where B : gfx_hal :: Backend , { let mut len = u32 :: max_value ( ) ; Ok ( Mesh { vbufs : self . vertices . iter ( ) . map ( | ( vertices , format ) | { len = min ( len , vertices . len ( ) as u32 / format . stride ) ; Ok ( VertexBuffer { buffer : { let mut buffer = factory . create_buffer ( 1 , vertices . len ( ) as _ , UsageVertexBuffer ) ? ; unsafe { // New buffer can't be touched by device yet. factory . upload_buffer ( & mut buffer , 0 , vertices , None , BufferState :: new ( queue ) . with_access ( gfx_hal :: buffer :: Access :: VERTEX_BUFFER_READ ) , ) ? ; } buffer } , format : format . clone ( ) , } ) } ) . collect :: < Result < _ , failure :: Error > > ( ) ? , ibuf : match self . indices { None => None , Some ( ( ref indices , index_type ) ) => { let stride = match index_type { gfx_hal :: IndexType :: U16 => size_of :: < u16 > ( ) , gfx_hal :: IndexType :: U32 => size_of :: < u32 > ( ) , } ; len = indices . len ( ) as u32 / stride as u32 ; Some ( IndexBuffer { buffer : { let mut buffer = factory . create_buffer ( 1 , indices . len ( ) as _ , UsageIndexBuffer ) ? ; unsafe { // New buffer can't be touched by device yet. factory . upload_buffer ( & mut buffer , 0 , indices , None , BufferState :: new ( queue ) . with_access ( gfx_hal :: buffer :: Access :: INDEX_BUFFER_READ ) , ) ? ; } buffer } , index_type , } ) } } , prim : self . prim , len , } ) }
Builds and returns the new mesh.
Builds and returns the new mesh .
&self
queue
QueueId
factory
&mut Factory<B>
&self
queue
QueueId
factory
&mut Factory<B>