diff --git a/image.go b/image.go index 776f58e58..8a8be65d1 100644 --- a/image.go +++ b/image.go @@ -367,7 +367,6 @@ func (i *Image) DrawTrianglesWithShader(vertices []Vertex, indices []uint16, sha mode := driver.CompositeMode(options.CompositeMode) us := []interface{}{} - var firstImage *Image for _, v := range options.Uniforms { switch v := v.(type) { case *Image: @@ -375,17 +374,6 @@ func (i *Image) DrawTrianglesWithShader(vertices []Vertex, indices []uint16, sha panic("ebiten: the given image to DrawTriangles must not be disposed") } us = append(us, v.buffered) - if firstImage == nil { - firstImage = v - } else { - b := v.Bounds() - us = append(us, []float32{ - float32(b.Min.X), - float32(b.Min.Y), - float32(b.Max.X), - float32(b.Max.Y), - }) - } default: us = append(us, v) } @@ -395,25 +383,17 @@ func (i *Image) DrawTrianglesWithShader(vertices []Vertex, indices []uint16, sha // The actual value is set at graphicscommand package. us = append([]interface{}{[]float32{0, 0}}, us...) - var bx0, by0, bx1, by1 float32 - if firstImage != nil { - b := firstImage.Bounds() - bx0 = float32(b.Min.X) - by0 = float32(b.Min.Y) - bx1 = float32(b.Max.X) - by1 = float32(b.Max.Y) - } - vs := make([]float32, len(vertices)*graphics.VertexFloatNum) for i, v := range vertices { vs[i*graphics.VertexFloatNum] = v.DstX vs[i*graphics.VertexFloatNum+1] = v.DstY vs[i*graphics.VertexFloatNum+2] = v.SrcX vs[i*graphics.VertexFloatNum+3] = v.SrcY - vs[i*graphics.VertexFloatNum+4] = bx0 - vs[i*graphics.VertexFloatNum+5] = by0 - vs[i*graphics.VertexFloatNum+6] = bx1 - vs[i*graphics.VertexFloatNum+7] = by1 + // TODO: Remove these values for the source region. + vs[i*graphics.VertexFloatNum+4] = 0 + vs[i*graphics.VertexFloatNum+5] = 0 + vs[i*graphics.VertexFloatNum+6] = 0 + vs[i*graphics.VertexFloatNum+7] = 0 vs[i*graphics.VertexFloatNum+8] = v.ColorR vs[i*graphics.VertexFloatNum+9] = v.ColorG vs[i*graphics.VertexFloatNum+10] = v.ColorB diff --git a/internal/graphicscommand/command.go b/internal/graphicscommand/command.go index 86ddf98d7..cf3b49f75 100644 --- a/internal/graphicscommand/command.go +++ b/internal/graphicscommand/command.go @@ -410,28 +410,10 @@ func (c *drawTrianglesCommand) Exec(indexOffset int) error { if c.shader != nil { us := make([]interface{}, len(c.uniforms)) - firstImage := true for i := 0; i < len(c.uniforms); i++ { switch v := c.uniforms[i].(type) { case *Image: us[i] = v.image.ID() - if firstImage { - firstImage = false - continue - } - - // Convert pixels to texels. - w, h := v.InternalSize() - i++ - region := c.uniforms[i].([]float32) - vs := []float32{ - region[0] / float32(w), - region[1] / float32(h), - region[2] / float32(w), - region[3] / float32(h), - } - - us[i] = vs default: us[i] = v } diff --git a/internal/restorable/shader_test.go b/internal/restorable/shader_test.go index a7194abd6..362c963dd 100644 --- a/internal/restorable/shader_test.go +++ b/internal/restorable/shader_test.go @@ -116,9 +116,7 @@ func TestShaderMultipleSources(t *testing.T) { []float32{0, 0}, srcs[0], srcs[1], - []float32{0, 0, 1, 1}, srcs[2], - []float32{0, 0, 1, 1}, } dst.DrawTriangles(nil, quadVertices(1, 1, 0, 0), graphics.QuadIndices(), nil, driver.CompositeModeCopy, driver.FilterNearest, driver.AddressUnsafe, s, us) diff --git a/internal/shareable/image.go b/internal/shareable/image.go index 2aa7b9f7a..e27b2665f 100644 --- a/internal/shareable/image.go +++ b/internal/shareable/image.go @@ -357,23 +357,11 @@ func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16, s = shader.shader } - firstImage := true us := make([]interface{}, len(uniforms)) for i := 0; i < len(uniforms); i++ { switch v := uniforms[i].(type) { case *Image: us[i] = v.backend.restorable - if !firstImage { - i++ - region := uniforms[i].([]float32) - us[i] = []float32{ - region[0] + oxf, - region[1] + oyf, - region[2] + oxf, - region[3] + oyf, - } - } - firstImage = false default: us[i] = v } diff --git a/internal/testing/shader.go b/internal/testing/shader.go index 32c5b82c9..200bbca8b 100644 --- a/internal/testing/shader.go +++ b/internal/testing/shader.go @@ -288,10 +288,8 @@ func ShaderProgramFill(r, g, b, a byte) shaderir.Program { // // Uniform variables's indices and their values are: // -// 0: the framebuffer size (Vec2) -// 1: the first images (Texture2D) -// 2n: the n-th image (Texture2D) -// 2n+1: the n-th image's region (Vec4) +// 0: the framebuffer size (Vec2) +// 1-: the images (Texture2D) // // The first image's size and region are represented in attribute variables. // @@ -363,7 +361,7 @@ func ShaderProgramImages(imageNum int) shaderir.Program { }, { Type: shaderir.UniformVariable, - Index: 2 * i, + Index: i + 1, }, texPos, },