mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +01:00
graphics: Refactoring
This commit is contained in:
parent
3c18e992a3
commit
d5e6e6893e
@ -15,6 +15,7 @@
|
|||||||
package ebiten
|
package ebiten
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"image/color"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/clock"
|
"github.com/hajimehoshi/ebiten/internal/clock"
|
||||||
@ -98,7 +99,7 @@ func (c *graphicsContext) Update(afterFrameUpdate func()) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for i := 0; i < updateCount; i++ {
|
for i := 0; i < updateCount; i++ {
|
||||||
c.offscreen.fill(0, 0, 0, 0)
|
c.offscreen.Fill(color.Transparent)
|
||||||
// Mipmap images should be disposed by fill.
|
// Mipmap images should be disposed by fill.
|
||||||
|
|
||||||
setDrawingSkipped(i < updateCount-1)
|
setDrawingSkipped(i < updateCount-1)
|
||||||
|
29
image.go
29
image.go
@ -169,17 +169,7 @@ func (i *Image) isSubimage() bool {
|
|||||||
//
|
//
|
||||||
// Clear always returns nil as of 1.5.0-alpha.
|
// Clear always returns nil as of 1.5.0-alpha.
|
||||||
func (i *Image) Clear() error {
|
func (i *Image) Clear() error {
|
||||||
i.copyCheck()
|
i.Fill(color.Transparent)
|
||||||
if i.isDisposed() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Implement this.
|
|
||||||
if i.isSubimage() {
|
|
||||||
panic("render to a subimage is not implemented")
|
|
||||||
}
|
|
||||||
|
|
||||||
i.fill(0, 0, 0, 0)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,20 +189,10 @@ func (i *Image) Fill(clr color.Color) error {
|
|||||||
panic("render to a subimage is not implemented")
|
panic("render to a subimage is not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
r, g, b, a := clr.RGBA()
|
r16, g16, b16, a16 := clr.RGBA()
|
||||||
i.fill(uint8(r>>8), uint8(g>>8), uint8(b>>8), uint8(a>>8))
|
r, g, b, a := uint8(r16>>8), uint8(g16>>8), uint8(b16>>8), uint8(a16>>8)
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *Image) fill(r, g, b, a uint8) {
|
|
||||||
if r == 0 && g == 0 && b == 0 && a == 0 {
|
|
||||||
i.mipmap.original().ReplacePixels(nil)
|
|
||||||
i.disposeMipmaps()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
wd, hd := i.Size()
|
wd, hd := i.Size()
|
||||||
|
|
||||||
if wd*hd <= 256 {
|
if wd*hd <= 256 {
|
||||||
// Prefer ReplacePixels since ReplacePixels can keep the images shared.
|
// Prefer ReplacePixels since ReplacePixels can keep the images shared.
|
||||||
pix := make([]uint8, 4*wd*hd)
|
pix := make([]uint8, 4*wd*hd)
|
||||||
@ -223,7 +203,7 @@ func (i *Image) fill(r, g, b, a uint8) {
|
|||||||
pix[4*i+3] = a
|
pix[4*i+3] = a
|
||||||
}
|
}
|
||||||
i.ReplacePixels(pix)
|
i.ReplacePixels(pix)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ws, hs := emptyImage.Size()
|
ws, hs := emptyImage.Size()
|
||||||
@ -241,6 +221,7 @@ func (i *Image) fill(r, g, b, a uint8) {
|
|||||||
op.CompositeMode = CompositeModeCopy
|
op.CompositeMode = CompositeModeCopy
|
||||||
op.Filter = FilterNearest
|
op.Filter = FilterNearest
|
||||||
i.drawImage(emptyImage, op)
|
i.drawImage(emptyImage, op)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) disposeMipmaps() {
|
func (i *Image) disposeMipmaps() {
|
||||||
|
Loading…
Reference in New Issue
Block a user