renderer: add destroy_texture function

This commit is contained in:
Victor Brekenfeld 2021-04-28 20:25:01 +02:00
parent 30a8693789
commit ab6dd61592
4 changed files with 20 additions and 0 deletions

View File

@ -251,6 +251,10 @@ where
fn import_egl(&mut self, buffer: &EGLBuffer) -> Result<Self::Texture, Self::Error> { fn import_egl(&mut self, buffer: &EGLBuffer) -> Result<Self::Texture, Self::Error> {
self.renderer.import_egl(buffer).map_err(Error::RenderError) 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<E1, E2, E3>> { fn begin(&mut self, width: u32, height: u32, transform: Transform) -> Result<(), Error<E1, E2, E3>> {
if self.current_buffer.is_some() { if self.current_buffer.is_some() {

View File

@ -558,6 +558,17 @@ impl Renderer for Gles2Renderer {
Ok(texture) 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> { fn begin(&mut self, width: u32, height: u32, transform: Transform) -> Result<(), Gles2Error> {

View File

@ -147,6 +147,7 @@ pub trait Renderer {
fn import_shm(&mut self, buffer: &wl_buffer::WlBuffer) -> Result<Self::Texture, Self::Error>; fn import_shm(&mut self, buffer: &wl_buffer::WlBuffer) -> Result<Self::Texture, Self::Error>;
#[cfg(feature = "wayland_frontend")] #[cfg(feature = "wayland_frontend")]
fn import_egl(&mut self, buffer: &EGLBuffer) -> Result<Self::Texture, Self::Error>; fn import_egl(&mut self, buffer: &EGLBuffer) -> Result<Self::Texture, Self::Error>;
fn destroy_texture(&mut self, texture: Self::Texture) -> Result<(), Self::Error>;
fn begin(&mut self, width: u32, height: u32, transform: Transform) -> Result<(), <Self as Renderer>::Error>; fn begin(&mut self, width: u32, height: u32, transform: Transform) -> Result<(), <Self as Renderer>::Error>;
fn finish(&mut self) -> Result<(), SwapBuffersError>; fn finish(&mut self) -> Result<(), SwapBuffersError>;

View File

@ -280,6 +280,10 @@ impl Renderer for WinitGraphicsBackend {
self.renderer.import_egl(buffer) 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<(), <Self as Renderer>::Error> { fn begin(&mut self, width: u32, height: u32, transform: Transform) -> Result<(), <Self as Renderer>::Error> {
self.renderer.bind(self.egl.clone())?; self.renderer.bind(self.egl.clone())?;
self.renderer.begin(width, height, transform) self.renderer.begin(width, height, transform)