mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
graphics: Remove pixels when inconsistent
This commit is contained in:
parent
1ec503e1b5
commit
558f559323
@ -95,9 +95,6 @@ func (c *graphicsContext) initializeIfNeeded(context *opengl.Context) error {
|
||||
if err := graphics.Reset(context); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := theImagesForRestoring.resetPixels(context); err != nil {
|
||||
return err
|
||||
}
|
||||
atomic.StoreInt32(&c.initialized, 1)
|
||||
}
|
||||
r, err := c.needsRestoring(context)
|
||||
@ -110,7 +107,6 @@ func (c *graphicsContext) initializeIfNeeded(context *opengl.Context) error {
|
||||
if err := c.restore(context); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -144,6 +140,9 @@ 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 {
|
||||
return err
|
||||
}
|
||||
for i := 0; i < updateCount; i++ {
|
||||
if err := theImagesForRestoring.clearVolatileImages(); err != nil {
|
||||
return err
|
||||
|
22
imageimpl.go
22
imageimpl.go
@ -115,6 +115,9 @@ func (i *imageImpl) Fill(clr color.Color) error {
|
||||
if i.disposed {
|
||||
return errors.New("ebiten: image is already disposed")
|
||||
}
|
||||
if i.pixels == nil {
|
||||
i.pixels = pixels.NewPixels(i.image)
|
||||
}
|
||||
i.pixels.Fill(clr)
|
||||
return i.image.Fill(clr)
|
||||
}
|
||||
@ -128,6 +131,9 @@ func (i *imageImpl) clearIfVolatile() error {
|
||||
if !i.volatile {
|
||||
return nil
|
||||
}
|
||||
if i.pixels == nil {
|
||||
i.pixels = pixels.NewPixels(i.image)
|
||||
}
|
||||
i.pixels.Clear()
|
||||
return i.image.Fill(color.Transparent)
|
||||
}
|
||||
@ -165,8 +171,10 @@ func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error {
|
||||
}
|
||||
geom := options.GeoM
|
||||
colorm := options.ColorM
|
||||
i.pixels.AppendDrawImageHistory(image.impl.image, vertices, &geom, &colorm, opengl.CompositeMode(options.CompositeMode))
|
||||
mode := opengl.CompositeMode(options.CompositeMode)
|
||||
if i.pixels != nil {
|
||||
i.pixels.AppendDrawImageHistory(image.impl.image, vertices, &geom, &colorm, mode)
|
||||
}
|
||||
if err := i.image.DrawImage(image.impl.image, vertices, &geom, &colorm, mode); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -196,6 +204,10 @@ func (i *imageImpl) resetPixels(context *opengl.Context) error {
|
||||
if i.disposed {
|
||||
return nil
|
||||
}
|
||||
if i.pixels != nil {
|
||||
return nil
|
||||
}
|
||||
i.pixels = pixels.NewPixels(i.image)
|
||||
if err := i.pixels.Reset(context); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -216,7 +228,7 @@ func (i *imageImpl) resetPixelsIfNeeded(target *imageImpl, context *opengl.Conte
|
||||
}
|
||||
if context == nil {
|
||||
// context is null when this is not initialized yet.
|
||||
// In this case, pixels is inconsistent with the image.
|
||||
i.pixels = nil
|
||||
return nil
|
||||
}
|
||||
if err := i.pixels.ResetIfNeeded(target.image, context); err != nil {
|
||||
@ -228,6 +240,9 @@ func (i *imageImpl) resetPixelsIfNeeded(target *imageImpl, context *opengl.Conte
|
||||
func (i *imageImpl) hasHistory() bool {
|
||||
i.m.Lock()
|
||||
defer i.m.Unlock()
|
||||
if i.pixels == nil {
|
||||
return false
|
||||
}
|
||||
return i.pixels.HasHistory()
|
||||
}
|
||||
|
||||
@ -287,6 +302,9 @@ func (i *imageImpl) ReplacePixels(p []uint8) error {
|
||||
}
|
||||
i.m.Lock()
|
||||
defer i.m.Unlock()
|
||||
if i.pixels == nil {
|
||||
i.pixels = pixels.NewPixels(i.image)
|
||||
}
|
||||
i.pixels.ResetWithPixels(p)
|
||||
if i.disposed {
|
||||
return errors.New("ebiten: image is already disposed")
|
||||
|
@ -31,10 +31,6 @@ type drawImageHistoryItem struct {
|
||||
}
|
||||
|
||||
// Pixels represents pixels of an image for restoring when GL context is lost.
|
||||
//
|
||||
// Until GL context is available,
|
||||
// Pixels member states might not match with actual pixels in GPU so
|
||||
// there is few function to retrieve the current state.
|
||||
type Pixels struct {
|
||||
image *graphics.Image
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user