render: add support for more formats
This commit is contained in:
parent
9d78231cac
commit
551dafcce8
13 changed files with 348 additions and 491 deletions
|
|
@ -32,11 +32,14 @@ impl GlRenderBuffer {
|
|||
height: i32,
|
||||
format: &'static Format,
|
||||
) -> Result<Rc<GlRenderBuffer>, RenderError> {
|
||||
let Some(shm_info) = &format.shm_info else {
|
||||
return Err(RenderError::UnsupportedShmFormat(format.name));
|
||||
};
|
||||
let gles = &ctx.dpy.gles;
|
||||
let mut rbo = 0;
|
||||
(gles.glGenRenderbuffers)(1, &mut rbo);
|
||||
(gles.glBindRenderbuffer)(GL_RENDERBUFFER, rbo);
|
||||
(gles.glRenderbufferStorage)(GL_RENDERBUFFER, format.gl_internal_format, width, height);
|
||||
(gles.glRenderbufferStorage)(GL_RENDERBUFFER, shm_info.gl_internal_format, width, height);
|
||||
(gles.glBindRenderbuffer)(GL_RENDERBUFFER, 0);
|
||||
Ok(Rc::new(GlRenderBuffer {
|
||||
_img: None,
|
||||
|
|
|
|||
|
|
@ -73,6 +73,9 @@ impl GlTexture {
|
|||
height: i32,
|
||||
stride: i32,
|
||||
) -> Result<GlTexture, RenderError> {
|
||||
let Some(shm_info) = &format.shm_info else {
|
||||
return Err(RenderError::UnsupportedShmFormat(format.name));
|
||||
};
|
||||
if (stride * height) as usize > data.len() {
|
||||
return Err(RenderError::SmallImageBuffer);
|
||||
}
|
||||
|
|
@ -83,16 +86,16 @@ impl GlTexture {
|
|||
(gles.glBindTexture)(GL_TEXTURE_2D, tex);
|
||||
(gles.glTexParameteri)(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
(gles.glTexParameteri)(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
(gles.glPixelStorei)(GL_UNPACK_ROW_LENGTH_EXT, stride / format.bpp as GLint);
|
||||
(gles.glPixelStorei)(GL_UNPACK_ROW_LENGTH_EXT, stride / shm_info.bpp as GLint);
|
||||
(gles.glTexImage2D)(
|
||||
GL_TEXTURE_2D,
|
||||
0,
|
||||
format.gl_format,
|
||||
shm_info.gl_format,
|
||||
width,
|
||||
height,
|
||||
0,
|
||||
format.gl_format as _,
|
||||
format.gl_type as _,
|
||||
shm_info.gl_format as _,
|
||||
shm_info.gl_type as _,
|
||||
data.as_ptr() as _,
|
||||
);
|
||||
(gles.glPixelStorei)(GL_UNPACK_ROW_LENGTH_EXT, 0);
|
||||
|
|
|
|||
|
|
@ -43,7 +43,10 @@ impl Framebuffer {
|
|||
height: i32,
|
||||
format: &Format,
|
||||
shm: &[Cell<u8>],
|
||||
) {
|
||||
) -> Result<(), RenderError> {
|
||||
let Some(shm_info) = &format.shm_info else {
|
||||
return Err(RenderError::UnsupportedShmFormat(format.name));
|
||||
};
|
||||
let gles = self.ctx.ctx.dpy.gles;
|
||||
let y = self.gl.height - y - height;
|
||||
let _ = self.ctx.ctx.with_current(|| {
|
||||
|
|
@ -55,14 +58,15 @@ impl Framebuffer {
|
|||
y,
|
||||
width,
|
||||
height,
|
||||
format.gl_format as _,
|
||||
format.gl_type as _,
|
||||
shm_info.gl_format as _,
|
||||
shm_info.gl_type as _,
|
||||
shm.len() as _,
|
||||
shm.as_ptr() as _,
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn render(
|
||||
|
|
@ -126,8 +130,9 @@ impl GfxFramebuffer for Framebuffer {
|
|||
format: &'static Format,
|
||||
shm: &[Cell<u8>],
|
||||
) -> Result<(), GfxError> {
|
||||
(*self).copy_to_shm(x, y, width, height, format, shm);
|
||||
Ok(())
|
||||
(*self)
|
||||
.copy_to_shm(x, y, width, height, format, shm)
|
||||
.map_err(|e| e.into())
|
||||
}
|
||||
|
||||
fn format(&self) -> &'static Format {
|
||||
|
|
|
|||
|
|
@ -70,8 +70,8 @@ impl GfxTexture for Texture {
|
|||
shm: &[Cell<u8>],
|
||||
) -> Result<(), GfxError> {
|
||||
self.to_framebuffer()?
|
||||
.copy_to_shm(x, y, width, height, format, shm);
|
||||
Ok(())
|
||||
.copy_to_shm(x, y, width, height, format, shm)
|
||||
.map_err(|e| e.into())
|
||||
}
|
||||
|
||||
fn dmabuf(&self) -> Option<&DmaBuf> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue