vtgl

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

Commit: 21f08e5cafd29dae841324424e7debc7f51009c0
Parent: 75749fdbd8cf925b803f0b1452d8c098fd09f87e
Author: Randy Palamar
Date:   Wed, 30 Oct 2024 06:23:19 -0600

apply global reverse video mask in the render shader

Diffstat:
Mfrag_render.glsl | 8+++++---
Mutil.h | 4+++-
Mvtgl.c | 15+++++++--------
3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/frag_render.glsl b/frag_render.glsl @@ -28,6 +28,8 @@ layout(std140, binding = 0) uniform parameters { float underline_min; float underline_max; + + uint reverse_video_mask; }; layout(location = 3) uniform sampler2D u_bitmap_texture; @@ -63,8 +65,8 @@ void main() RenderCell cell = cells[term_size_in_cells.x * cell_index.y + cell_index.x]; uint attr = cell.fg & ATTR_MASK; - vec3 fg = unpackUnorm4x8(cell.fg).wzy; - vec3 bg = unpackUnorm4x8(cell.bg).wzy; + vec3 fg = unpackUnorm4x8(cell.fg ^ reverse_video_mask).wzy; + vec3 bg = unpackUnorm4x8(cell.bg ^ reverse_video_mask).wzy; vec2 glyph_pos = unpack_glyph_position(cell.gpu_glyph) * cell_size; vec2 tex_coord = (glyph_pos + cell_pos) / vec2(textureSize(u_bitmap_texture, 0)); @@ -89,7 +91,7 @@ void main() cell_pos.y >= strike_min && cell_pos.y < strike_max) result = fg; } else { - result = unpackUnorm4x8(margin_colour).wzy; + result = unpackUnorm4x8(margin_colour ^ reverse_video_mask).wzy; } /* NOTE: set to true to see the glyph cache texture */ diff --git a/util.h b/util.h @@ -253,7 +253,9 @@ typedef struct { f32 underline_min; f32 underline_max; - u32 _pad[2]; + u32 reverse_video_mask; + + u32 _pad[1]; } ShaderParameters; typedef struct { diff --git a/vtgl.c b/vtgl.c @@ -26,10 +26,9 @@ normalize_colour(Colour c) } static void -clear_colour(b32 reverse) +clear_colour(void) { Colour c = g_colours.data[g_colours.bgidx]; - if (reverse) c.rgba ^= REVERSE_VIDEO_MASK; v4 cc = normalize_colour(c); glClearColor(cc.r, cc.g, cc.b, cc.a); glClear(GL_COLOR_BUFFER_BIT); @@ -345,10 +344,8 @@ render_framebuffer(Term *t, RenderCell *render_buf) CachedGlyph *cg; rc->gpu_glyph = get_gpu_glyph_index(t->arena_for_frame, &t->gl, &t->fa, c->cp, 0, c->bg & FS_MASK, &cg); - - u32 rmask = (t->gl.mode & WIN_MODE_REVERSE)? REVERSE_VIDEO_MASK : 0; - rc->fg = c->fg ^ rmask; - rc->bg = c->bg ^ rmask; + rc->fg = c->fg; + rc->bg = c->bg; /* TODO: there is probably a better way to do this */ u32 tiles = cg->tile_count; @@ -871,7 +868,7 @@ do_terminal(Term *t, f32 dt) glUseProgram(t->gl.programs[SHADER_RENDER]); glBindFramebuffer(GL_FRAMEBUFFER, t->gl.fb); - clear_colour(t->gl.mode & WIN_MODE_REVERSE); + clear_colour(); if (t->gl.flags & UPDATE_RENDER_BUFFER) { u32 cell_count = t->size.h * t->size.w; @@ -892,6 +889,8 @@ do_terminal(Term *t, f32 dt) sp->underline_min = (0.89 * t->fa.info.h); sp->underline_max = (0.96 * t->fa.info.h); + sp->reverse_video_mask = REVERSE_VIDEO_MASK * !!(t->gl.mode & WIN_MODE_REVERSE); + 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); @@ -907,7 +906,7 @@ do_terminal(Term *t, f32 dt) glBindFramebuffer(GL_FRAMEBUFFER, 0); - clear_colour(t->gl.mode & WIN_MODE_REVERSE); + clear_colour(); glUseProgram(t->gl.programs[SHADER_POST]); glUniform1i(t->gl.post.texslot, t->gl.fb_tex_unit); glUniform1f(t->gl.post.param, param);