Revert "internal/restorable: integrate Image.DrawTriangles into internal/atlas"

This reverts commit 3ee905bc4d.

Updates #3083
This commit is contained in:
Hajime Hoshi 2024-09-06 14:06:39 +09:00
parent d733308eb1
commit 17a5488c49
2 changed files with 32 additions and 10 deletions

View File

@ -372,11 +372,6 @@ func (i *Image) DrawTriangles(srcs [graphics.ShaderSrcImageCount]*Image, vertice
} }
func (i *Image) drawTriangles(srcs [graphics.ShaderSrcImageCount]*Image, vertices []float32, indices []uint32, blend graphicsdriver.Blend, dstRegion image.Rectangle, srcRegions [graphics.ShaderSrcImageCount]image.Rectangle, shader *Shader, uniforms []uint32, fillRule graphicsdriver.FillRule) { func (i *Image) drawTriangles(srcs [graphics.ShaderSrcImageCount]*Image, vertices []float32, indices []uint32, blend graphicsdriver.Blend, dstRegion image.Rectangle, srcRegions [graphics.ShaderSrcImageCount]image.Rectangle, shader *Shader, uniforms []uint32, fillRule graphicsdriver.FillRule) {
if len(vertices) == 0 {
return
}
// This slice is not escaped to the heap. This can be checked by `go build -gcflags=-m`.
backends := make([]*backend, 0, len(srcs)) backends := make([]*backend, 0, len(srcs))
for _, src := range srcs { for _, src := range srcs {
if src == nil { if src == nil {
@ -449,15 +444,15 @@ func (i *Image) drawTriangles(srcs [graphics.ShaderSrcImageCount]*Image, vertice
srcRegions[i] = srcRegions[i].Add(r.Min) srcRegions[i] = srcRegions[i].Add(r.Min)
} }
var imgs [graphics.ShaderSrcImageCount]*graphicscommand.Image var imgs [graphics.ShaderSrcImageCount]*restorable.Image
for i, src := range srcs { for i, src := range srcs {
if src == nil { if src == nil {
continue continue
} }
imgs[i] = src.backend.restorable.Image imgs[i] = src.backend.restorable
} }
i.backend.restorable.Image.DrawTriangles(imgs, vertices, indices, blend, dstRegion, srcRegions, shader.ensureShader().Shader, uniforms, fillRule) i.backend.restorable.DrawTriangles(imgs, vertices, indices, blend, dstRegion, srcRegions, shader.ensureShader(), uniforms, fillRule)
for _, src := range srcs { for _, src := range srcs {
if src == nil { if src == nil {

View File

@ -66,13 +66,13 @@ 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 // Use DrawTriangles instead of WritePixels because the image i might be stale and not have its pixels
// information. // information.
srcs := [graphics.ShaderSrcImageCount]*graphicscommand.Image{i.Image} srcs := [graphics.ShaderSrcImageCount]*Image{i}
sw, sh := i.Image.InternalSize() sw, sh := i.Image.InternalSize()
vs := make([]float32, 4*graphics.VertexFloatCount) vs := make([]float32, 4*graphics.VertexFloatCount)
graphics.QuadVerticesFromDstAndSrc(vs, 0, 0, float32(sw), float32(sh), 0, 0, float32(sw), float32(sh), 1, 1, 1, 1) graphics.QuadVerticesFromDstAndSrc(vs, 0, 0, float32(sw), float32(sh), 0, 0, float32(sw), float32(sh), 1, 1, 1, 1)
is := graphics.QuadIndices() is := graphics.QuadIndices()
dr := image.Rect(0, 0, sw, sh) dr := image.Rect(0, 0, sw, sh)
newImg.Image.DrawTriangles(srcs, vs, is, graphicsdriver.BlendCopy, dr, [graphics.ShaderSrcImageCount]image.Rectangle{}, NearestFilterShader.Shader, nil, graphicsdriver.FillRuleFillAll) newImg.DrawTriangles(srcs, vs, is, graphicsdriver.BlendCopy, dr, [graphics.ShaderSrcImageCount]image.Rectangle{}, NearestFilterShader, nil, graphicsdriver.FillRuleFillAll)
i.Image.Dispose() i.Image.Dispose()
i.Image = nil i.Image = nil
@ -108,3 +108,30 @@ func (i *Image) WritePixels(pixels *graphics.ManagedBytes, region image.Rectangl
i.Image.WritePixels(pixels, region) 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.ShaderSrcImageCount]*Image, vertices []float32, indices []uint32, blend graphicsdriver.Blend, dstRegion image.Rectangle, srcRegions [graphics.ShaderSrcImageCount]image.Rectangle, shader *Shader, uniforms []uint32, fillRule graphicsdriver.FillRule) {
if len(vertices) == 0 {
return
}
var imgs [graphics.ShaderSrcImageCount]*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)
}