graphics: Move all context usages to internal/graphics

This commit is contained in:
Hajime Hoshi 2016-07-03 22:35:27 +09:00
parent 6e76c3ed6b
commit f7a84fe969
2 changed files with 7 additions and 4 deletions

View File

@ -128,14 +128,10 @@ func (c *graphicsContext) drawToDefaultRenderTarget(context *opengl.Context) err
if err := graphics.FlushCommands(context); err != nil { if err := graphics.FlushCommands(context); err != nil {
return err return err
} }
// Call glFlush to prevent black flicking (especially on Android (#226) and iOS).
context.Flush()
return nil return nil
} }
func (c *graphicsContext) UpdateAndDraw(context *opengl.Context, updateCount int) error { func (c *graphicsContext) UpdateAndDraw(context *opengl.Context, updateCount int) error {
// glViewport must be called at every frame on iOS
context.ResetViewportSize()
if err := c.initializeIfNeeded(context); err != nil { if err := c.initializeIfNeeded(context); err != nil {
return err return err
} }

View File

@ -43,6 +43,8 @@ func (q *commandQueue) Enqueue(command command) {
} }
func (q *commandQueue) Flush(context *opengl.Context) error { func (q *commandQueue) Flush(context *opengl.Context) error {
// glViewport must be called at least at every frame on iOS.
context.ResetViewportSize()
q.indexOffsetInBytes = 0 q.indexOffsetInBytes = 0
vertices := []int16{} vertices := []int16{}
for _, c := range q.commands { for _, c := range q.commands {
@ -59,12 +61,17 @@ func (q *commandQueue) Flush(context *opengl.Context) error {
if MaxQuads < len(vertices)/16 { if MaxQuads < len(vertices)/16 {
return errors.New(fmt.Sprintf("len(quads) must be equal to or less than %d", MaxQuads)) return errors.New(fmt.Sprintf("len(quads) must be equal to or less than %d", MaxQuads))
} }
numc := len(q.commands)
for _, c := range q.commands { for _, c := range q.commands {
if err := c.Exec(context); err != nil { if err := c.Exec(context); err != nil {
return err return err
} }
} }
q.commands = []command{} q.commands = []command{}
if 0 < numc {
// Call glFlush to prevent black flicking (especially on Android (#226) and iOS).
context.Flush()
}
return nil return nil
} }