aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-06-02 20:27:07 -0700
committerJoe Wilm <joe@jwilm.com>2016-06-02 20:27:07 -0700
commit2f98871b029eef0631e8e3a70928b8d219940a02 (patch)
tree91bfc1e4d828c3f764e9569ab805e2945aceb165 /src/main.rs
parenta8024f64c78941ac2e36ef07ed545a176c2d5c12 (diff)
downloadr-alacritty-2f98871b029eef0631e8e3a70928b8d219940a02.tar.gz
r-alacritty-2f98871b029eef0631e8e3a70928b8d219940a02.tar.bz2
r-alacritty-2f98871b029eef0631e8e3a70928b8d219940a02.zip
Refactor renderer functions out of main.rs
This moves the rendering logic to draw the grid, to draw strings, and to draw the cursor into the renderere module. In addition to being an organizational improvement, this also allowed for some optimizations managing OpenGL state. Render times for a moderate screen of text dropped from ~10ms to ~4ms.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs65
1 files changed, 19 insertions, 46 deletions
diff --git a/src/main.rs b/src/main.rs
index f13784bc..9e9a6e86 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -55,23 +55,12 @@ static INIT_LIST: &'static str = "abcdefghijklmnopqrstuvwxyz\
type GlyphCache = HashMap<char, renderer::Glyph>;
-/// Render a string in a predefined location. Used for printing render time for profiling and
-/// optimization.
-fn render_string(s: &str,
- renderer: &QuadRenderer,
- glyph_cache: &GlyphCache,
- cell_width: u32,
- color: &Rgb)
-{
- let (mut x, mut y) = (200f32, 20f32);
-
- for c in s.chars() {
- if let Some(glyph) = glyph_cache.get(&c) {
- renderer.render(glyph, x, y, color);
- }
-
- x += cell_width as f32 + 2f32;
- }
+struct TermProps {
+ cell_width: f32,
+ sep_x: f32,
+ cell_height: f32,
+ sep_y: f32,
+ height: f32,
}
fn main() {
@@ -135,7 +124,7 @@ fn main() {
}
});
- let renderer = QuadRenderer::new(width, height);
+ let mut renderer = QuadRenderer::new(width, height);
let mut terminal = Term::new(tty, grid);
let mut meter = Meter::new();
@@ -191,43 +180,27 @@ fn main() {
{
let _sampler = meter.sampler();
+ let props = TermProps {
+ cell_width: cell_width as f32,
+ sep_x: sep_x as f32,
+ cell_height: cell_height as f32,
+ sep_y: sep_y as f32,
+ height: height as f32,
+ };
+
// Draw the grid
- let grid = terminal.grid();
- for i in 0..grid.rows() {
- let row = &grid[i];
- for j in 0..row.cols() {
- let cell = &row[j];
- if cell.c != ' ' {
- if let Some(glyph) = glyph_cache.get(&cell.c) {
- let y = (cell_height as f32 + sep_y as f32) * (i as f32);
- let x = (cell_width as f32 + sep_x as f32) * (j as f32);
-
- let y_inverted = (height as f32) - y - (cell_height as f32);
-
- renderer.render(glyph, x, y_inverted, &cell.fg);
- }
- }
- }
- }
+ renderer.render_grid(terminal.grid(), &glyph_cache, &props);
// Also draw the cursor
- if let Some(glyph) = glyph_cache.get(&term::CURSOR_SHAPE) {
- let y = (cell_height as f32 + sep_y as f32) * (terminal.cursor_y() as f32);
- let x = (cell_width as f32 + sep_x as f32) * (terminal.cursor_x() as f32);
-
- let y_inverted = (height as f32) - y - (cell_height as f32);
-
- renderer.render(glyph, x, y_inverted, &term::DEFAULT_FG);
- }
+ renderer.render_cursor(terminal.cursor(), &glyph_cache, &props);
}
+ // Draw render timer
let timing = format!("{:.3} usec", meter.average());
let color = Rgb { r: 0xd5, g: 0x4e, b: 0x53 };
- render_string(&timing[..], &renderer, &glyph_cache, cell_width, &color);
+ renderer.render_string(&timing[..], &glyph_cache, cell_width, &color);
window.swap_buffers().unwrap();
-
- // ::std::thread::sleep(::std::time::Duration::from_millis(17));
}
}