From ce4c511fdc81b52e77683e756034f37b444cec9a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 5 Sep 2025 08:47:53 +0530 Subject: [PATCH] Use a 16bit per channel texture for intermediate output rather than 8bit per channel This doubles VRAM consumption, but is needed for accurate color blending of the intermediate layers. 16bits is mostly enough, though for perfect accuracy 32 bits is required. Use 16 as a compromise. Fixes #8953 --- kitty/shaders.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kitty/shaders.c b/kitty/shaders.c index 735cb722c..495d9e727 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -651,7 +651,9 @@ setup_texture_as_render_target(unsigned width, unsigned height, GLuint *texture_ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + // We use GL_RGBA16 to avoid incorrect colors due to quantization loss when + // blending, see https://github.com/kovidgoyal/kitty/issues/8953 + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); bind_framebuffer_for_output(*framebuffer_id); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, *texture_id, 0); }