From eb2196633bee27971b59ec1682a06b92789aba1b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 23 Jun 2023 16:26:36 +0530 Subject: [PATCH] Speed up rendering in the case of transparent window + non-underlaid images Do single pass rendering for these as well. --- kitty/cell_fragment.glsl | 4 ++-- kitty/shaders.c | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/kitty/cell_fragment.glsl b/kitty/cell_fragment.glsl index c8044e65a..8994f115e 100644 --- a/kitty/cell_fragment.glsl +++ b/kitty/cell_fragment.glsl @@ -45,9 +45,9 @@ vec4 vec4_premul(vec4 rgba) { * are images that are below the foreground. Single pass rendering has PHASE=PHASE_BOTH. Otherwise, there * are three passes, PHASE=PHASE_BACKGROUND, PHASE=PHASE_SPECIAL, PHASE=PHASE_FOREGROUND. * 1) Single pass -- this path is used when there are either no images, or all images are - * drawn on top of text and the background is opaque. In this case, there is a single pass, + * drawn on top of text. In this case, there is a single pass, * of this shader with cell foreground and background colors blended directly. - * Expected output is a color premultiplied by alpha, with an alpha specified as well. + * Expected output is either opaque colors or pre-multiplied colors. * * 2) Interleaved -- this path is used if background is not opaque and there are images or * if the background is opaque but there are images under text. Rendering happens in diff --git a/kitty/shaders.c b/kitty/shaders.c index aa7859565..2407b8eb8 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -550,13 +550,14 @@ viewport_for_cells(const CellRenderData *crd) { } static void -draw_cells_simple(ssize_t vao_idx, Screen *screen, const CellRenderData *crd) { +draw_cells_simple(ssize_t vao_idx, Screen *screen, const CellRenderData *crd, bool is_semi_transparent) { bind_program(CELL_PROGRAM); glDrawArraysInstanced(GL_TRIANGLE_FAN, 0, 4, screen->lines * screen->columns); if (screen->grman->count) { glEnable(GL_BLEND); - BLEND_ONTO_OPAQUE; - draw_graphics(GRAPHICS_PROGRAM, vao_idx, screen->grman->render_data, 0, screen->grman->count, viewport_for_cells(crd)); + int program = GRAPHICS_PROGRAM; + if (is_semi_transparent) { BLEND_PREMULT; program = GRAPHICS_PREMULT_PROGRAM; } else { BLEND_ONTO_OPAQUE; } + draw_graphics(program, vao_idx, screen->grman->render_data, 0, screen->grman->count, viewport_for_cells(crd)); glDisable(GL_BLEND); } } @@ -955,14 +956,13 @@ draw_cells(ssize_t vao_idx, const ScreenRenderData *srd, OSWindow *os_window, bo scale_rendered_graphic(screen->grman->render_data + i, srd->xstart, srd->ystart, crd.x_ratio, crd.y_ratio); } } + has_underlying_image |= screen->grman->num_of_below_refs > 0 || screen->grman->num_of_negative_refs > 0; if (os_window->is_semi_transparent) { - if (screen->grman->count || has_underlying_image) draw_cells_interleaved_premult( - vao_idx, screen, os_window, &crd, wl); - else draw_cells_simple(vao_idx, screen, &crd); + if (has_underlying_image) draw_cells_interleaved_premult(vao_idx, screen, os_window, &crd, wl); + else draw_cells_simple(vao_idx, screen, &crd, os_window->is_semi_transparent); } else { - if (screen->grman->num_of_negative_refs || screen->grman->num_of_below_refs || has_underlying_image) draw_cells_interleaved( - vao_idx, screen, os_window, &crd, wl); - else draw_cells_simple(vao_idx, screen, &crd); + if (has_underlying_image) draw_cells_interleaved(vao_idx, screen, os_window, &crd, wl); + else draw_cells_simple(vao_idx, screen, &crd, os_window->is_semi_transparent); } if (screen->start_visual_bell_at) {