@@ -9,7 +9,7 @@ layout(std140) uniform CellRenderData {
99
1010 uint default_fg, highlight_fg, highlight_bg, cursor_fg, cursor_bg, url_color, url_style, inverted;
1111
12- uint columns, lines, sprites_xnum, sprites_ynum, cursor_fg_sprite_idx , cell_width, cell_height;
12+ uint columns, lines, sprites_xnum, sprites_ynum, cursor_shape , cell_width, cell_height;
1313 uint cursor_x1, cursor_x2, cursor_y1, cursor_y2;
1414 float cursor_opacity, inactive_text_alpha, dim_opacity;
1515
@@ -26,15 +26,22 @@ uniform usampler2D sprite_decorations_map;
2626layout (location= 0 ) in uvec3 colors;
2727layout (location= 1 ) in uvec2 sprite_idx;
2828layout (location= 2 ) in uint is_selected;
29+ // }}}
2930
3031const int fg_index_map[] = int [3 ](0 , 1 , 0 );
3132const uvec2 cell_pos_map[] = uvec2 [4 ](
32- uvec2 (1 , 0 ), // right, top
33- uvec2 (1 , 1 ), // right, bottom
34- uvec2 (0 , 1 ), // left, bottom
35- uvec2 (0 , 0 ) // left, top
33+ uvec2 (1u, 0u), // right, top
34+ uvec2 (1u, 1u), // right, bottom
35+ uvec2 (0u, 1u), // left, bottom
36+ uvec2 (0u, 0u) // left, top
37+ );
38+ const uint cursor_shape_map[] = uint [5 ]( // maps cursor shape to foreground sprite index
39+ 0u, // NO_CURSOR
40+ 0u, // BLOCK (this is rendered as background)
41+ 2u, // BEAM
42+ 3u, // UNDERLINE
43+ 4u // UNFOCUSED
3644);
37- // }}}
3845
3946
4047out vec3 background;
@@ -71,13 +78,7 @@ vec3 color_to_vec(uint c) {
7178 return vec3 (gamma_lut[r], gamma_lut[g], gamma_lut[b]);
7279}
7380
74- float one_if_equal_zero_otherwise(int a, int b) {
75- return 1 .0f - clamp (abs (float (a) - float (b)), 0 .0f, 1 .0f);
76- }
77-
78- float one_if_equal_zero_otherwise(uint a, uint b) {
79- return 1 .0f - clamp (abs (float (a) - float (b)), 0 .0f, 1 .0f);
80- }
81+ #define one_if_equal_zero_otherwise(a, b) (1 .0f - zero_or_one(abs (float (a) - float (b))))
8182
8283
8384uint resolve_color(uint c, uint defval) {
@@ -147,6 +148,7 @@ float is_cursor(uint x, uint y) {
147148struct CellData {
148149 float has_cursor, has_block_cursor;
149150 uvec2 pos;
151+ uint cursor_fg_sprite_idx;
150152} cell_data;
151153
152154CellData set_vertex_position() {
@@ -166,9 +168,9 @@ CellData set_vertex_position() {
166168 sprite_pos = to_sprite_pos(pos, sprite_idx[0 ] & SPRITE_INDEX_MASK);
167169 colored_sprite = float ((sprite_idx[0 ] & SPRITE_COLORED_MASK) >> SPRITE_COLORED_SHIFT);
168170#endif
169- float is_block_cursor = step ( float (cursor_fg_sprite_idx), 0.5 );
171+ float is_block_cursor = one_if_equal_zero_otherwise(cursor_shape, 1u );
170172 float has_cursor = is_cursor(column, row);
171- return CellData(has_cursor, has_cursor * is_block_cursor, pos);
173+ return CellData(has_cursor, has_cursor * is_block_cursor, pos, cursor_shape_map[cursor_shape] );
172174}
173175
174176float background_opacity_for(uint bg, uint colorval, float opacity_if_matched) { // opacity_if_matched if bg == colorval else 1
@@ -277,7 +279,7 @@ void main() {
277279 vec3 final_cursor_text_color = mix (foreground, color_to_vec(cursor_fg), cursor_opacity);
278280 foreground = if_one_then(cell_data.has_block_cursor, final_cursor_text_color, foreground);
279281 decoration_fg = if_one_then(cell_data.has_block_cursor, final_cursor_text_color, decoration_fg);
280- cursor_pos = to_sprite_pos(cell_data.pos, cursor_fg_sprite_idx * uint (cell_data.has_cursor));
282+ cursor_pos = to_sprite_pos(cell_data.pos, cell_data. cursor_fg_sprite_idx * uint (cell_data.has_cursor));
281283#endif
282284 // }}}
283285
0 commit comments