mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
graphics: Less calls of ReadPixelsFromVRAM
This commit is contained in:
parent
7a1d63fb02
commit
c54dc8ee1c
11
imageimpl.go
11
imageimpl.go
@ -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
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user