renderer: rename Texture to TextureId to better convey nature of the handle
This commit is contained in:
parent
ab6dd61592
commit
85bef5fec6
|
@ -223,17 +223,17 @@ where
|
|||
D: AsRawFd + 'static,
|
||||
A: Allocator<B, Error=E1>,
|
||||
B: Buffer + TryInto<Dmabuf, Error=E2>,
|
||||
R: Bind<Dmabuf> + Renderer<Error=E3, Texture=T>,
|
||||
R: Bind<Dmabuf> + Renderer<Error=E3, TextureId=T>,
|
||||
T: Texture,
|
||||
E1: std::error::Error + 'static,
|
||||
E2: std::error::Error + 'static,
|
||||
E3: std::error::Error + 'static,
|
||||
{
|
||||
type Error = Error<E1, E2, E3>;
|
||||
type Texture = T;
|
||||
type TextureId = T;
|
||||
|
||||
#[cfg(feature = "image")]
|
||||
fn import_bitmap<C: std::ops::Deref<Target=[u8]>>(&mut self, image: &image::ImageBuffer<image::Rgba<u8>, C>) -> Result<Self::Texture, Self::Error> {
|
||||
fn import_bitmap<C: std::ops::Deref<Target=[u8]>>(&mut self, image: &image::ImageBuffer<image::Rgba<u8>, C>) -> Result<Self::TextureId, Self::Error> {
|
||||
self.renderer.import_bitmap(image).map_err(Error::RenderError)
|
||||
}
|
||||
|
||||
|
@ -243,16 +243,16 @@ where
|
|||
}
|
||||
|
||||
#[cfg(feature = "wayland_frontend")]
|
||||
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::TextureId, Self::Error> {
|
||||
self.renderer.import_shm(buffer).map_err(Error::RenderError)
|
||||
}
|
||||
|
||||
#[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::TextureId, Self::Error> {
|
||||
self.renderer.import_egl(buffer).map_err(Error::RenderError)
|
||||
}
|
||||
|
||||
fn destroy_texture(&mut self, texture: Self::Texture) -> Result<(), Self::Error> {
|
||||
fn destroy_texture(&mut self, texture: Self::TextureId) -> Result<(), Self::Error> {
|
||||
self.renderer.destroy_texture(texture).map_err(Error::RenderError)
|
||||
}
|
||||
|
||||
|
@ -271,7 +271,7 @@ where
|
|||
self.renderer.clear(color).map_err(Error::RenderError)
|
||||
}
|
||||
|
||||
fn render_texture(&mut self, texture: &Self::Texture, matrix: Matrix3<f32>, alpha: f32) -> Result<(), Self::Error> {
|
||||
fn render_texture(&mut self, texture: &Self::TextureId, matrix: Matrix3<f32>, alpha: f32) -> Result<(), Self::Error> {
|
||||
self.renderer.render_texture(texture, matrix, alpha).map_err(Error::RenderError)
|
||||
}
|
||||
|
||||
|
|
|
@ -426,7 +426,7 @@ static TEX_COORDS: [ffi::types::GLfloat; 8] = [
|
|||
|
||||
impl Renderer for Gles2Renderer {
|
||||
type Error = Gles2Error;
|
||||
type Texture = Gles2Texture;
|
||||
type TextureId = Gles2Texture;
|
||||
|
||||
#[cfg(feature = "wayland_frontend")]
|
||||
fn shm_formats(&self) -> &[wl_shm::Format] {
|
||||
|
@ -439,7 +439,7 @@ impl Renderer for Gles2Renderer {
|
|||
}
|
||||
|
||||
#[cfg(feature = "image")]
|
||||
fn import_bitmap<C: std::ops::Deref<Target=[u8]>>(&mut self, image: &image::ImageBuffer<image::Rgba<u8>, C>) -> Result<Self::Texture, Self::Error> {
|
||||
fn import_bitmap<C: std::ops::Deref<Target=[u8]>>(&mut self, image: &image::ImageBuffer<image::Rgba<u8>, C>) -> Result<Self::TextureId, Self::Error> {
|
||||
self.make_current()?;
|
||||
|
||||
let mut tex = 0;
|
||||
|
@ -467,7 +467,7 @@ impl Renderer for Gles2Renderer {
|
|||
|
||||
|
||||
#[cfg(feature = "wayland_frontend")]
|
||||
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::TextureId, Self::Error> {
|
||||
use crate::wayland::shm::with_buffer_contents;
|
||||
|
||||
with_buffer_contents(&buffer, |slice, data| {
|
||||
|
@ -522,7 +522,7 @@ impl Renderer for Gles2Renderer {
|
|||
}
|
||||
|
||||
#[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::TextureId, Self::Error> {
|
||||
if !self.extensions.iter().any(|ext| ext == "GL_OES_EGL_image") {
|
||||
return Err(Gles2Error::GLExtensionNotSupported(&["GL_OES_EGL_image"]));
|
||||
}
|
||||
|
@ -559,7 +559,7 @@ impl Renderer for Gles2Renderer {
|
|||
Ok(texture)
|
||||
}
|
||||
|
||||
fn destroy_texture(&mut self, mut texture: Self::Texture) -> Result<(), Self::Error> {
|
||||
fn destroy_texture(&mut self, mut texture: Self::TextureId) -> Result<(), Self::Error> {
|
||||
self.make_current()?;
|
||||
|
||||
unsafe {
|
||||
|
@ -612,7 +612,7 @@ impl Renderer for Gles2Renderer {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn render_texture(&mut self, tex: &Self::Texture, mut matrix: Matrix3<f32>, alpha: f32) -> Result<(), Self::Error> {
|
||||
fn render_texture(&mut self, tex: &Self::TextureId, mut matrix: Matrix3<f32>, alpha: f32) -> Result<(), Self::Error> {
|
||||
self.make_current()?;
|
||||
if self.current_projection.is_none() {
|
||||
return Err(Gles2Error::UnconstraintRenderingOperation);
|
||||
|
|
|
@ -134,27 +134,27 @@ pub trait Texture {
|
|||
|
||||
pub trait Renderer {
|
||||
type Error: Error;
|
||||
type Texture: Texture;
|
||||
type TextureId: Texture;
|
||||
|
||||
#[cfg(feature = "image")]
|
||||
fn import_bitmap<C: std::ops::Deref<Target=[u8]>>(&mut self, image: &image::ImageBuffer<image::Rgba<u8>, C>) -> Result<Self::Texture, Self::Error>;
|
||||
fn import_bitmap<C: std::ops::Deref<Target=[u8]>>(&mut self, image: &image::ImageBuffer<image::Rgba<u8>, C>) -> Result<Self::TextureId, Self::Error>;
|
||||
#[cfg(feature = "wayland_frontend")]
|
||||
fn shm_formats(&self) -> &[wl_shm::Format] {
|
||||
// Mandatory
|
||||
&[wl_shm::Format::Argb8888, wl_shm::Format::Xrgb8888]
|
||||
}
|
||||
#[cfg(feature = "wayland_frontend")]
|
||||
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::TextureId, Self::Error>;
|
||||
#[cfg(feature = "wayland_frontend")]
|
||||
fn import_egl(&mut self, buffer: &EGLBuffer) -> Result<Self::Texture, Self::Error>;
|
||||
fn destroy_texture(&mut self, texture: Self::Texture) -> Result<(), Self::Error>;
|
||||
fn import_egl(&mut self, buffer: &EGLBuffer) -> Result<Self::TextureId, Self::Error>;
|
||||
fn destroy_texture(&mut self, texture: Self::TextureId) -> Result<(), Self::Error>;
|
||||
|
||||
fn begin(&mut self, width: u32, height: u32, transform: Transform) -> Result<(), <Self as Renderer>::Error>;
|
||||
fn finish(&mut self) -> Result<(), SwapBuffersError>;
|
||||
|
||||
fn clear(&mut self, color: [f32; 4]) -> Result<(), Self::Error>;
|
||||
fn render_texture(&mut self, texture: &Self::Texture, matrix: Matrix3<f32>, alpha: f32) -> Result<(), Self::Error>;
|
||||
fn render_texture_at(&mut self, texture: &Self::Texture, pos: (i32, i32), transform: Transform, alpha: f32) -> Result<(), Self::Error> {
|
||||
fn render_texture(&mut self, texture: &Self::TextureId, matrix: Matrix3<f32>, alpha: f32) -> Result<(), Self::Error>;
|
||||
fn render_texture_at(&mut self, texture: &Self::TextureId, pos: (i32, i32), transform: Transform, alpha: f32) -> Result<(), Self::Error> {
|
||||
let mut mat = Matrix3::<f32>::identity();
|
||||
|
||||
// position and scale
|
||||
|
|
|
@ -258,10 +258,10 @@ impl WinitGraphicsBackend {
|
|||
|
||||
impl Renderer for WinitGraphicsBackend {
|
||||
type Error = Gles2Error;
|
||||
type Texture = Gles2Texture;
|
||||
type TextureId = Gles2Texture;
|
||||
|
||||
#[cfg(feature = "image")]
|
||||
fn import_bitmap<C: std::ops::Deref<Target=[u8]>>(&mut self, image: &image::ImageBuffer<image::Rgba<u8>, C>) -> Result<Self::Texture, Self::Error> {
|
||||
fn import_bitmap<C: std::ops::Deref<Target=[u8]>>(&mut self, image: &image::ImageBuffer<image::Rgba<u8>, C>) -> Result<Self::TextureId, Self::Error> {
|
||||
self.renderer.import_bitmap(image)
|
||||
}
|
||||
|
||||
|
@ -271,16 +271,16 @@ impl Renderer for WinitGraphicsBackend {
|
|||
}
|
||||
|
||||
#[cfg(feature = "wayland_frontend")]
|
||||
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::TextureId, Self::Error> {
|
||||
self.renderer.import_shm(buffer)
|
||||
}
|
||||
|
||||
#[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::TextureId, Self::Error> {
|
||||
self.renderer.import_egl(buffer)
|
||||
}
|
||||
|
||||
fn destroy_texture(&mut self, texture: Self::Texture) -> Result<(), Self::Error> {
|
||||
fn destroy_texture(&mut self, texture: Self::TextureId) -> Result<(), Self::Error> {
|
||||
self.renderer.destroy_texture(texture)
|
||||
}
|
||||
|
||||
|
@ -293,7 +293,7 @@ impl Renderer for WinitGraphicsBackend {
|
|||
self.renderer.clear(color)
|
||||
}
|
||||
|
||||
fn render_texture(&mut self, texture: &Self::Texture, matrix: Matrix3<f32>, alpha: f32) -> Result<(), Self::Error> {
|
||||
fn render_texture(&mut self, texture: &Self::TextureId, matrix: Matrix3<f32>, alpha: f32) -> Result<(), Self::Error> {
|
||||
self.renderer.render_texture(texture, matrix, alpha)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue