Stop leaking textures and framebuffers in the OpenGL backend.
Closes #264. Possibly addresses #286.
This commit is contained in:
parent
bbcd371efc
commit
32a56eab85
|
@ -456,12 +456,15 @@ impl Device for GLDevice {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
fn destroy_framebuffer(&self, framebuffer: Self::Framebuffer) -> Self::Texture {
|
||||
fn destroy_framebuffer(&self, mut framebuffer: Self::Framebuffer) -> Self::Texture {
|
||||
let texture = GLTexture {
|
||||
gl_texture: framebuffer.texture.gl_texture,
|
||||
size: framebuffer.texture.size,
|
||||
format: framebuffer.texture.format,
|
||||
};
|
||||
unsafe {
|
||||
gl::DeleteFramebuffers(1, &mut framebuffer.gl_framebuffer); ck();
|
||||
}
|
||||
mem::forget(framebuffer);
|
||||
texture
|
||||
}
|
||||
|
@ -991,6 +994,14 @@ pub struct GLTexture {
|
|||
pub format: TextureFormat,
|
||||
}
|
||||
|
||||
impl Drop for GLTexture {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
gl::DeleteTextures(1, &mut self.gl_texture); ck();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GLTimerQuery {
|
||||
gl_query: GLuint,
|
||||
}
|
||||
|
|
|
@ -1140,12 +1140,11 @@ impl<D> TextureCache<D> where D: Device {
|
|||
fn create_texture(&mut self, device: &mut D, format: TextureFormat, size: Vector2I)
|
||||
-> D::Texture {
|
||||
for index in 0..self.textures.len() {
|
||||
if device.texture_size(&self.textures[index]) != size ||
|
||||
device.texture_format(&self.textures[index]) != format {
|
||||
continue;
|
||||
}
|
||||
if device.texture_size(&self.textures[index]) == size &&
|
||||
device.texture_format(&self.textures[index]) == format {
|
||||
return self.textures.remove(index);
|
||||
}
|
||||
}
|
||||
|
||||
device.create_texture(format, size)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue