Revert "graphics: Bug fix: More strict calculation for the nearest filter (#558)"

This reverts commit bae8f9d874.

Reason: TravisCI failed
This commit is contained in:
Hajime Hoshi 2018-03-20 04:15:49 +09:00
parent a40dc5cf22
commit b157f2d6d0
3 changed files with 26 additions and 31 deletions

View File

@ -504,7 +504,7 @@ func TestImageFill(t *testing.T) {
}
}
// Issue #317, #558
// Issue #317
func TestImageEdge(t *testing.T) {
const (
img0Width = 16
@ -537,7 +537,7 @@ func TestImageEdge(t *testing.T) {
transparent := color.RGBA{0, 0, 0, 0}
for _, f := range []Filter{FilterNearest, FilterLinear} {
for a := 0; a < 360; a++ {
for a := 0; a < 360; a += 5 {
img1.Clear()
op := &DrawImageOptions{}
w, h := img0.Size()

View File

@ -321,16 +321,17 @@ func (s *openGLState) useProgram(proj []float32, texture opengl.Texture, dst, sr
s.lastColorMatrixTranslation = esTranslate
}
sw, sh := src.Size()
sw = emath.NextPowerOf2Int(sw)
sh = emath.NextPowerOf2Int(sh)
if program == s.programLinear || program == s.programScreen {
sw, sh := src.Size()
sw = emath.NextPowerOf2Int(sw)
sh = emath.NextPowerOf2Int(sh)
if s.lastSourceWidth != sw || s.lastSourceHeight != sh {
c.UniformFloats(program, "source_size", []float32{float32(sw), float32(sh)})
s.lastSourceWidth = sw
s.lastSourceHeight = sh
if s.lastSourceWidth != sw || s.lastSourceHeight != sh {
c.UniformFloats(program, "source_size", []float32{float32(sw), float32(sh)})
s.lastSourceWidth = sw
s.lastSourceHeight = sh
}
}
if program == s.programScreen {
sw, _ := src.Size()
dw, _ := dst.Size()

View File

@ -76,7 +76,9 @@ uniform sampler2D texture;
uniform mat4 color_matrix;
uniform vec4 color_matrix_translation;
#if defined(FILTER_LINEAR) || defined(FILTER_SCREEN)
uniform highp vec2 source_size;
#endif
#if defined(FILTER_SCREEN)
uniform highp float scale;
@ -102,10 +104,19 @@ void main(void) {
// roundTexel adjusts pos by rounding it (#315, #558).
pos = roundTexel(pos);
#if defined(FILTER_NEAREST)
vec4 color = texture2D(texture, pos);
if (pos.x < varying_tex_coord_min.x ||
pos.y < varying_tex_coord_min.y ||
varying_tex_coord_max.x <= pos.x ||
varying_tex_coord_max.y <= pos.y) {
color = vec4(0, 0, 0, 0);
}
#endif
#if defined(FILTER_LINEAR)
highp vec2 texel_size = 1.0 / source_size;
#if defined(FILTER_NEAREST) || defined(FILTER_LINEAR)
// Even with the nearest filter, it is better to calculate the color with around 4 texels (#558).
highp vec2 p0 = pos - texel_size / 2.0;
highp vec2 p1 = pos + texel_size / 2.0;
vec4 c0 = texture2D(texture, p0);
@ -130,31 +141,14 @@ void main(void) {
}
vec2 rate = fract(p0 * source_size);
#if defined(FILTER_NEAREST)
vec4 color;
if (rate.x < 0.5) {
if (rate.y < 0.5) {
color = c0;
} else {
color = c2;
}
} else {
if (rate.y < 0.5) {
color = c1;
} else {
color = c3;
}
}
#elif defined(FILTER_LINEAR)
vec4 color = mix(mix(c0, c1, rate.x), mix(c2, c3, rate.x), rate.y);
#endif
#endif
#if defined(FILTER_SCREEN)
highp vec2 texel_size = 1.0 / source_size;
highp vec2 p0 = pos - texel_size / 2.0 / scale;
highp vec2 p1 = pos + texel_size / 2.0 / scale;
vec4 c0 = texture2D(texture, p0);
vec4 c1 = texture2D(texture, vec2(p1.x, p0.y));
vec4 c2 = texture2D(texture, vec2(p0.x, p1.y));