ebiten: revert the changes for DrawRectShader

This reverts these commits:
- 9bd46cb2b5.
- f8c4634017.

This causes test failures on the Steam bot. See #2246.

Updates #2166
Closes #2246
This commit is contained in:
Hajime Hoshi 2022-08-17 00:56:15 +09:00
parent bb2df24f83
commit 652cd169b2
2 changed files with 0 additions and 72 deletions

View File

@ -701,11 +701,6 @@ func (i *Image) DrawRectShader(width, height int, shader *Shader, options *DrawR
b := img.Bounds()
sx, sy = img.adjustPosition(b.Min.X, b.Min.Y)
sr = img.adjustedRegion()
} else {
sr = graphicsdriver.Region{
Width: float32(width),
Height: float32(height),
}
}
if offsetX, offsetY := i.adjustPosition(0, 0); offsetX != 0 || offsetY != 0 {

View File

@ -1181,70 +1181,3 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
}
}
}
// Issue #2166
func TestShaderDrawRect(t *testing.T) {
const (
dstW = 16
dstH = 16
srcW = 8
srcH = 8
)
dst := ebiten.NewImage(dstW, dstH)
src := ebiten.NewImage(srcW, srcH)
s, err := ebiten.NewShader([]byte(`package main
func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
// Adjust texCoord into [0, 1].
t := texCoord
origin, size := imageSrcRegionOnTexture()
t -= origin
t /= size
if t.x >= 0.5 && t.y >= 0.5 {
return vec4(1, 0, 0, 1)
}
return vec4(0, 1, 0, 1)
}
`))
if err != nil {
t.Fatal(err)
}
for _, withSrc := range []bool{false, true} {
withSrc := withSrc
title := "WithSrc"
if !withSrc {
title = "WithoutSrc"
}
t.Run(title, func(t *testing.T) {
const (
offsetX = (dstW - srcW) / 2
offsetY = (dstH - srcH) / 2
)
op := &ebiten.DrawRectShaderOptions{}
op.GeoM.Translate(offsetX, offsetY)
if withSrc {
op.Images[0] = src
}
dst.DrawRectShader(srcW, srcH, s, op)
for j := 0; j < dstH; j++ {
for i := 0; i < dstW; i++ {
got := dst.At(i, j).(color.RGBA)
var want color.RGBA
if offsetX <= i && i < offsetX+srcW && offsetY <= j && j < offsetY+srcH {
if offsetX+srcW/2 <= i && offsetY+srcH/2 <= j {
want = color.RGBA{0xff, 0, 0, 0xff}
} else {
want = color.RGBA{0, 0xff, 0, 0xff}
}
}
if got != want {
t.Errorf("dst.At(%d, %d): got: %v, want: %v", i, j, got, want)
}
}
}
})
}
}