pub fn add<P: AsRef<Path>>(&mut self, path: P) -> Result<Index> {
        let img = {
            let mut buf = Vec::new();
            let mut reader = File::open(&path)?;
            let _ = reader.read_to_end(&mut buf)?;
            let rgba = image::load_from_memory(&buf)?.to_rgba();
            Arc::new(rgba)
        };

        if img.width() > self.width || img.height() > self.height {
            Err(Error::TextureArray(super::Error::ImageIsTooBig(
                PathBuf::from(path.as_ref()),
            )))
        } else {
            let offset = self.current.add(img.clone());

            match offset {
                Some(offset) => Ok(Index {
                    layer: self.layers.len() as u16,
                    offset,
                }),
                None => {
                    self.layers.push(self.current.clone());
                    self.current =
                        Layer::new(self.width as u16, self.height as u16);

                    Ok(Index {
                        layer: self.layers.len() as u16,
                        offset: self
                            .current
                            .add(img)
                            .expect("Image should fit layer"),
                    })
                }
            }
        }
    }
/// Loads a new image from the given path and adds it to the produced
/// [`TextureArray`].
///
/// The [`Builder`] will try to fit multiple images in the same layer of the
/// array. For example, if you are building a texture array of `2048x2048`
/// pixels and you add 4 images of `1024x1024` pixels, they will all share
/// the same layer.
///
/// As of now, the [`Builder`] uses a very naive placement algorithm. It
/// simply places images in rows as they are added if there is any space left
/// in the current layer. If there is not, it creates a new layer.
///
/// [`TextureArray`]: struct.TextureArray.html
/// [`Builder`]: struct.Builder.html
Loads a new image from the given path and adds it to the produced
[`TextureArray`].

The [`Builder`] will try to fit multiple images in the same layer of the
array. For example, if you are building a texture array of `2048x2048`
pixels and you add 4 images of `1024x1024` pixels, they will all share
the same layer.

As of now, the [`Builder`] uses a very naive placement algorithm. It
simply places images in rows as they are added if there is any space left
in the current layer. If there is not, it creates a new layer.


Loads a new image from the given path and adds it to the produced [ ` TextureArray ` ] . The [ ` Builder ` ] will try to fit multiple images in the same layer of the array . For example if you are building a texture array of ` 2048x2048 ` pixels and you add 4 images of ` 1024x1024 ` pixels they will all share the same layer . As of now the [ ` Builder ` ] uses a very naive placement algorithm . It simply places images in rows as they are added if there is any space left in the current layer . If there is not it creates a new layer .
pub fn add<P: AsRef<Path>>(&mut self, path: P) -> Result<Index> {
        let img = {
            let mut buf = Vec::new();
            let mut reader = File::open(&path)?;
            let _ = reader.read_to_end(&mut buf)?;
            let rgba = image::load_from_memory(&buf)?.to_rgba();
            Arc::new(rgba)
        };
        if img.width() > self.width || img.height() > self.height {
            Err(Error::TextureArray(super::Error::ImageIsTooBig(
                PathBuf::from(path.as_ref()),
            )))
        } else {
            let offset = self.current.add(img.clone());
            match offset {
                Some(offset) => Ok(Index {
                    layer: self.layers.len() as u16,
                    offset,
                }),
                None => {
                    self.layers.push(self.current.clone());
                    self.current =
                        Layer::new(self.width as u16, self.height as u16);
                    Ok(Index {
                        layer: self.layers.len() as u16,
                        offset: self
                            .current
                            .add(img)
                            .expect("Image should fit layer"),
                    })
                }
            }
        }
    }
pub fn add < P : AsRef < Path > > ( & mut self , path : P ) -> Result < Index > { let img = { let mut buf = Vec :: new ( ) ; let mut reader = File :: open ( & path ) ? ; let _ = reader . read_to_end ( & mut buf ) ? ; let rgba = image :: load_from_memory ( & buf ) ? . to_rgba ( ) ; Arc :: new ( rgba ) } ; if img . width ( ) > self . width || img . height ( ) > self . height { Err ( Error :: TextureArray ( super :: Error :: ImageIsTooBig ( PathBuf :: from ( path . as_ref ( ) ) , ) ) ) } else { let offset = self . current . add ( img . clone ( ) ) ; match offset { Some ( offset ) => Ok ( Index { layer : self . layers . len ( ) as u16 , offset , } ) , None => { self . layers . push ( self . current . clone ( ) ) ; self . current = Layer :: new ( self . width as u16 , self . height as u16 ) ; Ok ( Index { layer : self . layers . len ( ) as u16 , offset : self . current . add ( img ) . expect ( " " ) , } ) } } } }
Loads a new image from the given path and adds it to the produced
[`TextureArray`].
Loads a new image from the given path and adds it to the produced [ ` TextureArray ` ] .
&mut self
path
P
&mut self
path
P