vtgl

terminal emulator implemented in OpenGL
git clone anongit@rnpnr.xyz:vtgl.git
Log | Files | Refs | Feed | LICENSE

Commit: 2800fa1a5f6cd085e8fee0ac45a1b0967dea22a9
Parent: e1ea2736fea8fc6257af53e5fcef71d0c8d5841d
Author: Randy Palamar
Date:   Mon, 21 Oct 2024 09:07:36 -0600

only refill/upload ssbo when the contents would change

Diffstat:
Mutil.h | 1+
Mvtgl.c | 32++++++++++++++++++--------------
2 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/util.h b/util.h @@ -197,6 +197,7 @@ enum gl_flags { NEEDS_RESIZE = 1 << 0, NEEDS_REFILL = 1 << 1, NEEDS_FULL_REFILL = 1 << 2, + UPDATE_RENDER_BUFFER = 1 << 3, UPDATE_RENDER_UNIFORMS = 1 << 27, UPDATE_POST_UNIFORMS = 1 << 28, diff --git a/vtgl.c b/vtgl.c @@ -398,6 +398,7 @@ update_selection(Term *t) } } sel->range = normalize_range(sel->range); + t->gl.flags |= UPDATE_RENDER_BUFFER; } KEYBIND_FN(copy) @@ -763,15 +764,27 @@ do_terminal(Term *t, f32 dt) t->gl.flags |= NEEDS_REFILL; } - if (t->gl.flags & (NEEDS_REFILL|NEEDS_FULL_REFILL)) + if (t->gl.flags & (NEEDS_REFILL|NEEDS_FULL_REFILL)) { blit_lines(t, t->arena_for_frame, parsed_lines); + t->gl.flags |= UPDATE_RENDER_BUFFER; + } update_selection(t); - u32 cell_count = t->size.h * t->size.w; - /* NOTE: this must be done every frame since we have time varying parameters */ - RenderCell *render_buf = alloc(&t->arena_for_frame, RenderCell, cell_count); - render_framebuffer(t, render_buf); + glUseProgram(t->gl.programs[SHADER_RENDER]); + glBindFramebuffer(GL_FRAMEBUFFER, t->gl.fb); + clear_colour(t->gl.mode & WIN_MODE_REVERSE); + + if (t->gl.flags & UPDATE_RENDER_BUFFER) { + u32 cell_count = t->size.h * t->size.w; + RenderCell *render_buf = alloc(&t->arena_for_frame, RenderCell, cell_count); + render_framebuffer(t, render_buf); + + glBindBuffer(GL_SHADER_STORAGE_BUFFER, t->gl.render_shader_ssbo); + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, t->gl.render_shader_ssbo); + glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, cell_count * sizeof(*render_buf), render_buf); + t->gl.flags &= ~UPDATE_RENDER_BUFFER; + } ShaderParameters *sp = &t->gl.shader_parameters; sp->blink_parameter += 2 * PI * g_blink_speed * dt_for_frame; @@ -781,21 +794,12 @@ do_terminal(Term *t, f32 dt) sp->underline_min = (u32)(0.94 * t->fa.info.h); sp->underline_max = t->fa.info.h; - glUseProgram(t->gl.programs[SHADER_RENDER]); - glBindFramebuffer(GL_FRAMEBUFFER, t->gl.fb); - - clear_colour(t->gl.mode & WIN_MODE_REVERSE); - glUniform2fv(t->gl.render.vertscale, 1, t->gl.window_size.E); glBindBuffer(GL_UNIFORM_BUFFER, t->gl.render_shader_ubo); glBindBufferBase(GL_UNIFORM_BUFFER, 0, t->gl.render_shader_ubo); glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(*sp), sp); - glBindBuffer(GL_SHADER_STORAGE_BUFFER, t->gl.render_shader_ssbo); - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, t->gl.render_shader_ssbo); - glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, cell_count * sizeof(*render_buf), render_buf); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); static f32 param = 0;