From f48a72a43e13291de22d6ad78b08ff14e0832219 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 22 Jun 2019 21:13:44 +0900 Subject: [PATCH] shareable: Refactoring: Remove PutQuadVertices --- image.go | 8 ++++---- internal/shareable/shareable.go | 10 +--------- internal/shareable/shareable_test.go | 6 +++--- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/image.go b/image.go index 4cbb57801..0883ab4b9 100644 --- a/image.go +++ b/image.go @@ -74,10 +74,10 @@ func (m *mipmap) level(r image.Rectangle, level int) *shareable.Image { vs := vertexSlice(4) if l := len(imgs); l == 0 { src = m.orig - src.PutQuadVertices(vs, r.Min.X, r.Min.Y, r.Max.X, r.Max.Y, 0.5, 0, 0, 0.5, 0, 0, 1, 1, 1, 1) + graphics.PutQuadVertices(vs, src, r.Min.X, r.Min.Y, r.Max.X, r.Max.Y, 0.5, 0, 0, 0.5, 0, 0, 1, 1, 1, 1) } else { src = m.level(r, l) - src.PutQuadVertices(vs, 0, 0, w, h, 0.5, 0, 0, 0.5, 0, 0, 1, 1, 1, 1) + graphics.PutQuadVertices(vs, src, 0, 0, w, h, 0.5, 0, 0, 0.5, 0, 0, 1, 1, 1, 1) } is := graphics.QuadIndices() s.DrawTriangles(src, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterLinear, graphics.AddressClampToZero) @@ -356,7 +356,7 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error { if level == 0 { src := img.mipmap.original() vs := vertexSlice(4) - src.PutQuadVertices(vs, bounds.Min.X, bounds.Min.Y, bounds.Max.X, bounds.Max.Y, a, b, c, d, tx, ty, cr, cg, cb, ca) + graphics.PutQuadVertices(vs, src, bounds.Min.X, bounds.Min.Y, bounds.Max.X, bounds.Max.Y, a, b, c, d, tx, ty, cr, cg, cb, ca) is := graphics.QuadIndices() i.mipmap.original().DrawTriangles(src, vs, is, colorm, mode, filter, graphics.AddressClampToZero) } else if src := img.mipmap.level(bounds, level); src != nil { @@ -367,7 +367,7 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error { c *= float32(s) d *= float32(s) vs := vertexSlice(4) - src.PutQuadVertices(vs, 0, 0, w, h, a, b, c, d, tx, ty, cr, cg, cb, ca) + graphics.PutQuadVertices(vs, src, 0, 0, w, h, a, b, c, d, tx, ty, cr, cg, cb, ca) is := graphics.QuadIndices() i.mipmap.original().DrawTriangles(src, vs, is, colorm, mode, filter, graphics.AddressClampToZero) } diff --git a/internal/shareable/shareable.go b/internal/shareable/shareable.go index c88a8af8a..37f7d18cb 100644 --- a/internal/shareable/shareable.go +++ b/internal/shareable/shareable.go @@ -175,7 +175,7 @@ func (i *Image) ensureNotShared() { _, _, w, h := i.region() newImg := restorable.NewImage(w, h) vs := make([]float32, 4*graphics.VertexFloatNum) - i.PutQuadVertices(vs, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1) + graphics.PutQuadVertices(vs, i, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1) is := graphics.QuadIndices() newImg.DrawTriangles(i.backend.restorable, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero) @@ -230,14 +230,6 @@ func (i *Image) Size() (width, height int) { return i.width, i.height } -// PutQuadVertices puts the given dst with vertices for rendering a quad. -func (i *Image) PutQuadVertices(dst []float32, sx0, sy0, sx1, sy1 int, a, b, c, d, tx, ty float32, cr, cg, cb, ca float32) { - if i.backend == nil { - i.allocate(true) - } - graphics.PutQuadVertices(dst, i, sx0, sy0, sx1, sy1, a, b, c, d, tx, ty, cr, cg, cb, ca) -} - // PutVertices puts the given dst with vertices that can be passed to DrawTriangles. func (i *Image) PutVertex(dst []float32, dx, dy, sx, sy float32, bx0, by0, bx1, by1 float32, cr, cg, cb, ca float32) { if i.backend == nil { diff --git a/internal/shareable/shareable_test.go b/internal/shareable/shareable_test.go index e918cf0b6..88f9147da 100644 --- a/internal/shareable/shareable_test.go +++ b/internal/shareable/shareable_test.go @@ -85,7 +85,7 @@ func TestEnsureNotShared(t *testing.T) { ) // img4.ensureNotShared() should be called. vs := make([]float32, 4*graphics.VertexFloatNum) - img3.PutQuadVertices(vs, 0, 0, size/2, size/2, 1, 0, 0, 1, size/4, size/4, 1, 1, 1, 1) + graphics.PutQuadVertices(vs, img3, 0, 0, size/2, size/2, 1, 0, 0, 1, size/4, size/4, 1, 1, 1, 1) is := graphics.QuadIndices() img4.DrawTriangles(img3, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero) want := false @@ -150,7 +150,7 @@ func TestReshared(t *testing.T) { // Use img1 as a render target. vs := make([]float32, 4*graphics.VertexFloatNum) - img2.PutQuadVertices(vs, 0, 0, size, size, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1) + graphics.PutQuadVertices(vs, img2, 0, 0, size, size, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1) is := graphics.QuadIndices() img1.DrawTriangles(img2, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero) if got, want := img1.IsSharedForTesting(), false; got != want { @@ -277,7 +277,7 @@ func TestReplacePixelsAfterDrawTriangles(t *testing.T) { src.ReplacePixels(pix) vs := make([]float32, 4*graphics.VertexFloatNum) - src.PutQuadVertices(vs, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1) + graphics.PutQuadVertices(vs, src, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1) is := graphics.QuadIndices() dst.DrawTriangles(src, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero) dst.ReplacePixels(pix)