diff --git a/kitty/cell_vertex.glsl b/kitty/cell_vertex.glsl index 8c0ab4a71..81eba7676 100644 --- a/kitty/cell_vertex.glsl +++ b/kitty/cell_vertex.glsl @@ -1,9 +1,8 @@ #version GLSL_VERSION -uniform uvec4 dimensions; // xnum, ynum, cursor.x, cursor.y uniform float geom[6]; -uniform ivec2 color_indices; // which color to use as fg and which as bg -uniform uint default_colors[6]; // The default colors -uniform uvec4 url_range; // The range for the currently highlighted URL (start_x, end_x, start_y, end_y) +uniform ivec2 color_indices; +uniform uint default_colors[6]; +uniform uint dimensions[8]; uniform ColorTable { uint color_table[256]; // The color table }; @@ -15,8 +14,13 @@ uniform ColorTable { #define highlight_bg default_colors[3] #define cursor_color default_colors[4] #define url_color default_colors[5] +#define xnum dimensions[0] +#define ynum dimensions[1] #define cursor_x dimensions[2] #define cursor_y dimensions[3] +#define url_y dimensions[5] +#define url_xl dimensions[4] +#define url_xr dimensions[6] #define sprite_dx geom[4] #define sprite_dy geom[5] @@ -90,8 +94,8 @@ vec3 mix_vecs(float q, vec3 a, vec3 b) { return q * a + (1.0 - q) * b; } -float in_range(uvec4 range, uint x, uint y) { - if (range[2] == y && range[0] <= x && x <= range[1]) return 1.0; +float in_range(uint x, uint y) { + if (url_y == y && url_xl <= x && x <= url_xr) return 1.0; return 0.0; } @@ -103,8 +107,8 @@ float is_cursor(uint x, uint y) { void main() { uint instance_id = uint(gl_InstanceID); // The current cell being rendered - uint r = instance_id / dimensions.x; - uint c = instance_id - r * dimensions.x; + uint r = instance_id / xnum; + uint c = instance_id - r * xnum; // The position of this vertex, at a corner of the cell float left = xstart + c * dx; @@ -129,7 +133,7 @@ void main() { background = cursor * color_to_vec(cursor_color) + (1.0 - cursor) * background; // Underline and strike through (rendered via sprites) - float in_url = in_range(url_range, c, r); + float in_url = in_range(c, r); decoration_fg = mix_vecs(in_url, color_to_vec(url_color), to_color(colors[2], resolved_fg)); underline_pos = mix_vecs(in_url, to_sprite_pos(pos, TWO, ZERO, ZERO), to_sprite_pos(pos, (text_attrs >> 2) & DECORATION_MASK, ZERO, ZERO)); strike_pos = to_sprite_pos(pos, ((text_attrs >> 7) & STRIKE_MASK) * THREE, ZERO, ZERO); diff --git a/kitty/screen.c b/kitty/screen.c index 368a3c0d1..ea4b2df5d 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -1196,11 +1196,11 @@ screen_apply_selection(Screen *self, void *address, size_t size) { } void -screen_url_range(Screen *self, unsigned int *start_x, unsigned int *start_y, unsigned int *end_x, unsigned int *end_y) { +screen_url_range(Screen *self, uint32_t *data) { SelectionBoundary start, end; selection_limits_(url_range, &start, &end); - if (is_selection_empty(self, start.x, start.y, end.x, end.y)) { *start_y = self->lines; *end_y = self->lines; *start_x = self->columns; *end_x = self->columns; } - else { *start_x = start.x; *start_y = start.y; *end_x = end.x; *end_y = end.y; } + if (is_selection_empty(self, start.x, start.y, end.x, end.y)) { *(data + 1) = self->lines; *(data + 3) = self->lines; *data = self->columns; *(data + 2) = self->columns; } + else { *data = start.x; *(data+1) = start.y; *(data + 2) = end.x; *(data + 3) = end.y; } } // }}} diff --git a/kitty/screen.h b/kitty/screen.h index 32200b691..e6d11b7a9 100644 --- a/kitty/screen.h +++ b/kitty/screen.h @@ -73,7 +73,7 @@ void screen_update_selection(Screen *self, index_type x, index_type y, bool ende bool screen_history_scroll(Screen *self, int amt, bool upwards); Line* screen_visual_line(Screen *self, index_type y); unsigned long screen_current_char_width(Screen *self); -void screen_url_range(Screen *self, unsigned int *start_x, unsigned int *start_y, unsigned int *limit_x, unsigned int *limit_y); +void screen_url_range(Screen *self, uint32_t *); void screen_mark_url(Screen *self, index_type start_x, index_type start_y, index_type end_x, index_type end_y); #define DECLARE_CH_SCREEN_HANDLER(name) void screen_##name(Screen *screen); DECLARE_CH_SCREEN_HANDLER(bell) diff --git a/kitty/shaders.c b/kitty/shaders.c index 8e4b76d36..d6fe43845 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -552,7 +552,7 @@ destroy_sprite_map() { // Cell {{{ -enum CellUniforms { CELL_dimensions, CELL_default_colors, CELL_color_indices, CELL_sprites, CELL_geom, CELL_url_range, CELL_color_table, NUM_CELL_UNIFORMS }; +enum CellUniforms { CELL_dimensions, CELL_default_colors, CELL_color_indices, CELL_sprites, CELL_geom, CELL_color_table, NUM_CELL_UNIFORMS }; static GLint cell_uniform_locations[NUM_CELL_UNIFORMS] = {0}; static GLint cell_uniform_indices[NUM_CELL_UNIFORMS] = {0}; static GLint cell_color_table_stride = 0, cell_color_table_offset = 0, cell_color_table_size = 0, cell_color_table_block_index = 0; @@ -569,7 +569,6 @@ init_cell_program() { else SET_LOC(color_indices) else SET_LOC(sprites) else SET_LOC(geom) - else SET_LOC(url_range) else { fatal("Unknown uniform in cell program: %s", p->uniforms[i].name); } } if (left) { fatal("Left over uniforms in cell program"); } @@ -629,7 +628,10 @@ draw_cells_impl(ssize_t vao_idx, GLfloat xstart, GLfloat ystart, GLfloat dx, GLf #define UL(name) cell_uniform_locations[CELL_##name] bind_program(CELL_PROGRAM); bind_vao_uniform_buffer(vao_idx, 2, cell_color_table_block_index); - glUniform4ui(UL(dimensions), screen->columns, screen->lines, cx, cy); check_gl(); + static GLuint dimensions[8]; + dimensions[0] = screen->columns; dimensions[1] = screen->lines; dimensions[2] = cx; dimensions[3] = cy; + screen_url_range(screen, dimensions + 4); + glUniform1uiv(UL(dimensions), sizeof(dimensions) / sizeof(dimensions[0]), dimensions); static GLfloat geom[6]; unsigned int x, y, z; sprite_map_current_layout(&x, &y, &z); @@ -641,9 +643,6 @@ draw_cells_impl(ssize_t vao_idx, GLfloat xstart, GLfloat ystart, GLfloat dx, GLf colors[0] = COLOR(default_fg); colors[1] = COLOR(default_bg); colors[2] = COLOR(highlight_fg); colors[3] = COLOR(highlight_bg); colors[4] = cursor->color; colors[5] = OPT(url_color); glUniform1uiv(UL(default_colors), sizeof(colors)/sizeof(colors[0]), colors); check_gl(); #undef COLOR - GLuint start_x, start_y, end_x, end_y; - screen_url_range(screen, &start_x, &start_y, &end_x, &end_y); - glUniform4ui(UL(url_range), start_x, end_x, start_y, end_y); check_gl(); glUniform1i(UL(sprites), sprite_map_unit); check_gl(); bind_vertex_array(vao_idx); glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, screen->lines * screen->columns); check_gl();