Bladeren bron

Implemented missing Drops

raster
Bergmann89 5 jaren geleden
bovenliggende
commit
a69f42a65b
3 gewijzigde bestanden met toevoegingen van 27 en 2 verwijderingen
  1. +6
    -0
      glc/src/array_buffer.rs
  2. +6
    -0
      glc/src/texture.rs
  3. +15
    -2
      glc/src/vertex_array.rs

+ 6
- 0
glc/src/array_buffer.rs Bestand weergeven

@@ -150,6 +150,12 @@ impl ArrayBuffer {
} }
} }


impl Drop for ArrayBuffer {
fn drop(&mut self) {
gl::delete_buffers(1, &self.id);
}
}

impl Bindable for ArrayBuffer { impl Bindable for ArrayBuffer {
fn bind(&self) { fn bind(&self) {
gl::bind_buffer(self.target.as_enum(), self.id); gl::bind_buffer(self.target.as_enum(), self.id);


+ 6
- 0
glc/src/texture.rs Bestand weergeven

@@ -125,6 +125,12 @@ impl Texture {
} }
} }


impl Drop for Texture {
fn drop(&mut self) {
gl::delete_textures(1, &self.id);
}
}

impl Bindable for Texture { impl Bindable for Texture {
fn bind(&self) { fn bind(&self) {
gl::bind_texture(self.target.as_enum(), self.id); gl::bind_texture(self.target.as_enum(), self.id);


+ 15
- 2
glc/src/vertex_array.rs Bestand weergeven

@@ -25,6 +25,12 @@ impl VertexArray {
} }
} }


impl Drop for VertexArray {
fn drop(&mut self) {
gl::delete_vertex_arrays(1, &self.id);
}
}

impl Bindable for VertexArray { impl Bindable for VertexArray {
fn bind(&self) { fn bind(&self) {
gl::bind_vertex_array(self.id); gl::bind_vertex_array(self.id);
@@ -59,15 +65,16 @@ impl Builder {


Error::checked(|| gl::create_vertex_arrays(1, &mut id))?; Error::checked(|| gl::create_vertex_arrays(1, &mut id))?;


let vertex_array = VertexArray {
let mut vertex_array = VertexArray {
id, id,
buffers: Vec::new(), buffers: Vec::new(),
}; };


let guard = BindGuard::new(&vertex_array); let guard = BindGuard::new(&vertex_array);


let mut buffers = Vec::new();
for binding in self.bindings { for binding in self.bindings {
let _guard = BindGuard::new(&binding.buffer);
let guard = BindGuard::new(&binding.buffer);


for pointer in binding.pointers { for pointer in binding.pointers {
Error::checked(|| { Error::checked(|| {
@@ -86,10 +93,16 @@ impl Builder {
) )
})?; })?;
} }

drop(guard);

buffers.push(binding.buffer);
} }


drop(guard); drop(guard);


vertex_array.buffers = buffers;

Ok(vertex_array) Ok(vertex_array)
} }
} }


Laden…
Annuleren
Opslaan