From ab6dd615924691c38a58b6ff9ac01efd37996df4 Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Wed, 28 Apr 2021 20:25:01 +0200 Subject: [PATCH] renderer: add destroy_texture function --- src/backend/drm/render.rs | 4 ++++ src/backend/renderer/gles2/mod.rs | 11 +++++++++++ src/backend/renderer/mod.rs | 1 + src/backend/winit.rs | 4 ++++ 4 files changed, 20 insertions(+) diff --git a/src/backend/drm/render.rs b/src/backend/drm/render.rs index 0d94f98..710ece4 100644 --- a/src/backend/drm/render.rs +++ b/src/backend/drm/render.rs @@ -251,6 +251,10 @@ where fn import_egl(&mut self, buffer: &EGLBuffer) -> Result { self.renderer.import_egl(buffer).map_err(Error::RenderError) } + + fn destroy_texture(&mut self, texture: Self::Texture) -> Result<(), Self::Error> { + self.renderer.destroy_texture(texture).map_err(Error::RenderError) + } fn begin(&mut self, width: u32, height: u32, transform: Transform) -> Result<(), Error> { if self.current_buffer.is_some() { diff --git a/src/backend/renderer/gles2/mod.rs b/src/backend/renderer/gles2/mod.rs index a9bb672..fa06a5b 100644 --- a/src/backend/renderer/gles2/mod.rs +++ b/src/backend/renderer/gles2/mod.rs @@ -558,6 +558,17 @@ impl Renderer for Gles2Renderer { Ok(texture) } + + fn destroy_texture(&mut self, mut texture: Self::Texture) -> Result<(), Self::Error> { + self.make_current()?; + + unsafe { + self.gl.DeleteTextures(1, &mut texture.texture); + } + self.egl.unbind()?; + + Ok(()) + } fn begin(&mut self, width: u32, height: u32, transform: Transform) -> Result<(), Gles2Error> { diff --git a/src/backend/renderer/mod.rs b/src/backend/renderer/mod.rs index f9bd9fe..8c37c23 100644 --- a/src/backend/renderer/mod.rs +++ b/src/backend/renderer/mod.rs @@ -147,6 +147,7 @@ pub trait Renderer { fn import_shm(&mut self, buffer: &wl_buffer::WlBuffer) -> Result; #[cfg(feature = "wayland_frontend")] fn import_egl(&mut self, buffer: &EGLBuffer) -> Result; + fn destroy_texture(&mut self, texture: Self::Texture) -> Result<(), Self::Error>; fn begin(&mut self, width: u32, height: u32, transform: Transform) -> Result<(), ::Error>; fn finish(&mut self) -> Result<(), SwapBuffersError>; diff --git a/src/backend/winit.rs b/src/backend/winit.rs index 9f9a739..f065fa1 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -280,6 +280,10 @@ impl Renderer for WinitGraphicsBackend { self.renderer.import_egl(buffer) } + fn destroy_texture(&mut self, texture: Self::Texture) -> Result<(), Self::Error> { + self.renderer.destroy_texture(texture) + } + fn begin(&mut self, width: u32, height: u32, transform: Transform) -> Result<(), ::Error> { self.renderer.bind(self.egl.clone())?; self.renderer.begin(width, height, transform)