shareable: Use color vertex values instead of ColorM

This is an optimization: using ColorM might cause graphics command
separation.
This commit is contained in:
Hajime Hoshi 2019-02-10 14:01:48 +09:00
parent d818fc3b5a
commit 1150fc69d0

View File

@ -257,6 +257,17 @@ func (i *Image) DrawImage(img *Image, vertices []float32, indices []uint16, colo
// Do not call Fill on emptyImage or the program causes infinite recursion.
var emptyImage = NewImage(16, 16)
func init() {
// Initialize emptyImage. As emptyImage is used for Fill, emptyImage itself cannot be initialized with Fill.
// Call ReplacePixels instead.
w, h := emptyImage.Size()
pix := make([]byte, 4*w*h)
for i := range pix {
pix[i] = 0xff
}
emptyImage.ReplacePixels(pix)
}
// Fill fills the image with a color. This affects not only the (0, 0)-(width, height) region but also the whole
// framebuffer region.
func (i *Image) Fill(r, g, b, a uint8) {
@ -267,22 +278,25 @@ func (i *Image) Fill(r, g, b, a uint8) {
i.ensureNotShared()
backendsM.Unlock()
rf := float32(0)
gf := float32(0)
bf := float32(0)
af := float32(0)
if a > 0 {
rf = float32(r) / float32(a)
gf = float32(g) / float32(a)
bf = float32(b) / float32(a)
af = float32(a) / 0xff
}
dw, dh := i.backend.restorable.SizePowerOf2()
sw, sh := emptyImage.Size()
vs := emptyImage.QuadVertices(0, 0, sw, sh,
float32(dw)/float32(sw), 0, 0, float32(dh)/float32(sh), 0, 0,
1, 1, 1, 1)
rf, gf, bf, af)
is := graphics.QuadIndices()
var colorm *affine.ColorM
if a > 0 {
rf := float32(r) / float32(a)
gf := float32(g) / float32(a)
bf := float32(b) / float32(a)
af := float32(a) / 0xff
colorm = colorm.Translate(rf, gf, bf, af)
}
i.DrawImage(emptyImage, vs, is, colorm, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero)
i.DrawImage(emptyImage, vs, is, nil, graphics.CompositeModeCopy, graphics.FilterNearest, graphics.AddressClampToZero)
}
func (i *Image) ReplacePixels(p []byte) {