From 6d36c432ab926cd0333b4a1fb61b77cab57c522f Mon Sep 17 00:00:00 2001 From: Bin Jin Date: Tue, 8 Dec 2015 22:22:08 +0000 Subject: [PATCH] vo_opengl: fix precision loss of fruit dithering matrix With default setting, the matrix for fruit dithering requires 12 bits precision (values from 0/4096 to 4095/4096). But 16-bit float provides only 10 bits. In addition, when `dither-size-fruit=8` is set, 16 bits are required from the texture format. Fix this by attempting to use 16 bit integer texture first. This is still not precise, but should be better than using a half float. --- video/out/opengl/video.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/video/out/opengl/video.c b/video/out/opengl/video.c index 8b7ec35478..30147235c2 100644 --- a/video/out/opengl/video.c +++ b/video/out/opengl/video.c @@ -1736,9 +1736,16 @@ static void pass_dither(struct gl_video *p) p->last_dither_matrix_size = size; } + const struct fmt_entry *fmt = find_tex_format(gl, 2, 1); tex_size = size; - tex_iformat = gl_float16_formats[0].internal_format; - tex_format = gl_float16_formats[0].format; + // Prefer R16 texture since they provide higher precision. + if (fmt->internal_format) { + tex_iformat = fmt->internal_format; + tex_format = fmt->format; + } else { + tex_iformat = gl_float16_formats[0].internal_format; + tex_format = gl_float16_formats[0].format; + } tex_type = GL_FLOAT; tex_data = p->last_dither_matrix; } else {