mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
pixels: Rename fuctions
This commit is contained in:
parent
558f559323
commit
0fc61ed568
@ -140,7 +140,7 @@ func (c *graphicsContext) UpdateAndDraw(context *opengl.Context, updateCount int
|
||||
if err := c.initializeIfNeeded(context); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := theImagesForRestoring.resetPixels(context); err != nil {
|
||||
if err := theImagesForRestoring.ensurePixels(context); err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 0; i < updateCount; i++ {
|
||||
|
4
image.go
4
image.go
@ -63,11 +63,11 @@ func (i *images) remove(img *Image) {
|
||||
runtime.SetFinalizer(img, nil)
|
||||
}
|
||||
|
||||
func (i *images) resetPixels(context *opengl.Context) error {
|
||||
func (i *images) ensurePixels(context *opengl.Context) error {
|
||||
i.m.Lock()
|
||||
defer i.m.Unlock()
|
||||
for img := range i.images {
|
||||
if err := img.resetPixels(context); err != nil {
|
||||
if err := img.ensurePixels(context); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
10
imageimpl.go
10
imageimpl.go
@ -53,7 +53,7 @@ func newImageImpl(width, height int, filter Filter, volatile bool) (*imageImpl,
|
||||
volatile: volatile,
|
||||
pixels: pixels.NewPixels(img),
|
||||
}
|
||||
i.pixels.ResetWithPixels(make([]uint8, width*height*4))
|
||||
i.pixels.ReplacePixels(make([]uint8, width*height*4))
|
||||
runtime.SetFinalizer(i, (*imageImpl).Dispose)
|
||||
return i, nil
|
||||
}
|
||||
@ -86,7 +86,7 @@ func newImageImplFromImage(source image.Image, filter Filter) (*imageImpl, error
|
||||
filter: filter,
|
||||
pixels: pixels.NewPixels(img),
|
||||
}
|
||||
i.pixels.ResetWithPixels(p)
|
||||
i.pixels.ReplacePixels(p)
|
||||
runtime.SetFinalizer(i, (*imageImpl).Dispose)
|
||||
return i, nil
|
||||
}
|
||||
@ -104,7 +104,7 @@ func newScreenImageImpl(width, height int) (*imageImpl, error) {
|
||||
screen: true,
|
||||
pixels: pixels.NewPixels(img),
|
||||
}
|
||||
i.pixels.ResetWithPixels(make([]uint8, width*height*4))
|
||||
i.pixels.ReplacePixels(make([]uint8, width*height*4))
|
||||
runtime.SetFinalizer(i, (*imageImpl).Dispose)
|
||||
return i, nil
|
||||
}
|
||||
@ -198,7 +198,7 @@ func (i *imageImpl) At(x, y int, context *opengl.Context) color.Color {
|
||||
return clr
|
||||
}
|
||||
|
||||
func (i *imageImpl) resetPixels(context *opengl.Context) error {
|
||||
func (i *imageImpl) ensurePixels(context *opengl.Context) error {
|
||||
i.m.Lock()
|
||||
defer i.m.Unlock()
|
||||
if i.disposed {
|
||||
@ -305,7 +305,7 @@ func (i *imageImpl) ReplacePixels(p []uint8) error {
|
||||
if i.pixels == nil {
|
||||
i.pixels = pixels.NewPixels(i.image)
|
||||
}
|
||||
i.pixels.ResetWithPixels(p)
|
||||
i.pixels.ReplacePixels(p)
|
||||
if i.disposed {
|
||||
return errors.New("ebiten: image is already disposed")
|
||||
}
|
||||
|
@ -46,15 +46,6 @@ func NewPixels(image *graphics.Image) *Pixels {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Pixels) ResetWithPixels(pixels []uint8) {
|
||||
if p.basePixels == nil {
|
||||
p.basePixels = make([]uint8, len(pixels))
|
||||
}
|
||||
copy(p.basePixels, pixels)
|
||||
p.baseColor = nil
|
||||
p.drawImageHistory = nil
|
||||
}
|
||||
|
||||
func (p *Pixels) Clear() {
|
||||
p.basePixels = nil
|
||||
p.baseColor = nil
|
||||
@ -67,6 +58,15 @@ func (p *Pixels) Fill(clr color.Color) {
|
||||
p.drawImageHistory = nil
|
||||
}
|
||||
|
||||
func (p *Pixels) ReplacePixels(pixels []uint8) {
|
||||
if p.basePixels == nil {
|
||||
p.basePixels = make([]uint8, len(pixels))
|
||||
}
|
||||
copy(p.basePixels, pixels)
|
||||
p.baseColor = nil
|
||||
p.drawImageHistory = nil
|
||||
}
|
||||
|
||||
func (p *Pixels) AppendDrawImageHistory(image *graphics.Image, vertices []int16, geom graphics.Matrix, colorm graphics.Matrix, mode opengl.CompositeMode) {
|
||||
item := &drawImageHistoryItem{
|
||||
image: image,
|
||||
|
Loading…
Reference in New Issue
Block a user