mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
graphics: Bug fix: screen flicks on Android (#229)
This commit is contained in:
parent
3f18096e95
commit
6640f60c88
@ -65,7 +65,7 @@ func (c *graphicsContext) needsRestoring(context *opengl.Context) (bool, error)
|
|||||||
return c.screen.impl.isInvalidated(context), nil
|
return c.screen.impl.isInvalidated(context), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *graphicsContext) Update() error {
|
func (c *graphicsContext) UpdateAndDraw() error {
|
||||||
if !c.initialized {
|
if !c.initialized {
|
||||||
if err := graphics.Initialize(ui.GLContext()); err != nil {
|
if err := graphics.Initialize(ui.GLContext()); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -112,6 +112,22 @@ func (c *graphicsContext) Update() error {
|
|||||||
return nil
|
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 {
|
func (c *graphicsContext) flush() error {
|
||||||
// TODO: imageM is necessary to call graphics functions. Move this to graphics package.
|
// TODO: imageM is necessary to call graphics functions. Move this to graphics package.
|
||||||
imageM.Lock()
|
imageM.Lock()
|
||||||
|
@ -95,7 +95,8 @@ func (c *runContext) setRunningSlowly(isRunningSlowly bool) {
|
|||||||
|
|
||||||
type GraphicsContext interface {
|
type GraphicsContext interface {
|
||||||
SetSize(width, height, scale int) error
|
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 {
|
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 {
|
if tt == 0 && (int64(time.Second)/int64(fps)-int64(5*time.Millisecond)) < t {
|
||||||
tt = 1
|
tt = 1
|
||||||
}
|
}
|
||||||
for i := 0; i < tt; i++ {
|
if 1 <= tt {
|
||||||
slow := i < tt-1
|
for i := 0; i < tt; i++ {
|
||||||
currentRunContext.setRunningSlowly(slow)
|
slow := i < tt-1
|
||||||
if err := g.Update(); err != nil {
|
currentRunContext.setRunningSlowly(slow)
|
||||||
|
if err := g.UpdateAndDraw(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := g.Draw(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user