diff --git a/internal/atlas/image.go b/internal/atlas/image.go index c98dc0e20..3f224a9a5 100644 --- a/internal/atlas/image.go +++ b/internal/atlas/image.go @@ -343,6 +343,10 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices [ } func (i *Image) drawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices []float32, indices []uint32, blend graphicsdriver.Blend, dstRegion image.Rectangle, srcRegions [graphics.ShaderImageCount]image.Rectangle, shader *Shader, uniforms []uint32, fillRule graphicsdriver.FillRule) { + if len(vertices) == 0 { + return + } + backends := make([]*backend, 0, len(srcs)) for _, src := range srcs { if src == nil { @@ -415,15 +419,15 @@ func (i *Image) drawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices [ srcRegions[i] = srcRegions[i].Add(r.Min) } - var imgs [graphics.ShaderImageCount]*restorable.Image + var imgs [graphics.ShaderImageCount]*graphicscommand.Image for i, src := range srcs { if src == nil { continue } - imgs[i] = src.backend.restorable + imgs[i] = src.backend.restorable.Image } - i.backend.restorable.DrawTriangles(imgs, vertices, indices, blend, dstRegion, srcRegions, shader.ensureShader(), uniforms, fillRule) + i.backend.restorable.Image.DrawTriangles(imgs, vertices, indices, blend, dstRegion, srcRegions, shader.ensureShader().Shader, uniforms, fillRule) for _, src := range srcs { if src == nil { diff --git a/internal/restorable/image.go b/internal/restorable/image.go index 6f2908c4a..c61781c47 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -66,12 +66,12 @@ func (i *Image) Extend(width, height int) *Image { // Use DrawTriangles instead of WritePixels because the image i might be stale and not have its pixels // information. - srcs := [graphics.ShaderImageCount]*Image{i} + srcs := [graphics.ShaderImageCount]*graphicscommand.Image{i.Image} sw, sh := i.Image.InternalSize() vs := quadVertices(0, 0, float32(sw), float32(sh), 0, 0, float32(sw), float32(sh), 1, 1, 1, 1) is := graphics.QuadIndices() dr := image.Rect(0, 0, sw, sh) - newImg.DrawTriangles(srcs, vs, is, graphicsdriver.BlendCopy, dr, [graphics.ShaderImageCount]image.Rectangle{}, NearestFilterShader, nil, graphicsdriver.FillAll) + newImg.Image.DrawTriangles(srcs, vs, is, graphicsdriver.BlendCopy, dr, [graphics.ShaderImageCount]image.Rectangle{}, NearestFilterShader.Shader, nil, graphicsdriver.FillAll) i.Image.Dispose() i.Image = nil @@ -116,30 +116,3 @@ func (i *Image) WritePixels(pixels *graphics.ManagedBytes, region image.Rectangl i.Image.WritePixels(pixels, region) } - -// DrawTriangles draws triangles with the given image. -// -// The vertex floats are: -// -// 0: Destination X in pixels -// 1: Destination Y in pixels -// 2: Source X in texels -// 3: Source Y in texels -// 4: Color R [0.0-1.0] -// 5: Color G -// 6: Color B -// 7: Color Y -func (i *Image) DrawTriangles(srcs [graphics.ShaderImageCount]*Image, vertices []float32, indices []uint32, blend graphicsdriver.Blend, dstRegion image.Rectangle, srcRegions [graphics.ShaderImageCount]image.Rectangle, shader *Shader, uniforms []uint32, fillRule graphicsdriver.FillRule) { - if len(vertices) == 0 { - return - } - - var imgs [graphics.ShaderImageCount]*graphicscommand.Image - for i, src := range srcs { - if src == nil { - continue - } - imgs[i] = src.Image - } - i.Image.DrawTriangles(imgs, vertices, indices, blend, dstRegion, srcRegions, shader.Shader, uniforms, fillRule) -}