mirror of
https://github.com/wez/wezterm.git
synced 2024-11-10 15:04:32 +03:00
move some of the vertex buffer state into TripleVertexBuffer
This is a stepping stone towards dynamically allocating vertices. refs: #986
This commit is contained in:
parent
38e350e9c8
commit
72d368440f
@ -2,10 +2,10 @@
|
||||
// this warning to its use
|
||||
#![allow(clippy::unneeded_field_pattern)]
|
||||
|
||||
use crate::renderstate::TripleVertexBuffer;
|
||||
use ::window::bitmaps::TextureRect;
|
||||
use ::window::color::LinearRgba;
|
||||
use ::window::glium::buffer::Mapping;
|
||||
use ::window::glium::VertexBuffer;
|
||||
use std::cell::RefMut;
|
||||
|
||||
/// Each cell is composed of two triangles built from 4 vertices.
|
||||
@ -117,12 +117,8 @@ impl<'a> MappedQuads<'a> {
|
||||
}
|
||||
|
||||
impl Quads {
|
||||
pub fn map<'a>(&self, tb: &'a mut RefMut<TripleVertexBuffer>) -> MappedQuads<'a> {
|
||||
let index = tb.index;
|
||||
let mapping = tb.bufs[index]
|
||||
.slice_mut(..)
|
||||
.expect("to map vertex buffer")
|
||||
.map();
|
||||
pub fn map<'a>(&self, bufs: &'a mut RefMut<VertexBuffer<Vertex>>) -> MappedQuads<'a> {
|
||||
let mapping = bufs.slice_mut(..).expect("to map vertex buffer").map();
|
||||
MappedQuads {
|
||||
mapping,
|
||||
quads: self.clone(),
|
||||
|
@ -7,13 +7,38 @@ use ::window::glium::texture::SrgbTexture2d;
|
||||
use ::window::glium::{IndexBuffer, VertexBuffer};
|
||||
use ::window::*;
|
||||
use config::ConfigHandle;
|
||||
use std::cell::RefCell;
|
||||
use std::cell::{Ref, RefCell, RefMut};
|
||||
use std::rc::Rc;
|
||||
use wezterm_font::FontConfiguration;
|
||||
|
||||
pub struct TripleVertexBuffer {
|
||||
pub index: usize,
|
||||
pub bufs: [VertexBuffer<Vertex>; 3],
|
||||
pub index: RefCell<usize>,
|
||||
pub bufs: RefCell<[VertexBuffer<Vertex>; 3]>,
|
||||
pub indices: IndexBuffer<u32>,
|
||||
pub capacity: usize,
|
||||
pub quads: Quads,
|
||||
}
|
||||
|
||||
impl TripleVertexBuffer {
|
||||
pub fn current_vb(&self) -> Ref<VertexBuffer<Vertex>> {
|
||||
let index = *self.index.borrow();
|
||||
let bufs = self.bufs.borrow();
|
||||
Ref::map(bufs, |bufs| &bufs[index])
|
||||
}
|
||||
|
||||
pub fn current_vb_mut(&self) -> RefMut<VertexBuffer<Vertex>> {
|
||||
let index = *self.index.borrow();
|
||||
let bufs = self.bufs.borrow_mut();
|
||||
RefMut::map(bufs, |bufs| &mut bufs[index])
|
||||
}
|
||||
|
||||
pub fn next_index(&self) {
|
||||
let mut index = self.index.borrow_mut();
|
||||
*index += 1;
|
||||
if *index >= 3 {
|
||||
*index = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RenderState {
|
||||
@ -24,9 +49,7 @@ pub struct RenderState {
|
||||
pub line_prog: glium::Program,
|
||||
pub glyph_prog: glium::Program,
|
||||
pub img_prog: glium::Program,
|
||||
pub glyph_vertex_buffer: RefCell<TripleVertexBuffer>,
|
||||
pub glyph_index_buffer: IndexBuffer<u32>,
|
||||
pub quads: Quads,
|
||||
pub glyph_vertex_buffer: TripleVertexBuffer,
|
||||
}
|
||||
|
||||
impl RenderState {
|
||||
@ -55,7 +78,7 @@ impl RenderState {
|
||||
// Last prog outputs srgb for gamma correction
|
||||
let img_prog = Self::compile_prog(&context, true, Self::img_shader)?;
|
||||
|
||||
let (glyph_vertex_buffer, glyph_index_buffer, quads) = Self::compute_vertices(
|
||||
let glyph_vertex_buffer = Self::compute_vertices(
|
||||
config,
|
||||
&context,
|
||||
metrics,
|
||||
@ -71,9 +94,7 @@ impl RenderState {
|
||||
line_prog,
|
||||
glyph_prog,
|
||||
img_prog,
|
||||
glyph_vertex_buffer: RefCell::new(glyph_vertex_buffer),
|
||||
glyph_index_buffer,
|
||||
quads,
|
||||
glyph_vertex_buffer,
|
||||
});
|
||||
}
|
||||
Err(OutOfTextureSpace {
|
||||
@ -125,7 +146,7 @@ impl RenderState {
|
||||
pixel_width: usize,
|
||||
pixel_height: usize,
|
||||
) -> anyhow::Result<()> {
|
||||
let (glyph_vertex_buffer, glyph_index_buffer, quads) = Self::compute_vertices(
|
||||
let glyph_vertex_buffer = Self::compute_vertices(
|
||||
config,
|
||||
&self.context,
|
||||
metrics,
|
||||
@ -133,9 +154,7 @@ impl RenderState {
|
||||
pixel_height as f32,
|
||||
)?;
|
||||
|
||||
*self.glyph_vertex_buffer.borrow_mut() = glyph_vertex_buffer;
|
||||
self.glyph_index_buffer = glyph_index_buffer;
|
||||
self.quads = quads;
|
||||
self.glyph_vertex_buffer = glyph_vertex_buffer;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -219,7 +238,7 @@ impl RenderState {
|
||||
metrics: &RenderMetrics,
|
||||
width: f32,
|
||||
height: f32,
|
||||
) -> anyhow::Result<(TripleVertexBuffer, IndexBuffer<u32>, Quads)> {
|
||||
) -> anyhow::Result<TripleVertexBuffer> {
|
||||
let cell_width = metrics.cell_size.width as f32;
|
||||
let cell_height = metrics.cell_size.height as f32;
|
||||
let mut verts = Vec::new();
|
||||
@ -309,23 +328,22 @@ impl RenderState {
|
||||
quads.scroll_thumb = define_quad(0.0, 0.0, 0.0, 0.0) as usize;
|
||||
|
||||
let buffer = TripleVertexBuffer {
|
||||
index: 0,
|
||||
bufs: [
|
||||
index: RefCell::new(0),
|
||||
bufs: RefCell::new([
|
||||
VertexBuffer::dynamic(context, &verts)?,
|
||||
VertexBuffer::dynamic(context, &verts)?,
|
||||
VertexBuffer::dynamic(context, &verts)?,
|
||||
],
|
||||
};
|
||||
|
||||
Ok((
|
||||
buffer,
|
||||
IndexBuffer::new(
|
||||
]),
|
||||
capacity: verts.len(),
|
||||
indices: IndexBuffer::new(
|
||||
context,
|
||||
glium::index::PrimitiveType::TrianglesList,
|
||||
&indices,
|
||||
)?,
|
||||
quads,
|
||||
))
|
||||
};
|
||||
|
||||
Ok(buffer)
|
||||
}
|
||||
|
||||
pub fn clear_texture_atlas(&mut self, metrics: &RenderMetrics) -> anyhow::Result<()> {
|
||||
|
@ -214,10 +214,11 @@ impl super::TermWindow {
|
||||
}
|
||||
|
||||
let gl_state = self.render_state.as_ref().unwrap();
|
||||
let mut vb = gl_state.glyph_vertex_buffer.borrow_mut();
|
||||
let vb = &gl_state.glyph_vertex_buffer;
|
||||
|
||||
let start = Instant::now();
|
||||
let mut quads = gl_state.quads.map(&mut vb);
|
||||
let mut vb_mut = vb.current_vb_mut();
|
||||
let mut quads = vb.quads.map(&mut vb_mut);
|
||||
log::trace!("quad map elapsed {:?}", start.elapsed());
|
||||
metrics::histogram!("quad.map", start.elapsed());
|
||||
|
||||
@ -409,7 +410,7 @@ impl super::TermWindow {
|
||||
|
||||
pub fn call_draw(&mut self, frame: &mut glium::Frame) -> anyhow::Result<()> {
|
||||
let gl_state = self.render_state.as_ref().unwrap();
|
||||
let mut vb = gl_state.glyph_vertex_buffer.borrow_mut();
|
||||
let vb = &gl_state.glyph_vertex_buffer;
|
||||
|
||||
let tex = gl_state.glyph_cache.borrow().atlas.texture();
|
||||
let projection = euclid::Transform3D::<f32, f32, f32>::ortho(
|
||||
@ -460,8 +461,8 @@ impl super::TermWindow {
|
||||
|
||||
// Pass 1: Draw backgrounds
|
||||
frame.draw(
|
||||
&vb.bufs[vb.index],
|
||||
&gl_state.glyph_index_buffer,
|
||||
&*vb.current_vb(),
|
||||
&vb.indices,
|
||||
&gl_state.background_prog,
|
||||
&uniform! {
|
||||
projection: projection,
|
||||
@ -473,8 +474,8 @@ impl super::TermWindow {
|
||||
|
||||
// Pass 2: strikethrough and underline
|
||||
frame.draw(
|
||||
&vb.bufs[vb.index],
|
||||
&gl_state.glyph_index_buffer,
|
||||
&*vb.current_vb(),
|
||||
&vb.indices,
|
||||
&gl_state.line_prog,
|
||||
&uniform! {
|
||||
projection: projection,
|
||||
@ -527,8 +528,8 @@ impl super::TermWindow {
|
||||
|
||||
// Pass 3: Draw glyphs
|
||||
frame.draw(
|
||||
&vb.bufs[vb.index],
|
||||
&gl_state.glyph_index_buffer,
|
||||
&*vb.current_vb(),
|
||||
&vb.indices,
|
||||
&gl_state.glyph_prog,
|
||||
&uniform! {
|
||||
projection: projection,
|
||||
@ -541,8 +542,8 @@ impl super::TermWindow {
|
||||
|
||||
// Pass 4: Draw image attachments
|
||||
frame.draw(
|
||||
&vb.bufs[vb.index],
|
||||
&gl_state.glyph_index_buffer,
|
||||
&*vb.current_vb(),
|
||||
&vb.indices,
|
||||
&gl_state.img_prog,
|
||||
&uniform! {
|
||||
projection: projection,
|
||||
@ -553,10 +554,7 @@ impl super::TermWindow {
|
||||
&blend_but_set_alpha_to_one,
|
||||
)?;
|
||||
|
||||
vb.index += 1;
|
||||
if vb.index >= 3 {
|
||||
vb.index = 0;
|
||||
}
|
||||
vb.next_index();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -567,8 +565,9 @@ impl super::TermWindow {
|
||||
pane: &Rc<dyn Pane>,
|
||||
) -> anyhow::Result<()> {
|
||||
let gl_state = self.render_state.as_ref().unwrap();
|
||||
let mut vb = gl_state.glyph_vertex_buffer.borrow_mut();
|
||||
let mut quads = gl_state.quads.map(&mut vb);
|
||||
let vb = &gl_state.glyph_vertex_buffer;
|
||||
let mut vb_mut = vb.current_vb_mut();
|
||||
let mut quads = vb.quads.map(&mut vb_mut);
|
||||
let config = &self.config;
|
||||
let block = BlockKey::from_char(if split.direction == SplitDirection::Horizontal {
|
||||
'\u{2502}'
|
||||
|
Loading…
Reference in New Issue
Block a user