diff --git a/internal/graphicscommand/command.go b/internal/graphicscommand/command.go index a80b6e7a8..b829bc9ee 100644 --- a/internal/graphicscommand/command.go +++ b/internal/graphicscommand/command.go @@ -418,13 +418,27 @@ func (c *drawTrianglesCommand) Exec(indexOffset int) error { if c.shader != nil { us := make([]interface{}, len(c.uniforms)) - // TODO: Adjust the source sizes in uniform variables. - for k, v := range c.uniforms { - switch v := v.(type) { + + firstImage := true + for i := 0; i < len(c.uniforms); i++ { + switch v := c.uniforms[i].(type) { case *Image: - us[k] = v.image.ID() + us[i] = v.image.ID() + if !firstImage { + // Convert pixels to texels. + w, h := v.InternalSize() + i++ + region := c.uniforms[i].([]float32) + us[i] = []float32{ + region[0] / float32(w), + region[1] / float32(h), + region[2] / float32(w), + region[3] / float32(h), + } + } + firstImage = false default: - us[k] = v + us[i] = v } } return theGraphicsDriver.DrawShader(c.dst.image.ID(), c.shader.shader.ID(), c.nindices, indexOffset, c.mode, us) diff --git a/internal/shareable/image.go b/internal/shareable/image.go index ba632d36a..836fea0c5 100644 --- a/internal/shareable/image.go +++ b/internal/shareable/image.go @@ -324,16 +324,18 @@ func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16, firstImage := true us := make([]interface{}, len(uniforms)) for i := 0; i < len(uniforms); i++ { - switch v := us[i].(type) { + switch v := uniforms[i].(type) { case *Image: us[i] = v.backend.restorable if !firstImage { i++ - region := us[i].([]float32) - region[0] += oxf - region[1] += oyf - region[2] += oxf - region[3] += oyf + region := uniforms[i].([]float32) + us[i] = []float32{ + region[0] + oxf, + region[1] + oyf, + region[2] + oxf, + region[3] + oyf, + } } firstImage = false default: