graphics: Bug fix: TestImageEdge failed on MacBook Pro (#491)

This commit is contained in:
Hajime Hoshi 2018-02-03 03:30:09 +09:00
parent b385a63856
commit 52350c1b1b
2 changed files with 9 additions and 17 deletions

View File

@ -51,19 +51,13 @@ varying vec2 varying_tex_coord;
varying vec2 varying_tex_coord_min;
varying vec2 varying_tex_coord_max;
const float minHighpValue = 1.0 / 32768.0;
void main(void) {
varying_tex_coord = vec2(tex_coord[0], tex_coord[1]);
// varying_tex_coord_min and varying_tex_coord_max mean endmost texel values
// in the source rect. As varying_tex_coord is adjusted with minHighpValue
// in vertices.go, re-adjust them so that exact endmost texel values.
varying_tex_coord_min = vec2(
min(tex_coord[0], tex_coord[2]) - minHighpValue,
min(tex_coord[1], tex_coord[3]) - minHighpValue);
varying_tex_coord_max = vec2(
max(tex_coord[0], tex_coord[2]) + minHighpValue,
max(tex_coord[1], tex_coord[3]) + minHighpValue);
varying_tex_coord_min = vec2(min(tex_coord[0], tex_coord[2]), min(tex_coord[1], tex_coord[3]));
varying_tex_coord_max = vec2(max(tex_coord[0], tex_coord[2]), max(tex_coord[1], tex_coord[3]));
gl_Position = projection_matrix * vec4(vertex, 0, 1);
}
`
@ -102,6 +96,13 @@ highp vec2 roundTexel(highp vec2 p) {
void main(void) {
highp vec2 pos = varying_tex_coord;
// Adjust texels to be slightly inside the source rect. Without this
// adjustment, texels can be exactly as same values as the (lower and left) edges'
// positions and it could happen that outside of the source is rendered. (#491)
// 1.0 / 4096.0 is an arbitrary number that doesn't cause problems on MacBook Pro.
pos.x = min(varying_tex_coord_max.x - 1.0 / 4096.0, pos.x);
pos.y = min(varying_tex_coord_max.y - 1.0 / 4096.0, pos.y);
#if defined(FILTER_NEAREST)
vec4 color = texture2D(texture, pos);
if (pos.x < varying_tex_coord_min.x ||

View File

@ -87,15 +87,6 @@ func vertices(sx0, sy0, sx1, sy1 int, width, height int, geo *affine.GeoM) []flo
hf := float32(h)
u0, v0, u1, v1 := float32(sx0)/wf, float32(sy0)/hf, float32(sx1)/wf, float32(sy1)/hf
// Adjust texels to be slightly inside the source rect. Without this
// adjustment, texels can be exactly as same values as the edges'
// positions and it could happen that outside of the source is rendered. (#491)
const minHighpValue = 1.0 / 32768.0
u0 += minHighpValue
v0 += minHighpValue
u1 -= minHighpValue
v1 -= minHighpValue
x, y := geo.Apply32(x0, y0)
// Vertex coordinates
vs[0] = x