vtgl

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

Commit: cb9aaf27887bb9bd183b5284bc168032bde0eda3
Parent: fdcd02004956cbc600ecf952a5a19c9fe6a23cdb
Author: Randy Palamar
Date:   Sun,  1 Sep 2024 15:14:50 -0600

support DECSCNM (reverse/normal video mode)

Diffstat:
Mterminal.c | 4++++
Mutil.h | 1+
Mvtgl.c | 25++++++++++++++++---------
3 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/terminal.c b/terminal.c @@ -417,6 +417,10 @@ set_mode(Term *t, CSI *csi, b32 set) if (set) t->gl.mode |= WIN_MODE_APPCURSOR; else t->gl.mode &= ~WIN_MODE_APPCURSOR; break; + case PRIV(5): /* DECSCNM: reverse/normal video mode */ + if (set) t->gl.mode |= WIN_MODE_REVERSE; + else t->gl.mode &= ~WIN_MODE_REVERSE; + break; case PRIV(6): /* DECOM: Cursor Origin Mode */ if (set) t->cursor.state |= CURSOR_ORIGIN; else t->cursor.state &= ~CURSOR_ORIGIN; diff --git a/util.h b/util.h @@ -210,6 +210,7 @@ enum win_mode { WIN_MODE_HIDECURSOR = 1 << 1, WIN_MODE_BRACKPASTE = 1 << 2, WIN_MODE_8BIT = 1 << 3, + WIN_MODE_REVERSE = 1 << 4, }; enum shader_stages { diff --git a/vtgl.c b/vtgl.c @@ -13,6 +13,8 @@ #include "debug.c" #endif +#define REVERSE_VIDEO_MASK (Colour){.r = 0xff, .g = 0xff, .b = 0xff}.rgba + #define TEXTURE_GLYPH_COUNT PUSH_BUFFER_CAP #define X(name) "u_"#name, @@ -31,10 +33,11 @@ normalized_colour(Colour c) } static void -clear_colour(void) +clear_colour(b32 reverse) { - v4 cc = normalized_colour(g_colours.data[g_colours.bgidx]); - //v4 cc = normalized_colour(g_colours.data[5]); + Colour c = g_colours.data[g_colours.bgidx]; + if (reverse) c.rgba ^= REVERSE_VIDEO_MASK; + v4 cc = normalized_colour(c); glClearColor(cc.r, cc.g, cc.b, cc.a); glClear(GL_COLOR_BUFFER_BIT); } @@ -312,10 +315,14 @@ push_cell(RenderPushBuffer *rpb, GLCtx *gl, FontAtlas *fa, Cell c, Rect r, v2 ce else cs.fg.a = 0.5 * 255; } - rpb->texcolours[idx + 0].x = (cs.attr & ATTR_INVERSE)? cs.bg.rgba : cs.fg.rgba; - rpb->texcolours[idx + 0].y = (cs.attr & ATTR_INVERSE)? cs.fg.rgba : cs.bg.rgba; - rpb->texcolours[idx + 1].x = (cs.attr & ATTR_INVERSE)? cs.bg.rgba : cs.fg.rgba; - rpb->texcolours[idx + 1].y = (cs.attr & ATTR_INVERSE)? cs.fg.rgba : cs.bg.rgba; + u32 fg = (cs.attr & ATTR_INVERSE)? cs.bg.rgba : cs.fg.rgba; + u32 bg = (cs.attr & ATTR_INVERSE)? cs.fg.rgba : cs.bg.rgba; + u32 rmask = (gl->mode & WIN_MODE_REVERSE)? REVERSE_VIDEO_MASK : 0; + + rpb->texcolours[idx + 0].x = fg ^ rmask; + rpb->texcolours[idx + 0].y = bg ^ rmask; + rpb->texcolours[idx + 1].x = fg ^ rmask; + rpb->texcolours[idx + 1].y = bg ^ rmask; } static void @@ -819,7 +826,7 @@ do_terminal(Term *t) glBindFramebuffer(GL_FRAMEBUFFER, t->gl.fb); RenderPushBuffer *rpb = alloc(&t->arena_for_frame, RenderPushBuffer, 1); - clear_colour(); + clear_colour(t->gl.mode & WIN_MODE_REVERSE); render_framebuffer(t, rpb); if (0) { @@ -864,7 +871,7 @@ do_terminal(Term *t) glBindFramebuffer(GL_FRAMEBUFFER, 0); - clear_colour(); + clear_colour(t->gl.mode & WIN_MODE_REVERSE); glUseProgram(t->gl.programs[SHADER_POST]); glUniform1i(t->gl.post.texslot, t->gl.fb_tex_unit); glUniform1f(t->gl.post.param, param);