1
0
Fork 0
forked from wry/wry

autocommit 2022-04-28 19:49:51 CEST

This commit is contained in:
Julian Orth 2022-04-28 19:49:51 +02:00
parent bd63f3f5f1
commit 1242a6c1e1
31 changed files with 707 additions and 64 deletions

View file

@ -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,