From e4907e50feab1af05f514a66adc0086d1c141885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Wed, 1 Jan 2020 11:49:58 +0100 Subject: GLES3: Fix false positive in ninepatch axis stretch code See #34704. --- drivers/gles3/shaders/canvas.glsl | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'drivers/gles3') diff --git a/drivers/gles3/shaders/canvas.glsl b/drivers/gles3/shaders/canvas.glsl index 53f84abf51..cd1c669be5 100644 --- a/drivers/gles3/shaders/canvas.glsl +++ b/drivers/gles3/shaders/canvas.glsl @@ -397,26 +397,29 @@ float map_ninepatch_axis(float pixel, float draw_size, float tex_pixel_size, flo draw_center--; } - if (np_repeat == 0) { //stretch - //convert to ratio + // np_repeat is passed as uniform using NinePatchRect::AxisStretchMode enum. + if (np_repeat == 0) { // Stretch. + // Convert to ratio. float ratio = (pixel - screen_margin_begin) / (draw_size - screen_margin_begin - screen_margin_end); - //scale to source texture + // Scale to source texture. return (margin_begin + ratio * (tex_size - margin_begin - margin_end)) * tex_pixel_size; - } else if (np_repeat == 1) { //tile - //convert to ratio + } else if (np_repeat == 1) { // Tile. + // Convert to offset. float ofs = mod((pixel - screen_margin_begin), tex_size - margin_begin - margin_end); - //scale to source texture + // Scale to source texture. return (margin_begin + ofs) * tex_pixel_size; - } else if (np_repeat == 2) { //tile fit - //convert to ratio + } else if (np_repeat == 2) { // Tile Fit. + // Calculate scale. float src_area = draw_size - screen_margin_begin - screen_margin_end; float dst_area = tex_size - margin_begin - margin_end; float scale = max(1.0, floor(src_area / max(dst_area, 0.0000001) + 0.5)); - - //convert to ratio + // Convert to ratio. float ratio = (pixel - screen_margin_begin) / src_area; ratio = mod(ratio * scale, 1.0); + // Scale to source texture. return (margin_begin + ratio * dst_area) * tex_pixel_size; + } else { // Shouldn't happen, but silences compiler warning. + return 0; } } } -- cgit v1.2.3