Skip to content

Commit eb21966

Browse files
committed
Speed up rendering in the case of transparent window + non-underlaid images
Do single pass rendering for these as well.
1 parent 1798c52 commit eb21966

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

kitty/cell_fragment.glsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ vec4 vec4_premul(vec4 rgba) {
4545
* are images that are below the foreground. Single pass rendering has PHASE=PHASE_BOTH. Otherwise, there
4646
* are three passes, PHASE=PHASE_BACKGROUND, PHASE=PHASE_SPECIAL, PHASE=PHASE_FOREGROUND.
4747
* 1) Single pass -- this path is used when there are either no images, or all images are
48-
* drawn on top of text and the background is opaque. In this case, there is a single pass,
48+
* drawn on top of text. In this case, there is a single pass,
4949
* of this shader with cell foreground and background colors blended directly.
50-
* Expected output is a color premultiplied by alpha, with an alpha specified as well.
50+
* Expected output is either opaque colors or pre-multiplied colors.
5151
*
5252
* 2) Interleaved -- this path is used if background is not opaque and there are images or
5353
* if the background is opaque but there are images under text. Rendering happens in

kitty/shaders.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,14 @@ viewport_for_cells(const CellRenderData *crd) {
550550
}
551551

552552
static void
553-
draw_cells_simple(ssize_t vao_idx, Screen *screen, const CellRenderData *crd) {
553+
draw_cells_simple(ssize_t vao_idx, Screen *screen, const CellRenderData *crd, bool is_semi_transparent) {
554554
bind_program(CELL_PROGRAM);
555555
glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, screen->lines * screen->columns);
556556
if (screen->grman->count) {
557557
glEnable(GL_BLEND);
558-
BLEND_ONTO_OPAQUE;
559-
draw_graphics(GRAPHICS_PROGRAM, vao_idx, screen->grman->render_data, 0, screen->grman->count, viewport_for_cells(crd));
558+
int program = GRAPHICS_PROGRAM;
559+
if (is_semi_transparent) { BLEND_PREMULT; program = GRAPHICS_PREMULT_PROGRAM; } else { BLEND_ONTO_OPAQUE; }
560+
draw_graphics(program, vao_idx, screen->grman->render_data, 0, screen->grman->count, viewport_for_cells(crd));
560561
glDisable(GL_BLEND);
561562
}
562563
}
@@ -955,14 +956,13 @@ draw_cells(ssize_t vao_idx, const ScreenRenderData *srd, OSWindow *os_window, bo
955956
scale_rendered_graphic(screen->grman->render_data + i, srd->xstart, srd->ystart, crd.x_ratio, crd.y_ratio);
956957
}
957958
}
959+
has_underlying_image |= screen->grman->num_of_below_refs > 0 || screen->grman->num_of_negative_refs > 0;
958960
if (os_window->is_semi_transparent) {
959-
if (screen->grman->count || has_underlying_image) draw_cells_interleaved_premult(
960-
vao_idx, screen, os_window, &crd, wl);
961-
else draw_cells_simple(vao_idx, screen, &crd);
961+
if (has_underlying_image) draw_cells_interleaved_premult(vao_idx, screen, os_window, &crd, wl);
962+
else draw_cells_simple(vao_idx, screen, &crd, os_window->is_semi_transparent);
962963
} else {
963-
if (screen->grman->num_of_negative_refs || screen->grman->num_of_below_refs || has_underlying_image) draw_cells_interleaved(
964-
vao_idx, screen, os_window, &crd, wl);
965-
else draw_cells_simple(vao_idx, screen, &crd);
964+
if (has_underlying_image) draw_cells_interleaved(vao_idx, screen, os_window, &crd, wl);
965+
else draw_cells_simple(vao_idx, screen, &crd, os_window->is_semi_transparent);
966966
}
967967

968968
if (screen->start_visual_bell_at) {

0 commit comments

Comments
 (0)