@@ -138,10 +138,12 @@ float is_cursor(uint xi, uint y) {
138138}
139139// }}}
140140
141+ struct CellData {
142+ float has_cursor;
143+ uvec2 pos;
144+ } cell_data;
141145
142- void main() {
143-
144- // set cell vertex position {{{
146+ CellData set_vertex_position() {
145147 uint instance_id = uint (gl_InstanceID );
146148 /* The current cell being rendered */
147149 uint r = instance_id / xnum;
@@ -154,8 +156,12 @@ void main() {
154156 vec2 ypos = vec2 (top, top - dy);
155157 uvec2 pos = cell_pos_map[gl_VertexID ];
156158 gl_Position = vec4 (xpos[pos.x], ypos[pos.y], 0 , 1 );
159+ return CellData(is_cursor(c, r), pos);
160+ }
157161
158- // }}}
162+ void main() {
163+
164+ CellData cell_data = set_vertex_position();
159165
160166 // set cell color indices {{{
161167 uvec2 default_colors = uvec2 (default_fg, default_bg);
@@ -164,9 +170,8 @@ void main() {
164170 uint is_inverted = is_reversed + inverted;
165171 int fg_index = fg_index_map[is_inverted];
166172 int bg_index = 1 - fg_index;
167- float cell_has_cursor = is_cursor(c, r);
168173 float is_block_cursor = step (float (cursor_fg_sprite_idx), 0.5 );
169- float cell_has_block_cursor = cell_has_cursor * is_block_cursor;
174+ float cell_has_block_cursor = cell_data.has_cursor * is_block_cursor;
170175 int mark = int (text_attrs >> MARK_SHIFT) & MARK_MASK;
171176 uint has_mark = uint (step (1 , float (mark)));
172177 uint bg_as_uint = resolve_color(colors[bg_index], default_colors[bg_index]);
@@ -179,7 +184,7 @@ void main() {
179184#ifdef NEEDS_FOREGROUND
180185
181186 // The character sprite being rendered
182- sprite_pos = to_sprite_pos(pos, sprite_coords.x, sprite_coords.y, sprite_coords.z & Z_MASK);
187+ sprite_pos = to_sprite_pos(cell_data. pos, sprite_coords.x, sprite_coords.y, sprite_coords.z & Z_MASK);
183188 colored_sprite = float ((sprite_coords.z & COLOR_MASK) >> 14 );
184189
185190 // Foreground
@@ -195,15 +200,15 @@ void main() {
195200 foreground = choose_color(float (is_selected & ONE), selection_color, foreground);
196201 decoration_fg = choose_color(float (is_selected & ONE), selection_color, decoration_fg);
197202 // Underline and strike through (rendered via sprites)
198- underline_pos = choose_color(in_url, to_sprite_pos(pos, url_style, ZERO, ZERO), to_sprite_pos(pos, (text_attrs >> DECORATION_SHIFT) & DECORATION_MASK, ZERO, ZERO));
199- strike_pos = to_sprite_pos(pos, ((text_attrs >> STRIKE_SHIFT) & ONE) * STRIKE_SPRITE_INDEX, ZERO, ZERO);
203+ underline_pos = choose_color(in_url, to_sprite_pos(cell_data. pos, url_style, ZERO, ZERO), to_sprite_pos(cell_data. pos, (text_attrs >> DECORATION_SHIFT) & DECORATION_MASK, ZERO, ZERO));
204+ strike_pos = to_sprite_pos(cell_data. pos, ((text_attrs >> STRIKE_SHIFT) & ONE) * STRIKE_SPRITE_INDEX, ZERO, ZERO);
200205
201206 // Cursor
202207 cursor_color_vec = vec4 (color_to_vec(cursor_bg), 1.0 );
203208 vec3 final_cursor_text_color = color_to_vec(cursor_fg);
204209 foreground = choose_color(cell_has_block_cursor, final_cursor_text_color, foreground);
205210 decoration_fg = choose_color(cell_has_block_cursor, final_cursor_text_color, decoration_fg);
206- cursor_pos = to_sprite_pos(pos, cursor_fg_sprite_idx * uint (cell_has_cursor ), ZERO, ZERO);
211+ cursor_pos = to_sprite_pos(cell_data. pos, cursor_fg_sprite_idx * uint (cell_data.has_cursor ), ZERO, ZERO);
207212#endif
208213 // }}}
209214
0 commit comments