Skip to content

Commit 152c31e

Browse files
committed
Move more code into position function
1 parent eb21966 commit 152c31e

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

kitty/cell_vertex.glsl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ float is_cursor(uint xi, uint y) {
122122
// }}}
123123

124124
struct CellData {
125-
float has_cursor;
125+
float has_cursor, has_block_cursor;
126126
uvec2 pos;
127127
} cell_data;
128128

@@ -139,7 +139,14 @@ CellData set_vertex_position() {
139139
vec2 ypos = vec2(top, top - dy);
140140
uvec2 pos = cell_pos_map[gl_VertexID];
141141
gl_Position = vec4(xpos[pos.x], ypos[pos.y], 0, 1);
142-
return CellData(is_cursor(c, r), pos);
142+
#ifdef NEEDS_FOREGROUND
143+
// The character sprite being rendered
144+
sprite_pos = to_sprite_pos(pos, sprite_coords.x, sprite_coords.y, sprite_coords.z & Z_MASK);
145+
colored_sprite = float((sprite_coords.z & COLOR_MASK) >> 14);
146+
#endif
147+
float is_block_cursor = step(float(cursor_fg_sprite_idx), 0.5);
148+
float has_cursor = is_cursor(c, r);
149+
return CellData(has_cursor, has_cursor * is_block_cursor, pos);
143150
}
144151

145152
void main() {
@@ -153,8 +160,6 @@ void main() {
153160
uint is_inverted = is_reversed + inverted;
154161
int fg_index = fg_index_map[is_inverted];
155162
int bg_index = 1 - fg_index;
156-
float is_block_cursor = step(float(cursor_fg_sprite_idx), 0.5);
157-
float cell_has_block_cursor = cell_data.has_cursor * is_block_cursor;
158163
int mark = int(text_attrs >> MARK_SHIFT) & MARK_MASK;
159164
uint has_mark = uint(step(1, float(mark)));
160165
uint bg_as_uint = resolve_color(colors[bg_index], default_colors[bg_index]);
@@ -166,9 +171,6 @@ void main() {
166171
// Foreground {{{
167172
#ifdef NEEDS_FOREGROUND
168173

169-
// The character sprite being rendered
170-
sprite_pos = to_sprite_pos(cell_data.pos, sprite_coords.x, sprite_coords.y, sprite_coords.z & Z_MASK);
171-
colored_sprite = float((sprite_coords.z & COLOR_MASK) >> 14);
172174

173175
// Foreground
174176
fg_as_uint = has_mark * color_table[NUM_COLORS + MARK_MASK + 1 + mark] + (ONE - has_mark) * fg_as_uint;
@@ -189,8 +191,8 @@ void main() {
189191
// Cursor
190192
cursor_color_vec = vec4(color_to_vec(cursor_bg), 1.0);
191193
vec3 final_cursor_text_color = color_to_vec(cursor_fg);
192-
foreground = choose_color(cell_has_block_cursor, final_cursor_text_color, foreground);
193-
decoration_fg = choose_color(cell_has_block_cursor, final_cursor_text_color, decoration_fg);
194+
foreground = choose_color(cell_data.has_block_cursor, final_cursor_text_color, foreground);
195+
decoration_fg = choose_color(cell_data.has_block_cursor, final_cursor_text_color, decoration_fg);
194196
cursor_pos = to_sprite_pos(cell_data.pos, cursor_fg_sprite_idx * uint(cell_data.has_cursor), ZERO, ZERO);
195197
#endif
196198
// }}}
@@ -212,7 +214,7 @@ void main() {
212214
// Which means they must not have a block cursor or a selection or reverse video
213215
// On other cells it should be 1. For the SPECIAL program it should be 1 on cells with
214216
// selections/block cursor and 0 everywhere else.
215-
float is_special_cell = cell_has_block_cursor + float(is_selected & ONE);
217+
float is_special_cell = cell_data.has_block_cursor + float(is_selected & ONE);
216218
#if (PHASE != PHASE_SPECIAL)
217219
is_special_cell += cell_has_non_default_bg + float(is_reversed);
218220
#endif
@@ -226,9 +228,9 @@ void main() {
226228
#if (PHASE == PHASE_SPECIAL) || (PHASE == PHASE_BOTH)
227229
// Selection and cursor
228230
bg = choose_color(float(is_selected & ONE), choose_color(use_cell_for_selection_bg, color_to_vec(fg_as_uint), color_to_vec(highlight_bg)), bg);
229-
background = choose_color(cell_has_block_cursor, color_to_vec(cursor_bg), bg);
231+
background = choose_color(cell_data.has_block_cursor, color_to_vec(cursor_bg), bg);
230232
#if !defined(TRANSPARENT) && (PHASE == PHASE_SPECIAL)
231-
float is_special_cell = cell_has_block_cursor + float(is_selected & ONE);
233+
float is_special_cell = cell_data.has_block_cursor + float(is_selected & ONE);
232234
bg_alpha = step(0.5, is_special_cell);
233235
#endif
234236
#endif

0 commit comments

Comments
 (0)