vtgl

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

Commit: 726eefc583ae3f8b971a69903f41ff16fe92777e
Parent: 67a4036d64af17d85971d3e9f3f32f130db5c73c
Author: Randy Palamar
Date:   Sat,  6 Jul 2024 08:56:35 -0600

remove oversized secondary framebuffer

Diffstat:
Mmain.c | 6++----
Mutil.h | 9++-------
Mvert_post.glsl | 10+---------
Mvtgl.c | 43+++++++++++++++----------------------------
4 files changed, 20 insertions(+), 48 deletions(-)

diff --git a/main.c b/main.c @@ -153,10 +153,8 @@ init_window(Term *t) glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - /* NOTE: Scale up the size of the Render Framebuffer */ - t->gl.window_size.h *= FB_HEIGHT_SCALE; - - /* NOTE: Generate an oversized intermediate Framebuffer for rendering to */ + /* NOTE: Generate an intermediate framebuffer for rendering to. This + * allows for additional post processing via a second shader stage */ glGenFramebuffers(1, &t->gl.fb); glBindFramebuffer(GL_FRAMEBUFFER, t->gl.fb); diff --git a/util.h b/util.h @@ -27,10 +27,6 @@ #define ISPRINT(c) BETWEEN((c), ' ', '~') -/* NOTE: Framebuffer Height is oversized by this to allow - * for text reflow without cpu side memory reallocations */ -#define FB_HEIGHT_SCALE 2 - /* NOTE: GLFW does not sequentially number keys so switch statement will never be optimized */ #define ENCODE_KEY(action, mod, key) (((action) << 24) | ((mod) << 16) | ((key) & 0xFFFF)) @@ -142,8 +138,7 @@ typedef struct { X(Pmat) \ X(param) \ X(texslot) \ - X(vertscale) \ - X(yoff) + X(vertscale) enum gl_flags { DISCARD_BUFFER = 1 << 0, @@ -179,7 +174,7 @@ typedef struct { } render; union { struct { GL_POST_UNIFORMS }; - i32 uniforms[5]; + i32 uniforms[4]; } post; #undef X diff --git a/vert_post.glsl b/vert_post.glsl @@ -4,7 +4,6 @@ in vec2 position; uniform mat4 u_Pmat; uniform vec2 u_vertscale; -uniform float u_yoff; out VS_OUT { vec2 tex_coord; @@ -15,14 +14,7 @@ void main() vec2 pos = position.xy; vec2 scale = u_vertscale; - mat4 transform = mat4( - scale.x, 0, 0, 0, - 0, scale.y, 0, 0, - 0, 0, 1, 0, - 0, u_yoff, 0, 1 - ); - - gl_Position = u_Pmat * transform * vec4(pos, 0.0, 1.0); + gl_Position = u_Pmat * vec4(pos * scale, 0.0, 1.0); vs_out.tex_coord = pos; } diff --git a/vtgl.c b/vtgl.c @@ -37,22 +37,19 @@ static void resize(GLCtx *gl) { v2 ws = gl->window_size; - f32 render_pmat[4 * 4] = { + + f32 pmat[4 * 4] = { 2.0/ws.w, 0.0, 0.0, -1.0, 0.0, 2.0/ws.h, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, }; - f32 post_pmat[4 * 4] = { - 2.0/ws.w, 0.0, 0.0, -1.0, - 0.0, 4.0/ws.h, 0.0, -1.0, - 0.0, 0.0, -1.0, 0.0, - 0.0, 0.0, 0.0, 1.0, - }; + + glViewport(0, 0, ws.w, ws.h); glUseProgram(gl->programs[SHADER_RENDER]); - glUniformMatrix4fv(gl->render.Pmat, 1, GL_TRUE, render_pmat); + glUniformMatrix4fv(gl->render.Pmat, 1, GL_TRUE, pmat); glUseProgram(gl->programs[SHADER_POST]); - glUniformMatrix4fv(gl->post.Pmat, 1, GL_TRUE, post_pmat); + glUniformMatrix4fv(gl->post.Pmat, 1, GL_TRUE, pmat); } static void @@ -290,7 +287,7 @@ push_line(Term *t, Line *line, v2 start_pos) static void blit_lines(Term *t) { - size line_count = t->size.h / FB_HEIGHT_SCALE - 1; + size line_count = t->size.h - 1; CLAMP(line_count, 0, t->log_lines.filled); v2 cs = get_cell_size(t); /* TODO: handle case where widx has wrapped around */ @@ -314,16 +311,16 @@ static void fb_callback(GLFWwindow *win, i32 w, i32 h) { Term *t = glfwGetWindowUserPointer(win); - t->gl.window_size.w = w; - t->gl.window_size.h = FB_HEIGHT_SCALE * h; + t->gl.window_size.w = w; + t->gl.window_size.h = h; v2 cs = get_cell_size(t); t->size.w = (u32)(w / cs.w); - t->size.h = FB_HEIGHT_SCALE * (u32)(h / cs.h); + t->size.h = (u32)(h / cs.h); /* NOTE: The terminal size still needs to have the correct number * of rows so that terminal programs know how to size themselves. */ - os_set_term_size(t->child, (uv2){.w = t->size.w, .h = t->size.h/FB_HEIGHT_SCALE}, w, h); + os_set_term_size(t->child, (uv2){.w = t->size.w, .h = t->size.h}, w, h); glActiveTexture(GL_TEXTURE0 + t->gl.fb_tex_unit); glBindTexture(GL_TEXTURE_2D, t->gl.fb_tex); @@ -418,7 +415,6 @@ do_terminal(Term *t, Arena a) glUniform1i(t->gl.render.texslot, 0); glBindFramebuffer(GL_FRAMEBUFFER, t->gl.fb); clear_colour(); - glViewport(0, 0, ws.w, ws.h); blit_lines(t); v2 cell_size = get_cell_size(t); @@ -427,17 +423,11 @@ do_terminal(Term *t, Arena a) .y = ws.h - cell_size.h * (t->cursor.row + 1), }; - v2 src_bl = { - .x = 0, - .y = ws.h / FB_HEIGHT_SCALE, - }; - v2 src_tr = { - .x = ws.w, - .y = src_bl.y + ws.h / FB_HEIGHT_SCALE, - }; + v2 src_bl = {0}; + v2 src_tr = { .x = ws.w, .y = src_bl.y + ws.h }; - if (t->cursor.row > t->size.h / FB_HEIGHT_SCALE) { - src_tr.y = cursor_pos.y + ws.h / FB_HEIGHT_SCALE; + if (t->cursor.row > t->size.h) { + src_tr.y = cursor_pos.y + ws.h; src_bl.y = cursor_pos.y; } @@ -466,11 +456,8 @@ do_terminal(Term *t, Arena a) p_scale *= -1.0f; glBindFramebuffer(GL_FRAMEBUFFER, 0); - glViewport(0, 0, ws.w, ws.h/FB_HEIGHT_SCALE); glUseProgram(t->gl.programs[SHADER_POST]); glUniform1i(t->gl.post.texslot, t->gl.fb_tex_unit); - f32 yoff = -MIN(cursor_pos.y, ws.h/FB_HEIGHT_SCALE); - glUniform1f(t->gl.post.yoff, yoff); glUniform1f(t->gl.post.param, param); glUniform2fv(t->gl.post.vertscale, 1, (f32 []){ws.w, ws.h}); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);