pub fn make_copy(&self) -> Option<Texture> {
        unsafe {
            // Allocate a new texture for the copy
            let copy                = Texture::new();
            let texture_id          = copy.texture.texture_id;

            // Fetch information on the existing texture
            let format              = self.texture_format;
            let width               = self.width;
            let height              = self.height;

            // Attach the existing texture to the read buffer
            let existing_texture    = RenderTarget::from_texture(self)?;

            // Generate the main texture image
            match self.texture_target {
                gl::TEXTURE_1D => {
                    gl::BindTexture(gl::TEXTURE_1D, texture_id);

                    gl::TexParameteri(gl::TEXTURE_1D, gl::TEXTURE_MIN_FILTER, gl::LINEAR as i32);
                    gl::TexParameteri(gl::TEXTURE_1D, gl::TEXTURE_MAG_FILTER, gl::LINEAR as i32);

                    gl::TexImage1D(gl::TEXTURE_1D, 0, format as _, width, 0, format, gl::UNSIGNED_BYTE, ptr::null());
                    panic_on_gl_error("Create 1D copy target");
                }

                gl::TEXTURE_2D => {
                    gl::BindTexture(gl::TEXTURE_2D, texture_id);

                    gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::LINEAR as i32);
                    gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::LINEAR as i32);

                    gl::TexImage2D(gl::TEXTURE_2D, 0, format as _, width, height, 0, format, gl::UNSIGNED_BYTE, ptr::null());
                    panic_on_gl_error("Create 2D copy target");
                }

                gl::TEXTURE_2D_MULTISAMPLE => {
                    // Clamp the number of samples to the maximum supported by the driver
                    let mut max_samples = 1;
                    let samples         = self.num_samples;
                    gl::GetIntegerv(gl::MAX_COLOR_TEXTURE_SAMPLES, &mut max_samples);
                    let samples = max_samples.min(samples as i32);

                    // Set up a MSAA texture
                    gl::BindTexture(gl::TEXTURE_2D_MULTISAMPLE, texture_id);

                    gl::TexImage2DMultisample(gl::TEXTURE_2D_MULTISAMPLE, samples, gl::RGBA, width as _, height as _, gl::FALSE);
                    panic_on_gl_error("Create multisampled copy target");
                }

                _ => { 
                    // Don't know how to copy this target type
                    return None;
                }
            }


            // Find the currently bound frame buffer (so we can rebind it later on)
            let mut old_frame_buffer = 0;
            gl::GetIntegerv(gl::DRAW_FRAMEBUFFER_BINDING, &mut old_frame_buffer);
            panic_on_gl_error("Get old framebuffer");

            // Bind to the frame buffer
            gl::BindFramebuffer(gl::FRAMEBUFFER, *existing_texture);
            gl::ReadBuffer(gl::COLOR_ATTACHMENT0);
            panic_on_gl_error("Bind new framebuffer");

            // Copy the first subimage to the new texture from the old one
            match self.texture_target {
                gl::TEXTURE_1D => {
                    gl::CopyTexImage1D(gl::TEXTURE_1D, 0, format, 0, 0, width, 0);
                    panic_on_gl_error("Copy 1D");
                }

                gl::TEXTURE_2D => {
                    gl::CopyTexImage2D(gl::TEXTURE_2D, 0, format, 0, 0, width, height, 0);
                    panic_on_gl_error("Copy 2D");
                }

                _ => { /* Don't know how to copy */ }
            }

            // Bind back to the old framebuffer
            gl::BindFramebuffer(gl::FRAMEBUFFER, old_frame_buffer as _);

            // Return the copied texture
            Some(copy)
        }
    }
///
/// Creates a copy of this texture, if possible
///
Creates a copy of this texture, if possible
Creates a copy of this texture if possible
pub fn make_copy(&self) -> Option<Texture> {
        unsafe {
            // Allocate a new texture for the copy
            let copy                = Texture::new();
            let texture_id          = copy.texture.texture_id;
            // Fetch information on the existing texture
            let format              = self.texture_format;
            let width               = self.width;
            let height              = self.height;
            // Attach the existing texture to the read buffer
            let existing_texture    = RenderTarget::from_texture(self)?;
            // Generate the main texture image
            match self.texture_target {
                gl::TEXTURE_1D => {
                    gl::BindTexture(gl::TEXTURE_1D, texture_id);
                    gl::TexParameteri(gl::TEXTURE_1D, gl::TEXTURE_MIN_FILTER, gl::LINEAR as i32);
                    gl::TexParameteri(gl::TEXTURE_1D, gl::TEXTURE_MAG_FILTER, gl::LINEAR as i32);
                    gl::TexImage1D(gl::TEXTURE_1D, 0, format as _, width, 0, format, gl::UNSIGNED_BYTE, ptr::null());
                    panic_on_gl_error("Create 1D copy target");
                }
                gl::TEXTURE_2D => {
                    gl::BindTexture(gl::TEXTURE_2D, texture_id);
                    gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::LINEAR as i32);
                    gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::LINEAR as i32);
                    gl::TexImage2D(gl::TEXTURE_2D, 0, format as _, width, height, 0, format, gl::UNSIGNED_BYTE, ptr::null());
                    panic_on_gl_error("Create 2D copy target");
                }
                gl::TEXTURE_2D_MULTISAMPLE => {
                    // Clamp the number of samples to the maximum supported by the driver
                    let mut max_samples = 1;
                    let samples         = self.num_samples;
                    gl::GetIntegerv(gl::MAX_COLOR_TEXTURE_SAMPLES, &mut max_samples);
                    let samples = max_samples.min(samples as i32);
                    // Set up a MSAA texture
                    gl::BindTexture(gl::TEXTURE_2D_MULTISAMPLE, texture_id);
                    gl::TexImage2DMultisample(gl::TEXTURE_2D_MULTISAMPLE, samples, gl::RGBA, width as _, height as _, gl::FALSE);
                    panic_on_gl_error("Create multisampled copy target");
                }
                _ => { 
                    // Don't know how to copy this target type
                    return None;
                }
            }
            // Find the currently bound frame buffer (so we can rebind it later on)
            let mut old_frame_buffer = 0;
            gl::GetIntegerv(gl::DRAW_FRAMEBUFFER_BINDING, &mut old_frame_buffer);
            panic_on_gl_error("Get old framebuffer");
            // Bind to the frame buffer
            gl::BindFramebuffer(gl::FRAMEBUFFER, *existing_texture);
            gl::ReadBuffer(gl::COLOR_ATTACHMENT0);
            panic_on_gl_error("Bind new framebuffer");
            // Copy the first subimage to the new texture from the old one
            match self.texture_target {
                gl::TEXTURE_1D => {
                    gl::CopyTexImage1D(gl::TEXTURE_1D, 0, format, 0, 0, width, 0);
                    panic_on_gl_error("Copy 1D");
                }
                gl::TEXTURE_2D => {
                    gl::CopyTexImage2D(gl::TEXTURE_2D, 0, format, 0, 0, width, height, 0);
                    panic_on_gl_error("Copy 2D");
                }
                _ => { /* Don't know how to copy */ }
            }
            // Bind back to the old framebuffer
            gl::BindFramebuffer(gl::FRAMEBUFFER, old_frame_buffer as _);
            // Return the copied texture
            Some(copy)
        }
    }
pub fn make_copy ( & self ) -> Option < Texture > { unsafe { // Allocate a new texture for the copy let copy = Texture :: new ( ) ; let texture_id = copy . texture . texture_id ; // Fetch information on the existing texture let format = self . texture_format ; let width = self . width ; let height = self . height ; // Attach the existing texture to the read buffer let existing_texture = RenderTarget :: from_texture ( self ) ? ; // Generate the main texture image match self . texture_target { gl :: TEXTURE_1D => { gl :: BindTexture ( gl :: TEXTURE_1D , texture_id ) ; gl :: TexParameteri ( gl :: TEXTURE_1D , gl :: TEXTURE_MIN_FILTER , gl :: LINEAR as i32 ) ; gl :: TexParameteri ( gl :: TEXTURE_1D , gl :: TEXTURE_MAG_FILTER , gl :: LINEAR as i32 ) ; gl :: TexImage1D ( gl :: TEXTURE_1D , 0 , format as _ , width , 0 , format , gl :: UNSIGNED_BYTE , ptr :: null ( ) ) ; panic_on_gl_error ( " " ) ; } gl :: TEXTURE_2D => { gl :: BindTexture ( gl :: TEXTURE_2D , texture_id ) ; gl :: TexParameteri ( gl :: TEXTURE_2D , gl :: TEXTURE_MIN_FILTER , gl :: LINEAR as i32 ) ; gl :: TexParameteri ( gl :: TEXTURE_2D , gl :: TEXTURE_MAG_FILTER , gl :: LINEAR as i32 ) ; gl :: TexImage2D ( gl :: TEXTURE_2D , 0 , format as _ , width , height , 0 , format , gl :: UNSIGNED_BYTE , ptr :: null ( ) ) ; panic_on_gl_error ( " " ) ; } gl :: TEXTURE_2D_MULTISAMPLE => { // Clamp the number of samples to the maximum supported by the driver let mut max_samples = 1 ; let samples = self . num_samples ; gl :: GetIntegerv ( gl :: MAX_COLOR_TEXTURE_SAMPLES , & mut max_samples ) ; let samples = max_samples . min ( samples as i32 ) ; // Set up a MSAA texture gl :: BindTexture ( gl :: TEXTURE_2D_MULTISAMPLE , texture_id ) ; gl :: TexImage2DMultisample ( gl :: TEXTURE_2D_MULTISAMPLE , samples , gl :: RGBA , width as _ , height as _ , gl :: FALSE ) ; panic_on_gl_error ( " " ) ; } _ => { // Don't know how to copy this target type return None ; } } // Find the currently bound frame buffer (so we can rebind it later on) let mut old_frame_buffer = 0 ; gl :: GetIntegerv ( gl :: DRAW_FRAMEBUFFER_BINDING , & mut old_frame_buffer ) ; panic_on_gl_error ( " " ) ; // Bind to the frame buffer gl :: BindFramebuffer ( gl :: FRAMEBUFFER , * existing_texture ) ; gl :: ReadBuffer ( gl :: COLOR_ATTACHMENT0 ) ; panic_on_gl_error ( " " ) ; // Copy the first subimage to the new texture from the old one match self . texture_target { gl :: TEXTURE_1D => { gl :: CopyTexImage1D ( gl :: TEXTURE_1D , 0 , format , 0 , 0 , width , 0 ) ; panic_on_gl_error ( " " ) ; } gl :: TEXTURE_2D => { gl :: CopyTexImage2D ( gl :: TEXTURE_2D , 0 , format , 0 , 0 , width , height , 0 ) ; panic_on_gl_error ( " " ) ; } _ => { /* Don't know how to copy */ } } // Bind back to the old framebuffer gl :: BindFramebuffer ( gl :: FRAMEBUFFER , old_frame_buffer as _ ) ; // Return the copied texture Some ( copy ) } }
Creates a copy of this texture, if possible
Creates a copy of this texture if possible
&self