pub fn read_data<T: GlType>(&self, format: GLenum) -> Result<Vec<T>, String>
        where T: Default + Clone
    {
        let n_elems = self.width as usize * self.height as usize;
        let size = n_elems * mem::size_of::<T>();
        let buf = vec![T::default(); n_elems];
        let err = unsafe {
            gl::GetTextureImage(self.id, 0, format, T::get_gl_type(), size as GLsizei, buf.as_ptr() as *mut _);
            gl::GetError()
        };
        if err == gl::NO_ERROR { Ok(buf) } else { Err(format!("read_data: GL error {:x}", err)) }
    }
//FIXME: there should be a safer way of doing this. maybe storing the size of the internal format
there should be a safer way of doing this. maybe storing the size of the internal format
there should be a safer way of doing this . maybe storing the size of the internal format
pub fn read_data<T: GlType>(&self, format: GLenum) -> Result<Vec<T>, String>
        where T: Default + Clone
    {
        let n_elems = self.width as usize * self.height as usize;
        let size = n_elems * mem::size_of::<T>();
        let buf = vec![T::default(); n_elems];
        let err = unsafe {
            gl::GetTextureImage(self.id, 0, format, T::get_gl_type(), size as GLsizei, buf.as_ptr() as *mut _);
            gl::GetError()
        };
        if err == gl::NO_ERROR { Ok(buf) } else { Err(format!("read_data: GL error {:x}", err)) }
    }
pub fn read_data < T : GlType > ( & self , format : GLenum ) -> Result < Vec < T > , String > where T : Default + Clone { let n_elems = self . width as usize * self . height as usize ; let size = n_elems * mem :: size_of :: < T > ( ) ; let buf = vec ! [ T default ( ) n_elems ] ; let err = unsafe { gl :: GetTextureImage ( self . id , 0 , format , T :: get_gl_type ( ) , size as GLsizei , buf . as_ptr ( ) as * mut _ ) ; gl :: GetError ( ) } ; if err == gl :: NO_ERROR { Ok ( buf ) } else { Err ( format ! ( " " err ) ) } }
FIXME: there should be a safer way of doing this.
FIXME : there should be a safer way of doing this .
&self
format
GLenum
&self
format
GLenum