1
0
Fork 0
forked from wry/wry

autocommit 2022-01-31 23:45:42 CET

This commit is contained in:
Julian Orth 2022-01-31 23:45:42 +01:00
parent 865d5f295d
commit f2117256b9
33 changed files with 784 additions and 178 deletions

View file

@ -18,6 +18,24 @@ use std::ffi::CString;
use std::rc::Rc;
use uapi::ustr;
pub(super) struct TexProg {
pub(super) prog: GlProgram,
pub(super) pos: GLint,
pub(super) texcoord: GLint,
pub(super) tex: GLint,
}
impl TexProg {
unsafe fn from(prog: GlProgram) -> Self {
Self {
pos: prog.get_attrib_location(ustr!("pos")),
texcoord: prog.get_attrib_location(ustr!("texcoord")),
tex: prog.get_uniform_location(ustr!("tex")),
prog,
}
}
}
pub struct RenderContext {
pub(super) ctx: Rc<EglContext>,
@ -25,10 +43,8 @@ pub struct RenderContext {
pub(super) renderdoc: Option<RefCell<RenderDoc<V100>>>,
pub(super) tex_prog: GlProgram,
pub(super) tex_prog_pos: GLint,
pub(super) tex_prog_texcoord: GLint,
pub(super) tex_prog_tex: GLint,
pub(super) tex_prog: TexProg,
pub(super) tex_alpha_prog: TexProg,
pub(super) fill_prog: GlProgram,
pub(super) fill_prog_pos: GLint,
@ -60,6 +76,11 @@ impl RenderContext {
include_str!("../shaders/tex.vert.glsl"),
include_str!("../shaders/tex.frag.glsl"),
)?;
let tex_alpha_prog = GlProgram::from_shaders(
ctx,
include_str!("../shaders/tex.vert.glsl"),
include_str!("../shaders/tex-alpha.frag.glsl"),
)?;
let fill_prog = GlProgram::from_shaders(
ctx,
include_str!("../shaders/fill.vert.glsl"),
@ -70,10 +91,8 @@ impl RenderContext {
render_node: node.clone(),
tex_prog_pos: tex_prog.get_attrib_location(ustr!("pos")),
tex_prog_texcoord: tex_prog.get_attrib_location(ustr!("texcoord")),
tex_prog_tex: tex_prog.get_uniform_location(ustr!("tex")),
tex_prog,
tex_prog: TexProg::from(tex_prog),
tex_alpha_prog: TexProg::from(tex_alpha_prog),
fill_prog_pos: fill_prog.get_attrib_location(ustr!("pos")),
fill_prog_color: fill_prog.get_uniform_location(ustr!("color")),

View file

@ -7,6 +7,9 @@ use crate::render::renderer::renderer::Renderer;
use crate::tree::Node;
use std::ptr;
use std::rc::Rc;
use crate::rect::Rect;
use crate::render::sys::{GL_ONE, GL_ONE_MINUS_SRC_ALPHA, glBlendFunc};
use crate::State;
pub struct Framebuffer {
pub(super) ctx: Rc<RenderContext>,
@ -14,7 +17,7 @@ pub struct Framebuffer {
}
impl Framebuffer {
pub fn render(&self, node: &dyn Node) {
pub fn render(&self, node: &dyn Node, state: &State, cursor_rect: Option<Rect>) {
let _ = self.ctx.ctx.with_current(|| {
if let Some(rd) = &self.ctx.renderdoc {
rd.borrow_mut()
@ -25,12 +28,25 @@ impl Framebuffer {
glViewport(0, 0, self.gl.width, self.gl.height);
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
let mut renderer = Renderer {
ctx: &self.ctx,
fb: &self.gl,
};
node.render(&mut renderer, 0, 0);
if let Some(rect) = cursor_rect {
let seats = state.globals.lock_seats();
for seat in seats.values() {
if let Some(cursor) = seat.get_cursor() {
let extents = cursor.extents();
if extents.intersects(&rect) {
let (x, y) = rect.translate(extents.x1(), extents.y1());
renderer.render_surface(cursor.surface(), x, y);
}
}
}
}
if let Some(rd) = &self.ctx.renderdoc {
rd.borrow_mut().end_frame_capture(ptr::null(), ptr::null());
}

View file

@ -17,6 +17,7 @@ use crate::tree::{
use std::ops::Deref;
use std::rc::Rc;
use std::slice;
use crate::render::sys::{GL_BLEND, glDisable, glEnable};
const NON_COLOR: (f32, f32, f32) = (0.2, 0.2, 0.2);
const CHILD_COLOR: (f32, f32, f32) = (0.8, 0.8, 0.8);
@ -47,7 +48,7 @@ impl Renderer<'_> {
self.render_container(&node, x, y)
}
for stacked in workspace.stacked.iter() {
let pos = stacked.absolute_position();
let (pos, _) = stacked.absolute_position();
stacked.render(self, pos.x1(), pos.y1());
}
}
@ -186,7 +187,9 @@ impl Renderer<'_> {
let buffer = match surface.buffer.get() {
Some(b) => b,
_ => {
log::warn!("surface has no buffer attached");
if !surface.is_cursor() {
log::warn!("surface has no buffer attached");
}
return;
}
};
@ -226,9 +229,20 @@ impl Renderer<'_> {
glBindTexture(GL_TEXTURE_2D, texture.gl.tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glUseProgram(self.ctx.tex_prog.prog);
let prog = match buffer.format.has_alpha {
true => {
glEnable(GL_BLEND);
&self.ctx.tex_alpha_prog
},
false => {
glDisable(GL_BLEND);
&self.ctx.tex_prog
},
};
glUniform1i(self.ctx.tex_prog_tex, 0);
glUseProgram(prog.prog.prog);
glUniform1i(prog.tex, 0);
let texcoord: [f32; 8] = [1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0];
@ -248,7 +262,7 @@ impl Renderer<'_> {
];
glVertexAttribPointer(
self.ctx.tex_prog_texcoord as _,
prog.texcoord as _,
2,
GL_FLOAT,
GL_FALSE,
@ -256,7 +270,7 @@ impl Renderer<'_> {
texcoord.as_ptr() as _,
);
glVertexAttribPointer(
self.ctx.tex_prog_pos as _,
prog.pos as _,
2,
GL_FLOAT,
GL_FALSE,
@ -264,13 +278,13 @@ impl Renderer<'_> {
pos.as_ptr() as _,
);
glEnableVertexAttribArray(self.ctx.tex_prog_texcoord as _);
glEnableVertexAttribArray(self.ctx.tex_prog_pos as _);
glEnableVertexAttribArray(prog.texcoord as _);
glEnableVertexAttribArray(prog.pos as _);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableVertexAttribArray(self.ctx.tex_prog_texcoord as _);
glDisableVertexAttribArray(self.ctx.tex_prog_pos as _);
glDisableVertexAttribArray(prog.texcoord as _);
glDisableVertexAttribArray(prog.pos as _);
glBindTexture(GL_TEXTURE_2D, 0);
}