pub fn build(self, fac: &mut Factory) -> Result<Texture> {
        use gfx::format::Swizzle;
        use gfx::memory::cast_slice;
        use gfx::texture::ResourceDesc;
        use gfx::Factory;
        use std::mem::size_of;

        // This variable has to live here to make sure the flipped
        // buffer lives long enough. (If one exists)
        let mut v_flip_buffer;
        let mut data = self.data.as_ref();

        if cfg!(feature = "opengl") {
            let pixel_width = (self.info.format.get_total_bits() / 8) as usize / size_of::<T>();
            v_flip_buffer = Vec::with_capacity(data.len());
            let (w, h, _, _) = self.info.kind.get_dimensions();
            let w = w as usize;
            let h = h as usize;
            for y in 0..h {
                for x in 0..(w * pixel_width) {
                    v_flip_buffer.push(data[x + (h - y - 1) * w * pixel_width]);
                    // Uncomment this if you need to debug this.
                    //println!("x: {}, y: {}, w: {}, h: {}, pw: {}", x, y, w, h, pixel_width);
                }
            }
            data = &v_flip_buffer;
        }

        let tex = fac.create_texture_raw(
            self.info,
            Some(self.channel_type),
            Some((&[cast_slice(data)], Mipmap::Provided)),
        )?;

        let desc = ResourceDesc {
            channel: self.channel_type,
            layer: None,
            min: 1,
            max: self.info.levels,
            swizzle: Swizzle::new(),
        };

        let view = fac.view_texture_as_shader_resource_raw(&tex, desc)?;
        let sampler = fac.create_sampler(self.sampler);

        Ok(Texture {
            sampler: sampler,
            texture: tex,
            view: view,
        })
    }
/// Builds and returns the new texture.
Builds and returns the new texture.
Builds and returns the new texture .
pub fn build(self, fac: &mut Factory) -> Result<Texture> {
        use gfx::format::Swizzle;
        use gfx::memory::cast_slice;
        use gfx::texture::ResourceDesc;
        use gfx::Factory;
        use std::mem::size_of;
        // This variable has to live here to make sure the flipped
        // buffer lives long enough. (If one exists)
        let mut v_flip_buffer;
        let mut data = self.data.as_ref();
        if cfg!(feature = "opengl") {
            let pixel_width = (self.info.format.get_total_bits() / 8) as usize / size_of::<T>();
            v_flip_buffer = Vec::with_capacity(data.len());
            let (w, h, _, _) = self.info.kind.get_dimensions();
            let w = w as usize;
            let h = h as usize;
            for y in 0..h {
                for x in 0..(w * pixel_width) {
                    v_flip_buffer.push(data[x + (h - y - 1) * w * pixel_width]);
                    // Uncomment this if you need to debug this.
                    //println!("x: {}, y: {}, w: {}, h: {}, pw: {}", x, y, w, h, pixel_width);
                }
            }
            data = &v_flip_buffer;
        }
        let tex = fac.create_texture_raw(
            self.info,
            Some(self.channel_type),
            Some((&[cast_slice(data)], Mipmap::Provided)),
        )?;
        let desc = ResourceDesc {
            channel: self.channel_type,
            layer: None,
            min: 1,
            max: self.info.levels,
            swizzle: Swizzle::new(),
        };
        let view = fac.view_texture_as_shader_resource_raw(&tex, desc)?;
        let sampler = fac.create_sampler(self.sampler);
        Ok(Texture {
            sampler: sampler,
            texture: tex,
            view: view,
        })
    }
pub fn build ( self , fac : & mut Factory ) -> Result < Texture > { use gfx :: format :: Swizzle ; use gfx :: memory :: cast_slice ; use gfx :: texture :: ResourceDesc ; use gfx :: Factory ; use std :: mem :: size_of ; // This variable has to live here to make sure the flipped // buffer lives long enough. (If one exists) let mut v_flip_buffer ; let mut data = self . data . as_ref ( ) ; if cfg ! ( feature " " ) { let pixel_width = ( self . info . format . get_total_bits ( ) / 8 ) as usize / size_of :: < T > ( ) ; v_flip_buffer = Vec :: with_capacity ( data . len ( ) ) ; let ( w , h , _ , _ ) = self . info . kind . get_dimensions ( ) ; let w = w as usize ; let h = h as usize ; for y in 0 .. h { for x in 0 .. ( w * pixel_width ) { v_flip_buffer . push ( data [ x + ( h - y - 1 ) * w * pixel_width ] ) ; // Uncomment this if you need to debug this. //println!("x: {}, y: {}, w: {}, h: {}, pw: {}", x, y, w, h, pixel_width); } } data = & v_flip_buffer ; } let tex = fac . create_texture_raw ( self . info , Some ( self . channel_type ) , Some ( ( & [ cast_slice ( data ) ] , Mipmap :: Provided ) ) , ) ? ; let desc = ResourceDesc { channel : self . channel_type , layer : None , min : 1 , max : self . info . levels , swizzle : Swizzle :: new ( ) , } ; let view = fac . view_texture_as_shader_resource_raw ( & tex , desc ) ? ; let sampler = fac . create_sampler ( self . sampler ) ; Ok ( Texture { sampler : sampler , texture : tex , view : view , } ) }
Builds and returns the new texture.
Builds and returns the new texture .
self
fac
&mut Factory
self
fac
&mut Factory