internal/ui: reland: refactoring: improve anti-alias logic

* Remove the image extension. The image is always flushed when necessary.
* Use a small offscreen image whichever the blend is.

Updates #2399
This commit is contained in:
Hajime Hoshi 2023-02-19 22:12:27 +09:00
parent f6b48cb57c
commit d91b8cae88

View File

@ -339,30 +339,10 @@ func (i *bigOffscreenImage) drawTriangles(srcs [graphics.ShaderImageCount]*Image
} }
i.blend = blend i.blend = blend
// If the new region doesn't match with the current region, extend the buffer image. // If the new region doesn't match with the current region, remove the buffer image and recreate it later.
if r := i.requiredRegion(vertices); i.region != r { if r := i.requiredRegion(vertices); i.region != r {
if i.image != nil { i.flush()
img := i.image i.image = nil
i.image = NewImage(int(r.Width)*bigOffscreenScale, int(r.Height)*bigOffscreenScale, i.imageType)
srcs := [graphics.ShaderImageCount]*Image{img}
// TODO: Should we keep vertices like tmpVerticesForCopying?
vertices := make([]float32, 4*graphics.VertexFloatCount)
graphics.QuadVertices(
vertices,
0, 0, i.region.Width*bigOffscreenScale, i.region.Height*bigOffscreenScale,
1, 0, 0, 1, (i.region.X-r.X)*bigOffscreenScale, (i.region.Y-r.Y)*bigOffscreenScale,
1, 1, 1, 1)
is := graphics.QuadIndices()
dstRegion := graphicsdriver.Region{
X: 0,
Y: 0,
Width: r.Width * bigOffscreenScale,
Height: r.Height * bigOffscreenScale,
}
i.image.DrawTriangles(srcs, vertices, is, graphicsdriver.BlendCopy, dstRegion, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, NearestFilterShader, nil, false, true, false)
img.MarkDisposed()
}
i.region = r i.region = r
} }
@ -379,15 +359,15 @@ func (i *bigOffscreenImage) drawTriangles(srcs [graphics.ShaderImageCount]*Image
// i.tmpVerticesForCopying can be resused as this is sent to DrawTriangles immediately. // i.tmpVerticesForCopying can be resused as this is sent to DrawTriangles immediately.
graphics.QuadVertices( graphics.QuadVertices(
i.tmpVerticesForCopying, i.tmpVerticesForCopying,
0, 0, float32(i.orig.width), float32(i.orig.height), i.region.X, i.region.Y, i.region.X+i.region.Width, i.region.Y+i.region.Height,
bigOffscreenScale, 0, 0, bigOffscreenScale, 0, 0, bigOffscreenScale, 0, 0, bigOffscreenScale, 0, 0,
1, 1, 1, 1) 1, 1, 1, 1)
is := graphics.QuadIndices() is := graphics.QuadIndices()
dstRegion := graphicsdriver.Region{ dstRegion := graphicsdriver.Region{
X: 0, X: 0,
Y: 0, Y: 0,
Width: float32(i.orig.width * bigOffscreenScale), Width: i.region.Width * bigOffscreenScale,
Height: float32(i.orig.height * bigOffscreenScale), Height: i.region.Height * bigOffscreenScale,
} }
i.image.DrawTriangles(srcs, i.tmpVerticesForCopying, is, graphicsdriver.BlendCopy, dstRegion, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, NearestFilterShader, nil, false, true, false) i.image.DrawTriangles(srcs, i.tmpVerticesForCopying, is, graphicsdriver.BlendCopy, dstRegion, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, NearestFilterShader, nil, false, true, false)
} }
@ -441,15 +421,6 @@ func (i *bigOffscreenImage) flush() {
} }
func (i *bigOffscreenImage) requiredRegion(vertices []float32) graphicsdriver.Region { func (i *bigOffscreenImage) requiredRegion(vertices []float32) graphicsdriver.Region {
if i.blend != graphicsdriver.BlendSourceOver {
return graphicsdriver.Region{
X: 0,
Y: 0,
Width: float32(i.orig.width),
Height: float32(i.orig.height),
}
}
minX := float32(i.orig.width) minX := float32(i.orig.width)
minY := float32(i.orig.height) minY := float32(i.orig.height)
maxX := float32(0) maxX := float32(0)