fixed overlapping alpha
This commit is contained in:
parent
9edbb8da85
commit
a0a1adef12
2 changed files with 13 additions and 4 deletions
|
@ -20,11 +20,20 @@ func (b *SoftwareBackend) Clear(pts [4][2]float64) {
|
|||
}
|
||||
|
||||
func (b *SoftwareBackend) Fill(style *backendbase.FillStyle, pts [][2]float64) {
|
||||
p2 := b.mask.Pix
|
||||
for i := range p2 {
|
||||
p2[i] = 0
|
||||
}
|
||||
|
||||
iterateTriangles(pts[:], func(tri [][2]float64) {
|
||||
b.fillTriangle(tri, func(x, y int) {
|
||||
if b.clip.AlphaAt(x, y).A == 0 {
|
||||
return
|
||||
}
|
||||
if b.mask.AlphaAt(x, y).A > 0 {
|
||||
return
|
||||
}
|
||||
b.mask.SetAlpha(x, y, color.Alpha{A: 255})
|
||||
b.Image.SetRGBA(x, y, mix(style.Color, b.Image.RGBAAt(x, y)))
|
||||
})
|
||||
})
|
||||
|
@ -90,14 +99,14 @@ func (b *SoftwareBackend) ClearClip() {
|
|||
}
|
||||
|
||||
func (b *SoftwareBackend) Clip(pts [][2]float64) {
|
||||
p2 := b.clip2.Pix
|
||||
p2 := b.mask.Pix
|
||||
for i := range p2 {
|
||||
p2[i] = 0
|
||||
}
|
||||
|
||||
iterateTriangles(pts[:], func(tri [][2]float64) {
|
||||
b.fillTriangle(tri, func(x, y int) {
|
||||
b.clip2.SetAlpha(x, y, color.Alpha{A: 255})
|
||||
b.mask.SetAlpha(x, y, color.Alpha{A: 255})
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
type SoftwareBackend struct {
|
||||
Image *image.RGBA
|
||||
clip *image.Alpha
|
||||
clip2 *image.Alpha
|
||||
mask *image.Alpha
|
||||
w, h int
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ func (b *SoftwareBackend) SetSize(w, h int) {
|
|||
b.w, b.h = w, h
|
||||
b.Image = image.NewRGBA(image.Rect(0, 0, w, h))
|
||||
b.clip = image.NewAlpha(image.Rect(0, 0, w, h))
|
||||
b.clip2 = image.NewAlpha(image.Rect(0, 0, w, h))
|
||||
b.mask = image.NewAlpha(image.Rect(0, 0, w, h))
|
||||
b.ClearClip()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue