pub fn ensure_allocated(&mut self, new_capacity: usize, retain_old_data: bool) {
        if new_capacity > self.allocated {
            let mut new_buffer = 0;
            let bytes = new_capacity * mem::size_of::<T>();

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

                gl::BindVertexArray(self.vao);
                T::setup_attrib_pointers(0);

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

            self.vbo = new_buffer;
            self.allocated = new_capacity
        }
    }
/// Ensures that the capacity of this buffer is `new_capacity`. If necessary, this reallocates
/// the internal buffer. If the internal buffer is allready big enough this function does
/// nothing. `new_capacity` is in units of `T`.
/// If `retain_old_data` is `false` this will zero out all data if it decides to reallocate
Ensures that the capacity of this buffer is `new_capacity`. If necessary, this reallocates
the internal buffer. If the internal buffer is allready big enough this function does
nothing. `new_capacity` is in units of `T`.
If `retain_old_data` is `false` this will zero out all data if it decides to reallocate
Ensures that the capacity of this buffer is ` new_capacity ` . If necessary this reallocates the internal buffer . If the internal buffer is allready big enough this function does nothing . ` new_capacity ` is in units of ` T ` . If ` retain_old_data ` is ` false ` this will zero out all data if it decides to reallocate
pub fn ensure_allocated(&mut self, new_capacity: usize, retain_old_data: bool) {
        if new_capacity > self.allocated {
            let mut new_buffer = 0;
            let bytes = new_capacity * mem::size_of::<T>();
            unsafe {
                gl::GenBuffers(1, &mut new_buffer);
                gl::BindBuffer(BufferTarget::Array as GLenum, new_buffer);
                gl::BufferData(BufferTarget::Array as GLenum, bytes as GLsizeiptr, ptr::null(), self.usage as GLenum);
                gl::BindVertexArray(self.vao);
                T::setup_attrib_pointers(0);
                // Copy old data
                if retain_old_data && self.vbo != 0 {
                    gl::BindBuffer(BufferTarget::CopyRead as GLenum, self.vbo);
                    gl::CopyBufferSubData(
                        BufferTarget::CopyRead as GLenum,
                        BufferTarget::Array as GLenum,
                        0, 0,
                        (self.vertex_count * mem::size_of::<T>()) as GLsizeiptr
                    );
                    gl::DeleteBuffers(1, &mut self.vbo);
                }
            }
            self.vbo = new_buffer;
            self.allocated = new_capacity
        }
    }
pub fn ensure_allocated ( & mut self , new_capacity : usize , retain_old_data : bool ) { if new_capacity > self . allocated { let mut new_buffer = 0 ; let bytes = new_capacity * mem :: size_of :: < T > ( ) ; unsafe { gl :: GenBuffers ( 1 , & mut new_buffer ) ; gl :: BindBuffer ( BufferTarget :: Array as GLenum , new_buffer ) ; gl :: BufferData ( BufferTarget :: Array as GLenum , bytes as GLsizeiptr , ptr :: null ( ) , self . usage as GLenum ) ; gl :: BindVertexArray ( self . vao ) ; T :: setup_attrib_pointers ( 0 ) ; // Copy old data if retain_old_data && self . vbo != 0 { gl :: BindBuffer ( BufferTarget :: CopyRead as GLenum , self . vbo ) ; gl :: CopyBufferSubData ( BufferTarget :: CopyRead as GLenum , BufferTarget :: Array as GLenum , 0 , 0 , ( self . vertex_count * mem :: size_of :: < T > ( ) ) as GLsizeiptr ) ; gl :: DeleteBuffers ( 1 , & mut self . vbo ) ; } } self . vbo = new_buffer ; self . allocated = new_capacity } }
Ensures that the capacity of this buffer is `new_capacity`.
Ensures that the capacity of this buffer is ` new_capacity ` .
&mut self
new_capacity
usize
retain_old_data
bool
&mut self
new_capacity
usize
retain_old_data
bool