From 912d498cdf6b63a38c60ede88627b13a4cf03fd7 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 11 Jun 2016 05:48:09 +0900 Subject: [PATCH] graphics: Remove unused arguments --- graphicscontext.go | 1 + image.go | 12 ++++++------ internal/graphics/command.go | 4 ++++ internal/graphics/framebuffer.go | 13 +++---------- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/graphicscontext.go b/graphicscontext.go index ca694aa9c..6608b030b 100644 --- a/graphicscontext.go +++ b/graphicscontext.go @@ -84,6 +84,7 @@ func (c *graphicsContext) Update() error { if err := c.defaultRenderTarget.DrawImage(c.screen, options); err != nil { return err } + graphics.FlushCommands(ui.GLContext()) // Call glFlush to prevent black flicking (especially on Android (#226)). ui.GLContext().Flush() return nil diff --git a/image.go b/image.go index d59ee2e1a..fe73dc5c6 100644 --- a/image.go +++ b/image.go @@ -199,10 +199,10 @@ type imageImpl struct { texture *graphics.Texture defaultFramebuffer bool disposed bool - pixels []uint8 width int height int filter Filter + pixels []uint8 } func (i *imageImpl) Fill(clr color.Color) error { @@ -213,7 +213,7 @@ func (i *imageImpl) Fill(clr color.Color) error { return errors.New("ebiten: image is already disposed") } i.pixels = nil - return i.framebuffer.Fill(ui.GLContext(), clr) + return i.framebuffer.Fill(clr) } if theDelayedImageTasks.add(f) { return nil @@ -261,7 +261,7 @@ func (i *imageImpl) DrawImage(image *Image, options *DrawImageOptions) error { geom := &options.GeoM colorm := &options.ColorM mode := opengl.CompositeMode(options.CompositeMode) - if err := i.framebuffer.DrawTexture(ui.GLContext(), image.impl.texture, vertices[:16*n], geom, colorm, mode); err != nil { + if err := i.framebuffer.DrawTexture(image.impl.texture, vertices[:16*n], geom, colorm, mode); err != nil { return err } return nil @@ -373,12 +373,12 @@ func (i *imageImpl) ReplacePixels(p []uint8) error { f := func() error { imageM.Lock() defer imageM.Unlock() - // Don't set i.pixels here because i.pixels is used not every time. + // TODO: Copy p? i.pixels = nil if i.isDisposed() { return errors.New("ebiten: image is already disposed") } - return i.framebuffer.ReplacePixels(ui.GLContext(), i.texture, p) + return i.framebuffer.ReplacePixels(i.texture, p) } if theDelayedImageTasks.add(f) { return nil @@ -427,7 +427,7 @@ func NewImage(width, height int, filter Filter) (*Image, error) { image.framebuffer = framebuffer image.texture = texture runtime.SetFinalizer(image, (*imageImpl).Dispose) - if err := image.framebuffer.Fill(ui.GLContext(), color.Transparent); err != nil { + if err := image.framebuffer.Fill(color.Transparent); err != nil { return err } return nil diff --git a/internal/graphics/command.go b/internal/graphics/command.go index 499d48aa5..2d7e38ffd 100644 --- a/internal/graphics/command.go +++ b/internal/graphics/command.go @@ -66,6 +66,10 @@ func (q *commandQueue) Flush(context *opengl.Context) error { return nil } +func FlushCommands(context *opengl.Context) error { + return theCommandQueue.Flush(context) +} + type fillCommand struct { dst *Framebuffer color color.Color diff --git a/internal/graphics/framebuffer.go b/internal/graphics/framebuffer.go index c32b19a08..08b3eb6b3 100644 --- a/internal/graphics/framebuffer.go +++ b/internal/graphics/framebuffer.go @@ -96,7 +96,7 @@ func (f *Framebuffer) projectionMatrix() *[4][4]float64 { return f.proMatrix } -func (f *Framebuffer) Fill(context *opengl.Context, clr color.Color) error { +func (f *Framebuffer) Fill(clr color.Color) error { c := &fillCommand{ dst: f, color: clr, @@ -105,7 +105,7 @@ func (f *Framebuffer) Fill(context *opengl.Context, clr color.Color) error { return nil } -func (f *Framebuffer) DrawTexture(context *opengl.Context, t *Texture, vertices []int16, geo, clr Matrix, mode opengl.CompositeMode) error { +func (f *Framebuffer) DrawTexture(t *Texture, vertices []int16, geo, clr Matrix, mode opengl.CompositeMode) error { c := &drawImageCommand{ dst: f, src: t, @@ -115,13 +115,6 @@ func (f *Framebuffer) DrawTexture(context *opengl.Context, t *Texture, vertices mode: mode, } theCommandQueue.Enqueue(c) - // Drawing a texture to the default buffer must be the last command. - // TODO(hajimehoshi): This seems a little hacky. Refactor. - if f.native == opengl.ZeroFramebuffer { - if err := theCommandQueue.Flush(context); err != nil { - return err - } - } return nil } @@ -133,7 +126,7 @@ func (f *Framebuffer) Pixels(context *opengl.Context) ([]uint8, error) { return context.FramebufferPixels(f.native, f.width, f.height) } -func (f *Framebuffer) ReplacePixels(context *opengl.Context, t *Texture, p []uint8) error { +func (f *Framebuffer) ReplacePixels(t *Texture, p []uint8) error { c := &replacePixelsCommand{ dst: f, texture: t,