GLES3: Fix false positive in ninepatch axis stretch code

See #34704.
This commit is contained in:
Rémi Verschelde 2020-01-01 11:49:58 +01:00
parent 5b173c4bf1
commit e4907e50fe

View File

@ -397,26 +397,29 @@ float map_ninepatch_axis(float pixel, float draw_size, float tex_pixel_size, flo
draw_center--; draw_center--;
} }
if (np_repeat == 0) { //stretch // np_repeat is passed as uniform using NinePatchRect::AxisStretchMode enum.
//convert to ratio if (np_repeat == 0) { // Stretch.
// Convert to ratio.
float ratio = (pixel - screen_margin_begin) / (draw_size - screen_margin_begin - screen_margin_end); 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; return (margin_begin + ratio * (tex_size - margin_begin - margin_end)) * tex_pixel_size;
} else if (np_repeat == 1) { //tile } else if (np_repeat == 1) { // Tile.
//convert to ratio // Convert to offset.
float ofs = mod((pixel - screen_margin_begin), tex_size - margin_begin - margin_end); 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; return (margin_begin + ofs) * tex_pixel_size;
} else if (np_repeat == 2) { //tile fit } else if (np_repeat == 2) { // Tile Fit.
//convert to ratio // Calculate scale.
float src_area = draw_size - screen_margin_begin - screen_margin_end; float src_area = draw_size - screen_margin_begin - screen_margin_end;
float dst_area = tex_size - margin_begin - 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)); 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; float ratio = (pixel - screen_margin_begin) / src_area;
ratio = mod(ratio * scale, 1.0); ratio = mod(ratio * scale, 1.0);
// Scale to source texture.
return (margin_begin + ratio * dst_area) * tex_pixel_size; return (margin_begin + ratio * dst_area) * tex_pixel_size;
} else { // Shouldn't happen, but silences compiler warning.
return 0;
} }
} }
} }