Skip to content

Commit

Permalink
shareable: Bug fix: Wrong offset calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
hajimehoshi committed Sep 20, 2020
1 parent 9ac7a16 commit 138d9b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/shareable/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageNum]*Image, vertices []f
ox += paddingSize
oy += paddingSize
offsets[i][0] = float32(ox) - oxf + subimageOffsets[i][0]
offsets[i][1] = float32(oy) - oyf + subimageOffsets[i][0]
offsets[i][1] = float32(oy) - oyf + subimageOffsets[i][1]
}

var s *restorable.Shader
Expand Down
16 changes: 8 additions & 8 deletions shader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
pix0 := make([]byte, 4*w*h)
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
if 2 <= i && i < 10 && 2 <= j && j < 10 {
if 2 <= i && i < 10 && 3 <= j && j < 11 {
pix0[4*(j*w+i)] = 0xff
pix0[4*(j*w+i)+1] = 0
pix0[4*(j*w+i)+2] = 0
Expand All @@ -830,13 +830,13 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
}
}
src0.ReplacePixels(pix0)
src0 = src0.SubImage(image.Rect(2, 2, 10, 10)).(*Image)
src0 = src0.SubImage(image.Rect(2, 3, 10, 11)).(*Image)

src1, _ := NewImage(w, h, FilterDefault)
pix1 := make([]byte, 4*w*h)
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
if 6 <= i && i < 14 && 6 <= j && j < 14 {
if 6 <= i && i < 14 && 8 <= j && j < 16 {
pix1[4*(j*w+i)] = 0
pix1[4*(j*w+i)+1] = 0xff
pix1[4*(j*w+i)+2] = 0
Expand All @@ -845,7 +845,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
}
}
src1.ReplacePixels(pix1)
src1 = src1.SubImage(image.Rect(6, 6, 14, 14)).(*Image)
src1 = src1.SubImage(image.Rect(6, 8, 14, 16)).(*Image)

testPixels := func(testname string, dst *Image) {
for j := 0; j < h; j++ {
Expand Down Expand Up @@ -878,7 +878,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
DstX: 0,
DstY: 0,
SrcX: 2,
SrcY: 2,
SrcY: 3,
ColorR: 1,
ColorG: 1,
ColorB: 1,
Expand All @@ -888,7 +888,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
DstX: w / 2,
DstY: 0,
SrcX: 10,
SrcY: 2,
SrcY: 3,
ColorR: 1,
ColorG: 1,
ColorB: 1,
Expand All @@ -898,7 +898,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
DstX: 0,
DstY: h / 2,
SrcX: 2,
SrcY: 10,
SrcY: 11,
ColorR: 1,
ColorG: 1,
ColorB: 1,
Expand All @@ -908,7 +908,7 @@ func Fragment(position vec4, texCoord vec2, color vec4) vec4 {
DstX: w / 2,
DstY: h / 2,
SrcX: 10,
SrcY: 10,
SrcY: 11,
ColorR: 1,
ColorG: 1,
ColorB: 1,
Expand Down

0 comments on commit 138d9b8

Please sign in to comment.