mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
graphics: Less calls of ReadPixelsFromVRAM
This commit is contained in:
parent
7a1d63fb02
commit
c54dc8ee1c
@ -212,21 +212,14 @@ func (i *imageImpl) resetPixelsIfDependingOn(target *imageImpl, context *opengl.
|
|||||||
if target.isDisposed() {
|
if target.isDisposed() {
|
||||||
return errors.New("ebiten: target is already disposed")
|
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 pixels object is related to that image, the pixels must be reset.
|
||||||
if !i.pixels.DependsOn(target.image) {
|
if !i.pixels.DependsOn(target.image) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if context == nil || i.volatile {
|
|
||||||
// context is nil when this is not initialized yet.
|
|
||||||
i.pixels.MakeStale()
|
i.pixels.MakeStale()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err := i.pixels.ReadPixelsFromVRAM(i.image, context); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *imageImpl) hasDependency() bool {
|
func (i *imageImpl) hasDependency() bool {
|
||||||
i.m.Lock()
|
i.m.Lock()
|
||||||
|
@ -91,7 +91,7 @@ func (p *Pixels) AppendDrawImageHistory(image *graphics.Image, vertices []int16,
|
|||||||
// This means Pixels members must match with acutal state in VRAM.
|
// 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) {
|
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 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
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ func (p *Pixels) DependsOn(target *graphics.Image) bool {
|
|||||||
return false
|
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
|
var err error
|
||||||
p.basePixels, err = image.Pixels(context)
|
p.basePixels, err = image.Pixels(context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -127,7 +127,7 @@ func (p *Pixels) ReadPixelsFromVRAMIfStale(image *graphics.Image, context *openg
|
|||||||
if !p.stale {
|
if !p.stale {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return p.ReadPixelsFromVRAM(image, context)
|
return p.readPixelsFromVRAM(image, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Pixels) HasDependency() bool {
|
func (p *Pixels) HasDependency() bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user