diff --git a/graphicscontext.go b/graphicscontext.go index 9be199591..f9369552f 100644 --- a/graphicscontext.go +++ b/graphicscontext.go @@ -65,7 +65,7 @@ func (c *graphicsContext) needsRestoring(context *opengl.Context) (bool, error) return c.screen.impl.isInvalidated(context), nil } -func (c *graphicsContext) Update() error { +func (c *graphicsContext) UpdateAndDraw() error { if !c.initialized { if err := graphics.Initialize(ui.GLContext()); err != nil { return err @@ -112,6 +112,22 @@ func (c *graphicsContext) Update() error { return nil } +func (c *graphicsContext) Draw() error { + if err := c.defaultRenderTarget.Clear(); err != nil { + return err + } + scale := float64(c.screenScale) + options := &DrawImageOptions{} + options.GeoM.Scale(scale, scale) + if err := c.defaultRenderTarget.DrawImage(c.screen, options); err != nil { + return err + } + if err := c.flush(); err != nil { + return err + } + return nil +} + func (c *graphicsContext) flush() error { // TODO: imageM is necessary to call graphics functions. Move this to graphics package. imageM.Lock() diff --git a/internal/loop/run.go b/internal/loop/run.go index 87d06ccb6..efa4c5a18 100644 --- a/internal/loop/run.go +++ b/internal/loop/run.go @@ -95,7 +95,8 @@ func (c *runContext) setRunningSlowly(isRunningSlowly bool) { type GraphicsContext interface { SetSize(width, height, scale int) error - Update() error + UpdateAndDraw() error + Draw() error } func Run(g GraphicsContext, width, height, scale int, title string, fps int) error { @@ -143,10 +144,16 @@ func Run(g GraphicsContext, width, height, scale int, title string, fps int) err if tt == 0 && (int64(time.Second)/int64(fps)-int64(5*time.Millisecond)) < t { tt = 1 } - for i := 0; i < tt; i++ { - slow := i < tt-1 - currentRunContext.setRunningSlowly(slow) - if err := g.Update(); err != nil { + if 1 <= tt { + for i := 0; i < tt; i++ { + slow := i < tt-1 + currentRunContext.setRunningSlowly(slow) + if err := g.UpdateAndDraw(); err != nil { + return err + } + } + } else { + if err := g.Draw(); err != nil { return err } }