diff --git a/internal/graphics/command.go b/internal/graphics/command.go index 0c73dd340..acd1539cb 100644 --- a/internal/graphics/command.go +++ b/internal/graphics/command.go @@ -309,6 +309,43 @@ func (c *replacePixelsCommand) CanMerge(dst, src *Image, color *affine.ColorM, m return false } +type pixelsCommand struct { + result []byte + img *Image +} + +// Exec executes a pixelsCommand. +func (c *pixelsCommand) Exec(indexOffsetInBytes int) error { + f, err := c.img.createFramebufferIfNeeded() + if err != nil { + return err + } + p, err := opengl.GetContext().FramebufferPixels(f.native, c.img.width, c.img.height) + if err != nil { + return err + } + c.result = p + return nil +} + +func (c *pixelsCommand) NumVertices() int { + return 0 +} + +func (c *pixelsCommand) NumIndices() int { + return 0 +} + +func (c *pixelsCommand) AddNumVertices(n int) { +} + +func (c *pixelsCommand) AddNumIndices(n int) { +} + +func (c *pixelsCommand) CanMerge(dst, src *Image, color *affine.ColorM, mode opengl.CompositeMode, filter Filter) bool { + return false +} + // disposeCommand represents a command to dispose an image. type disposeCommand struct { target *Image diff --git a/internal/graphics/image.go b/internal/graphics/image.go index 7ab2dd773..c32605fab 100644 --- a/internal/graphics/image.go +++ b/internal/graphics/image.go @@ -91,15 +91,14 @@ func (i *Image) DrawImage(src *Image, vertices []float32, indices []uint16, clr } func (i *Image) Pixels() ([]byte, error) { - // Flush the enqueued commands so that pixels are certainly read. + c := &pixelsCommand{ + img: i, + } + theCommandQueue.Enqueue(c) if err := theCommandQueue.Flush(); err != nil { return nil, err } - f, err := i.createFramebufferIfNeeded() - if err != nil { - return nil, err - } - return opengl.GetContext().FramebufferPixels(f.native, i.width, i.height) + return c.result, nil } func (i *Image) ReplacePixels(p []byte, x, y, width, height int) {