mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
graphics: Add Image.noSave
This commit is contained in:
parent
fb8b6e93e5
commit
0519c69c13
@ -48,6 +48,8 @@ func (c *graphicsContext) SetSize(screenWidth, screenHeight int, screenScale flo
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
offscreen.impl.noSave = true
|
||||
|
||||
intScreenScale := int(math.Ceil(screenScale))
|
||||
w := screenWidth * intScreenScale
|
||||
h := screenHeight * intScreenScale
|
||||
@ -55,13 +57,17 @@ func (c *graphicsContext) SetSize(screenWidth, screenHeight int, screenScale flo
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
offscreen2.impl.noSave = true
|
||||
|
||||
w = int(float64(screenWidth) * screenScale)
|
||||
h = int(float64(screenHeight) * screenScale)
|
||||
c.screen, err = newImageWithScreenFramebuffer(w, h)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.screen.impl.noSave = true
|
||||
c.screen.Clear()
|
||||
|
||||
c.offscreen = offscreen
|
||||
c.offscreen2 = offscreen2
|
||||
c.screenScale = screenScale
|
||||
@ -148,12 +154,7 @@ func (c *graphicsContext) UpdateAndDraw() error {
|
||||
if err := c.drawToDefaultRenderTarget(); err != nil {
|
||||
return err
|
||||
}
|
||||
exceptions := map[*imageImpl]struct{}{
|
||||
c.offscreen.impl: {},
|
||||
c.offscreen2.impl: {},
|
||||
c.screen.impl: {},
|
||||
}
|
||||
if err := theImages.savePixels(ui.GLContext(), exceptions); err != nil {
|
||||
if err := theImages.savePixels(ui.GLContext()); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
15
image.go
15
image.go
@ -57,16 +57,10 @@ func (i *images) remove(img *Image) {
|
||||
delete(i.images, img.impl)
|
||||
}
|
||||
|
||||
func (i *images) savePixels(context *opengl.Context, exceptions map[*imageImpl]struct{}) error {
|
||||
func (i *images) savePixels(context *opengl.Context) error {
|
||||
i.m.Lock()
|
||||
defer i.m.Unlock()
|
||||
for img := range i.images {
|
||||
if _, ok := exceptions[img]; ok {
|
||||
continue
|
||||
}
|
||||
if img.isDisposed() {
|
||||
continue
|
||||
}
|
||||
if err := img.savePixels(context); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -200,6 +194,7 @@ type imageImpl struct {
|
||||
height int
|
||||
filter Filter
|
||||
pixels []uint8
|
||||
noSave bool
|
||||
}
|
||||
|
||||
func (i *imageImpl) Fill(clr color.Color) error {
|
||||
@ -275,6 +270,12 @@ func (i *imageImpl) At(x, y int) color.Color {
|
||||
}
|
||||
|
||||
func (i *imageImpl) savePixels(context *opengl.Context) error {
|
||||
if i.noSave {
|
||||
return nil
|
||||
}
|
||||
if i.disposed {
|
||||
return nil
|
||||
}
|
||||
if i.pixels != nil {
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user