pub fn ensure_allocated(&mut self, new_size: usize, retain_old_data: bool) {
        // Only reallocate if necessary
        if new_size > self.allocated {
            let bytes = new_size * mem::size_of::<T>();

            let mut new_vbo = 0;

            unsafe {
                gl::GenBuffers(1, &mut new_vbo);
                gl::BindBuffer(BufferTarget::Array as GLenum, new_vbo);
                gl::BufferData(BufferTarget::Array as GLenum, bytes as GLsizeiptr, ptr::null(), self.usage as GLenum);

                // Copy old data
                if retain_old_data && self.buffer != 0 {
                    gl::BindBuffer(BufferTarget::CopyRead as GLenum, self.buffer);
                    gl::CopyBufferSubData(
                        BufferTarget::CopyRead as GLenum,
                        BufferTarget::Array as GLenum,
                        0, 0,
                        (self.primitive_count*mem::size_of::<T>()) as GLsizeiptr
                    );
                    gl::DeleteBuffers(1, &mut self.buffer);
                }
            }

            self.buffer = new_vbo;
            self.allocated = new_size
        }
    }
/// Sets the number of vertices that can be stored in this buffer without reallocating memory.
/// If the buffer already has capacity for the given number of vertices no space will be
/// allocated.
/// If `retain_old_data` is `false` this will zero out all data if it decides to reallocate
Sets the number of vertices that can be stored in this buffer without reallocating memory.
If the buffer already has capacity for the given number of vertices no space will be
allocated.
If `retain_old_data` is `false` this will zero out all data if it decides to reallocate
Sets the number of vertices that can be stored in this buffer without reallocating memory . If the buffer already has capacity for the given number of vertices no space will be allocated . If ` retain_old_data ` is ` false ` this will zero out all data if it decides to reallocate
pub fn ensure_allocated(&mut self, new_size: usize, retain_old_data: bool) {
        // Only reallocate if necessary
        if new_size > self.allocated {
            let bytes = new_size * mem::size_of::<T>();
            let mut new_vbo = 0;
            unsafe {
                gl::GenBuffers(1, &mut new_vbo);
                gl::BindBuffer(BufferTarget::Array as GLenum, new_vbo);
                gl::BufferData(BufferTarget::Array as GLenum, bytes as GLsizeiptr, ptr::null(), self.usage as GLenum);
                // Copy old data
                if retain_old_data && self.buffer != 0 {
                    gl::BindBuffer(BufferTarget::CopyRead as GLenum, self.buffer);
                    gl::CopyBufferSubData(
                        BufferTarget::CopyRead as GLenum,
                        BufferTarget::Array as GLenum,
                        0, 0,
                        (self.primitive_count*mem::size_of::<T>()) as GLsizeiptr
                    );
                    gl::DeleteBuffers(1, &mut self.buffer);
                }
            }
            self.buffer = new_vbo;
            self.allocated = new_size
        }
    }
pub fn ensure_allocated ( & mut self , new_size : usize , retain_old_data : bool ) { // Only reallocate if necessary if new_size > self . allocated { let bytes = new_size * mem :: size_of :: < T > ( ) ; let mut new_vbo = 0 ; unsafe { gl :: GenBuffers ( 1 , & mut new_vbo ) ; gl :: BindBuffer ( BufferTarget :: Array as GLenum , new_vbo ) ; gl :: BufferData ( BufferTarget :: Array as GLenum , bytes as GLsizeiptr , ptr :: null ( ) , self . usage as GLenum ) ; // Copy old data if retain_old_data && self . buffer != 0 { gl :: BindBuffer ( BufferTarget :: CopyRead as GLenum , self . buffer ) ; gl :: CopyBufferSubData ( BufferTarget :: CopyRead as GLenum , BufferTarget :: Array as GLenum , 0 , 0 , ( self . primitive_count * mem :: size_of :: < T > ( ) ) as GLsizeiptr ) ; gl :: DeleteBuffers ( 1 , & mut self . buffer ) ; } } self . buffer = new_vbo ; self . allocated = new_size } }
Sets the number of vertices that can be stored in this buffer without reallocating memory.
Sets the number of vertices that can be stored in this buffer without reallocating memory .
&mut self
new_size
usize
retain_old_data
bool
&mut self
new_size
usize
retain_old_data
bool