pub fn blit_cpu(
    src: TextureView<'_>,
    dst: &mut Texture2D,
    dst_pos: Vec2u,
) -> Result<(), BlitError> {
    if src.format != dst.format {
        return Err(BlitError::IncompatibleFormat);
    }

    // Check if size will overflow.
    if src.extent.width() + dst_pos.x as i32 > dst.extent.width()
        || src.extent.height() + dst_pos.y as i32 > dst.extent.height()
    {
        return Err(BlitError::SizeOverflow);
    }

    let single_copy = dst_pos.x == 0 && dst_pos.y == 0 && dst.extent.width() == src.extent.width();

    if single_copy {
        unsafe {
            ptr::copy_nonoverlapping(src.data.as_ptr(), dst.data.as_mut_ptr(), src.data.len());
        }
        return Ok(());
    }

    // Copy line-by-line.
    let stride = src.format.stride();
    let max_height = src.extent.height() as u32;
    let width = src.extent.width() as u32;
    let mut height: u32 = 0;

    while height < max_height {
        unsafe {
            // FIXME:
            let src_data_ptr = src
                .data
                .as_ptr()
                .add(((height * width) as usize * stride) + dst_pos.x as usize);
            let dst_data_ptr = dst.data.as_mut_ptr().add(
                ((height + dst_pos.y) as usize * (dst.extent.width() as usize) * stride
                    + dst_pos.x as usize) as _,
            );

            ptr::copy_nonoverlapping(src_data_ptr, dst_data_ptr, width as _);
        }

        height += 1;
    }

    Ok(())
}
/// Copy a texture to given position in target texture.
Copy a texture to given position in target texture.
Copy a texture to given position in target texture .
pub fn blit_cpu(
    src: TextureView<'_>,
    dst: &mut Texture2D,
    dst_pos: Vec2u,
) -> Result<(), BlitError> {
    if src.format != dst.format {
        return Err(BlitError::IncompatibleFormat);
    }
    // Check if size will overflow.
    if src.extent.width() + dst_pos.x as i32 > dst.extent.width()
        || src.extent.height() + dst_pos.y as i32 > dst.extent.height()
    {
        return Err(BlitError::SizeOverflow);
    }
    let single_copy = dst_pos.x == 0 && dst_pos.y == 0 && dst.extent.width() == src.extent.width();
    if single_copy {
        unsafe {
            ptr::copy_nonoverlapping(src.data.as_ptr(), dst.data.as_mut_ptr(), src.data.len());
        }
        return Ok(());
    }
    // Copy line-by-line.
    let stride = src.format.stride();
    let max_height = src.extent.height() as u32;
    let width = src.extent.width() as u32;
    let mut height: u32 = 0;
    while height < max_height {
        unsafe {
            // FIXME:
            let src_data_ptr = src
                .data
                .as_ptr()
                .add(((height * width) as usize * stride) + dst_pos.x as usize);
            let dst_data_ptr = dst.data.as_mut_ptr().add(
                ((height + dst_pos.y) as usize * (dst.extent.width() as usize) * stride
                    + dst_pos.x as usize) as _,
            );
            ptr::copy_nonoverlapping(src_data_ptr, dst_data_ptr, width as _);
        }
        height += 1;
    }
    Ok(())
}
pub fn blit_cpu ( src : TextureView < ' _ > , dst : & mut Texture2D , dst_pos : Vec2u , ) -> Result < ( ) , BlitError > { if src . format != dst . format { return Err ( BlitError :: IncompatibleFormat ) ; } // Check if size will overflow. if src . extent . width ( ) + dst_pos . x as i32 > dst . extent . width ( ) || src . extent . height ( ) + dst_pos . y as i32 > dst . extent . height ( ) { return Err ( BlitError :: SizeOverflow ) ; } let single_copy = dst_pos . x == 0 && dst_pos . y == 0 && dst . extent . width ( ) == src . extent . width ( ) ; if single_copy { unsafe { ptr :: copy_nonoverlapping ( src . data . as_ptr ( ) , dst . data . as_mut_ptr ( ) , src . data . len ( ) ) ; } return Ok ( ( ) ) ; } // Copy line-by-line. let stride = src . format . stride ( ) ; let max_height = src . extent . height ( ) as u32 ; let width = src . extent . width ( ) as u32 ; let mut height : u32 = 0 ; while height < max_height { unsafe { // FIXME: let src_data_ptr = src . data . as_ptr ( ) . add ( ( ( height * width ) as usize * stride ) + dst_pos . x as usize ) ; let dst_data_ptr = dst . data . as_mut_ptr ( ) . add ( ( ( height + dst_pos . y ) as usize * ( dst . extent . width ( ) as usize ) * stride + dst_pos . x as usize ) as _ , ) ; ptr :: copy_nonoverlapping ( src_data_ptr , dst_data_ptr , width as _ ) ; } height += 1 ; } Ok ( ( ) ) }
Copy a texture to given position in target texture.
Copy a texture to given position in target texture .
src
TextureView<'_>
dst
&mut Texture2D
dst_pos
Vec2u
src
TextureView<'_>
dst
&mut Texture2D
dst_pos
Vec2u