pub fn load_texture(
        &self,
        dimensions: (i32, i32),
        pixels: Option<&[u8]>,
        internal_format: gl::types::GLint,
        format: gl::types::GLenum,
        data_type: gl::types::GLenum,
        repeat: bool,
    ) {
        assert!(dimensions.0 >= 0);
        assert!(dimensions.1 >= 0);
        self.bind();
        let pixels_pointer = if let Some(pixels) = pixels {
            // Check correct size of data and dimensions.
            let pixel_size = match format {
                gl::RGBA => 4,
                _ => panic!("Unhandled pixel type."),
            };
            assert_eq!(
                pixels.len(),
                (dimensions.0 * dimensions.1) as usize * pixel_size,
                "Inconsistent texture size!"
            );

            pixels.as_ptr() as *const std::ffi::c_void
        } else {
            std::ptr::null() as *const std::ffi::c_void
        };

        // Safety: the size of the data **MUST** be correct, as checked above.
        unsafe {
            gl::TexImage2D(
                gl::TEXTURE_2D, // Target
                0,              // Level-of-detail number. 0 for no mip-map
                internal_format,
                dimensions.0,
                dimensions.1,
                0, // Docs declare that this argument must be zero.
                format,
                data_type,
                pixels_pointer,
            );
        }

        let param = match repeat {
            true => gl::REPEAT,
            false => gl::CLAMP_TO_BORDER,
        };

        // Safety: No particular requirements, beyond enums should be valid or else OpenGL will log
        // an error.
        unsafe {
            gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_WRAP_S, param as i32);
            gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_WRAP_T, param as i32);
            gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::NEAREST as i32);
            gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::NEAREST as i32);
        }
    }
/// Loads given texture data into this texture. If `pixels` is `None`, the texture memory is
/// allocated but left unassigned.
Loads given texture data into this texture. If `pixels` is `None`, the texture memory is
allocated but left unassigned.
Loads given texture data into this texture . If ` pixels ` is ` None ` the texture memory is allocated but left unassigned .
pub fn load_texture(
        &self,
        dimensions: (i32, i32),
        pixels: Option<&[u8]>,
        internal_format: gl::types::GLint,
        format: gl::types::GLenum,
        data_type: gl::types::GLenum,
        repeat: bool,
    ) {
        assert!(dimensions.0 >= 0);
        assert!(dimensions.1 >= 0);
        self.bind();
        let pixels_pointer = if let Some(pixels) = pixels {
            // Check correct size of data and dimensions.
            let pixel_size = match format {
                gl::RGBA => 4,
                _ => panic!("Unhandled pixel type."),
            };
            assert_eq!(
                pixels.len(),
                (dimensions.0 * dimensions.1) as usize * pixel_size,
                "Inconsistent texture size!"
            );
            pixels.as_ptr() as *const std::ffi::c_void
        } else {
            std::ptr::null() as *const std::ffi::c_void
        };
        // Safety: the size of the data **MUST** be correct, as checked above.
        unsafe {
            gl::TexImage2D(
                gl::TEXTURE_2D, // Target
                0,              // Level-of-detail number. 0 for no mip-map
                internal_format,
                dimensions.0,
                dimensions.1,
                0, // Docs declare that this argument must be zero.
                format,
                data_type,
                pixels_pointer,
            );
        }
        let param = match repeat {
            true => gl::REPEAT,
            false => gl::CLAMP_TO_BORDER,
        };
        // Safety: No particular requirements, beyond enums should be valid or else OpenGL will log
        // an error.
        unsafe {
            gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_WRAP_S, param as i32);
            gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_WRAP_T, param as i32);
            gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::NEAREST as i32);
            gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::NEAREST as i32);
        }
    }
pub fn load_texture ( & self , dimensions : ( i32 , i32 ) , pixels : Option < & [ u8 ] > , internal_format : gl :: types :: GLint , format : gl :: types :: GLenum , data_type : gl :: types :: GLenum , repeat : bool , ) { assert ! ( dimensions 0 0 ) ; assert ! ( dimensions 1 0 ) ; self . bind ( ) ; let pixels_pointer = if let Some ( pixels ) = pixels { // Check correct size of data and dimensions. let pixel_size = match format { gl :: RGBA => 4 , _ => panic ! ( " " ) , } ; assert_eq ! ( pixels len ( ) ( dimensions 0 dimensions 1 ) as usize pixel_size " " ) ; pixels . as_ptr ( ) as * const std :: ffi :: c_void } else { std :: ptr :: null ( ) as * const std :: ffi :: c_void } ; // Safety: the size of the data **MUST** be correct, as checked above. unsafe { gl :: TexImage2D ( gl :: TEXTURE_2D , // Target 0 , // Level-of-detail number. 0 for no mip-map internal_format , dimensions . 0 , dimensions . 1 , 0 , // Docs declare that this argument must be zero. format , data_type , pixels_pointer , ) ; } let param = match repeat { true => gl :: REPEAT , false => gl :: CLAMP_TO_BORDER , } ; // Safety: No particular requirements, beyond enums should be valid or else OpenGL will log // an error. unsafe { gl :: TexParameteri ( gl :: TEXTURE_2D , gl :: TEXTURE_WRAP_S , param as i32 ) ; gl :: TexParameteri ( gl :: TEXTURE_2D , gl :: TEXTURE_WRAP_T , param as i32 ) ; gl :: TexParameteri ( gl :: TEXTURE_2D , gl :: TEXTURE_MAG_FILTER , gl :: NEAREST as i32 ) ; gl :: TexParameteri ( gl :: TEXTURE_2D , gl :: TEXTURE_MIN_FILTER , gl :: NEAREST as i32 ) ; } }
Loads given texture data into this texture.
Loads given texture data into this texture .
&self
dimensions
(i32, i32)
pixels
Option<&[u8]>
internal_format
gl::types::GLint
format
gl::types::GLenum
data_type
gl::types::GLenum
repeat
bool
&self
dimensions
(i32, i32)
pixels
Option<&[u8]>
internal_format
gl::types::GLint
format
gl::types::GLenum
data_type
gl::types::GLenum
repeat
bool