autocommit 2022-04-28 19:49:51 CEST
This commit is contained in:
parent
bd63f3f5f1
commit
1242a6c1e1
31 changed files with 707 additions and 64 deletions
|
|
@ -74,6 +74,17 @@ extern "C" {
|
|||
#[allow(dead_code)]
|
||||
pub fn glFlush();
|
||||
|
||||
pub fn glReadnPixels(
|
||||
x: GLint,
|
||||
y: GLint,
|
||||
width: GLsizei,
|
||||
height: GLsizei,
|
||||
format: GLenum,
|
||||
ty: GLenum,
|
||||
buf_size: GLsizei,
|
||||
data: *mut c::c_void,
|
||||
);
|
||||
|
||||
pub fn glGenTextures(n: GLsizei, textures: *mut GLuint);
|
||||
pub fn glDeleteTextures(n: GLsizei, textures: *const GLuint);
|
||||
pub fn glBindTexture(target: GLenum, texture: GLuint);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use {
|
||||
crate::{
|
||||
format::{Format, XRGB8888},
|
||||
rect::Rect,
|
||||
render::{
|
||||
gl::{
|
||||
|
|
@ -10,13 +11,14 @@ use {
|
|||
},
|
||||
},
|
||||
renderer::{context::RenderContext, renderer::Renderer},
|
||||
sys::{glBlendFunc, glFlush, GL_ONE, GL_ONE_MINUS_SRC_ALPHA},
|
||||
RenderResult,
|
||||
sys::{glBlendFunc, glFlush, glReadnPixels, GL_ONE, GL_ONE_MINUS_SRC_ALPHA},
|
||||
RenderResult, Texture,
|
||||
},
|
||||
state::State,
|
||||
tree::Node,
|
||||
},
|
||||
std::{
|
||||
cell::Cell,
|
||||
fmt::{Debug, Formatter},
|
||||
rc::Rc,
|
||||
},
|
||||
|
|
@ -46,6 +48,57 @@ impl Framebuffer {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn copy_texture(&self, state: &State, texture: &Texture, x: i32, y: i32) {
|
||||
let _ = self.ctx.ctx.with_current(|| {
|
||||
unsafe {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, self.gl.fbo);
|
||||
glViewport(0, 0, self.gl.width, self.gl.height);
|
||||
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
let mut renderer = Renderer {
|
||||
ctx: &self.ctx,
|
||||
fb: &self.gl,
|
||||
state,
|
||||
on_output: false,
|
||||
result: &mut RenderResult::default(),
|
||||
};
|
||||
renderer.render_texture(texture, x, y, XRGB8888);
|
||||
unsafe {
|
||||
glFlush();
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
|
||||
pub fn copy_to_shm(
|
||||
&self,
|
||||
x: i32,
|
||||
y: i32,
|
||||
width: i32,
|
||||
height: i32,
|
||||
format: &Format,
|
||||
shm: &[Cell<u8>],
|
||||
) {
|
||||
let y = self.gl.height - y - height;
|
||||
let _ = self.ctx.ctx.with_current(|| {
|
||||
unsafe {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, self.gl.fbo);
|
||||
glViewport(0, 0, self.gl.width, self.gl.height);
|
||||
glReadnPixels(
|
||||
x,
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
format.gl_format as _,
|
||||
format.gl_type as _,
|
||||
shm.len() as _,
|
||||
shm.as_ptr() as _,
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
|
||||
pub fn render(
|
||||
&self,
|
||||
node: &dyn Node,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
use {
|
||||
crate::render::{
|
||||
egl::image::EglImage, gl::texture::GlTexture, RenderContext, RenderError, Texture,
|
||||
egl::image::EglImage,
|
||||
gl::{render_buffer::GlRenderBuffer, texture::GlTexture},
|
||||
Framebuffer, RenderContext, RenderError, Texture,
|
||||
},
|
||||
std::rc::Rc,
|
||||
};
|
||||
|
|
@ -25,4 +27,15 @@ impl Image {
|
|||
gl: GlTexture::import_img(&self.ctx.ctx, &self.gl)?,
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn to_framebuffer(&self) -> Result<Rc<Framebuffer>, RenderError> {
|
||||
self.ctx.ctx.with_current(|| unsafe {
|
||||
let rb = GlRenderBuffer::from_image(&self.gl, &self.ctx.ctx)?;
|
||||
let fb = rb.create_framebuffer()?;
|
||||
Ok(Rc::new(Framebuffer {
|
||||
ctx: self.ctx.clone(),
|
||||
gl: fb,
|
||||
}))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
use {
|
||||
crate::render::{gl::texture::GlTexture, renderer::context::RenderContext},
|
||||
std::rc::Rc,
|
||||
std::{
|
||||
fmt::{Debug, Formatter},
|
||||
rc::Rc,
|
||||
},
|
||||
};
|
||||
|
||||
pub struct Texture {
|
||||
|
|
@ -8,6 +11,12 @@ pub struct Texture {
|
|||
pub(super) gl: GlTexture,
|
||||
}
|
||||
|
||||
impl Debug for Texture {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("Texture").finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
|
||||
impl Texture {
|
||||
pub fn width(&self) -> i32 {
|
||||
self.gl.width
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue