From eb322913c3b2c35dd8a8ebbb0db490d711b1b66a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 15 Dec 2024 22:13:11 +0530 Subject: [PATCH] Remove a switch in the cell vertex shader --- kitty/cell_vertex.glsl | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/kitty/cell_vertex.glsl b/kitty/cell_vertex.glsl index 99e87efa3..2cbef2646 100644 --- a/kitty/cell_vertex.glsl +++ b/kitty/cell_vertex.glsl @@ -76,21 +76,17 @@ vec3 color_to_vec(uint c) { return vec3(gamma_lut[r], gamma_lut[g], gamma_lut[b]); } +float one_if_equal_zero_otherwise(int a, int b) { + return 1.0f - clamp(abs(float(a) - float(b)), 0.0f, 1.0f); +} + uint resolve_color(uint c, uint defval) { // Convert a cell color to an actual color based on the color table int t = int(c & BYTE_MASK); - uint r; - switch(t) { - case 1: - r = color_table[(c >> 8) & BYTE_MASK]; - break; - case 2: - r = c >> 8; - break; - default: - r = defval; - } - return r; + uint is_one = uint(one_if_equal_zero_otherwise(t, 1)); + uint is_two = uint(one_if_equal_zero_otherwise(t, 2)); + uint is_neither_one_nor_two = 1u - is_one - is_two; + return is_one * color_table[(c >> 8) & BYTE_MASK] + is_two * (c >> 8) + is_neither_one_nor_two * defval; } vec3 to_color(uint c, uint defval) {