graphics: Less calls of ReadPixelsFromVRAM

This commit is contained in:
Hajime Hoshi 2016-08-20 23:25:45 +09:00
parent 7a1d63fb02
commit c54dc8ee1c
2 changed files with 5 additions and 12 deletions

View File

@ -212,19 +212,12 @@ func (i *imageImpl) resetPixelsIfDependingOn(target *imageImpl, context *opengl.
if target.isDisposed() {
return errors.New("ebiten: target is already disposed")
}
// target is an image begin tried to mutate.
// target is an image that is about to be tried mutating.
// If pixels object is related to that image, the pixels must be reset.
if !i.pixels.DependsOn(target.image) {
return nil
}
if context == nil || i.volatile {
// context is nil when this is not initialized yet.
i.pixels.MakeStale()
return nil
}
if err := i.pixels.ReadPixelsFromVRAM(i.image, context); err != nil {
return err
}
i.pixels.MakeStale()
return nil
}

View File

@ -91,7 +91,7 @@ func (p *Pixels) AppendDrawImageHistory(image *graphics.Image, vertices []int16,
// This means Pixels members must match with acutal state in VRAM.
func (p *Pixels) At(idx int, image *graphics.Image, context *opengl.Context) (color.Color, error) {
if p.basePixels == nil || p.drawImageHistory != nil || p.stale {
if err := p.ReadPixelsFromVRAM(image, context); err != nil {
if err := p.readPixelsFromVRAM(image, context); err != nil {
return nil, err
}
}
@ -111,7 +111,7 @@ func (p *Pixels) DependsOn(target *graphics.Image) bool {
return false
}
func (p *Pixels) ReadPixelsFromVRAM(image *graphics.Image, context *opengl.Context) error {
func (p *Pixels) readPixelsFromVRAM(image *graphics.Image, context *opengl.Context) error {
var err error
p.basePixels, err = image.Pixels(context)
if err != nil {
@ -127,7 +127,7 @@ func (p *Pixels) ReadPixelsFromVRAMIfStale(image *graphics.Image, context *openg
if !p.stale {
return nil
}
return p.ReadPixelsFromVRAM(image, context)
return p.readPixelsFromVRAM(image, context)
}
func (p *Pixels) HasDependency() bool {