graphics: Refactoring: Remove graphicsContext.Draw and flush

This commit is contained in:
Hajime Hoshi 2016-07-03 18:56:32 +09:00
parent 86144a1cd6
commit 146c1e5846
2 changed files with 19 additions and 39 deletions

View File

@ -124,9 +124,14 @@ func (c *graphicsContext) drawToDefaultRenderTarget(context *opengl.Context) err
if err := drawWithFittingScale(c.screen, c.offscreen2); err != nil {
return err
}
if err := c.flush(context); err != nil {
// TODO: imageM is necessary to call graphics functions. Move this to graphics package.
imageM.Lock()
defer imageM.Unlock()
if err := graphics.FlushCommands(context); err != nil {
return err
}
// Call glFlush to prevent black flicking (especially on Android (#226) and iOS).
context.Flush()
return nil
}
@ -143,43 +148,25 @@ func (c *graphicsContext) UpdateAndDraw(context *opengl.Context, updateCount int
return err
}
}
if err := c.offscreen2.Clear(); err != nil {
return err
}
if err := drawWithFittingScale(c.offscreen2, c.offscreen); err != nil {
return err
if 0 < updateCount {
if err := c.offscreen2.Clear(); err != nil {
return err
}
if err := drawWithFittingScale(c.offscreen2, c.offscreen); err != nil {
return err
}
}
if err := c.drawToDefaultRenderTarget(context); err != nil {
return err
}
if err := theImages.savePixels(context); err != nil {
return err
if 0 < updateCount {
if err := theImages.savePixels(context); err != nil {
return err
}
}
return nil
}
func (c *graphicsContext) Draw(context *opengl.Context) error {
if err := c.initializeIfNeeded(context); err != nil {
return err
}
if err := c.drawToDefaultRenderTarget(context); err != nil {
return err
}
return nil
}
func (c *graphicsContext) flush(context *opengl.Context) error {
// TODO: imageM is necessary to call graphics functions. Move this to graphics package.
imageM.Lock()
defer imageM.Unlock()
if err := graphics.FlushCommands(context); err != nil {
return err
}
// Call glFlush to prevent black flicking (especially on Android (#226) and iOS).
context.Flush()
return nil
}
func (c *graphicsContext) restore(context *opengl.Context) error {
imageM.Lock()
defer imageM.Unlock()

View File

@ -81,7 +81,6 @@ func (c *runContext) updateFPS(fps float64) {
type GraphicsContext interface {
SetSize(width, height int, scale float64) error
UpdateAndDraw(context *opengl.Context, updateCount int) error
Draw(context *opengl.Context) error
}
func Run(g GraphicsContext, width, height int, scale float64, title string, fps int) error {
@ -155,14 +154,8 @@ func (c *runContext) render(g GraphicsContext) error {
if tt == 0 && (int64(time.Second)/int64(fps)-int64(5*time.Millisecond)) < t {
tt = 1
}
if 1 <= tt {
if err := g.UpdateAndDraw(ui.GLContext(), tt); err != nil {
return err
}
} else {
if err := g.Draw(ui.GLContext()); err != nil {
return err
}
if err := g.UpdateAndDraw(ui.GLContext(), tt); err != nil {
return err
}
if err := ui.CurrentUI().SwapBuffers(); err != nil {
return err