mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
graphics: Refactoring: Add pixelCommand
This commit is contained in:
parent
aa06c5ffa5
commit
a9a21132ae
@ -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
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user