driver: Move getting actual drivers to ebiten package

This commit is contained in:
Hajime Hoshi 2019-03-30 22:13:48 +09:00
parent f2e42c3ea1
commit 747d1be54e
5 changed files with 24 additions and 15 deletions

View File

@ -15,7 +15,7 @@
// +build darwin,!ios
// +build !js
package driver
package ebiten
// #cgo CFLAGS: -x objective-c
// #cgo LDFLAGS: -framework Foundation
@ -52,7 +52,7 @@ func init() {
}
}
func Graphics() graphicsdriver.GraphicsDriver {
func graphicsDriver() graphicsdriver.GraphicsDriver {
if isMetalSupported {
return metal.Get()
}

View File

@ -14,13 +14,13 @@
// +build !darwin ios js
package driver
package ebiten
import (
"github.com/hajimehoshi/ebiten/internal/graphicsdriver"
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/opengl"
)
func Graphics() graphicsdriver.GraphicsDriver {
func graphicsDriver() graphicsdriver.GraphicsDriver {
return opengl.Get()
}

View File

@ -19,13 +19,17 @@ import (
"math"
"github.com/hajimehoshi/ebiten/internal/clock"
"github.com/hajimehoshi/ebiten/internal/driver"
"github.com/hajimehoshi/ebiten/internal/graphicscommand"
"github.com/hajimehoshi/ebiten/internal/graphicsdriver"
"github.com/hajimehoshi/ebiten/internal/hooks"
"github.com/hajimehoshi/ebiten/internal/shareable"
"github.com/hajimehoshi/ebiten/internal/ui"
)
func init() {
graphicscommand.SetGraphicsDriver(graphicsDriver())
}
func newGraphicsContext(f func(*Image) error) *graphicsContext {
return &graphicsContext{
f: f,
@ -123,7 +127,7 @@ func (c *graphicsContext) Update(afterFrameUpdate func()) error {
op := &DrawImageOptions{}
switch vd := driver.Graphics().VDirection(); vd {
switch vd := graphicsDriver().VDirection(); vd {
case graphicsdriver.VDownward:
// c.screen is special: its Y axis is down to up,
// and the origin point is lower left.

View File

@ -18,10 +18,16 @@ import (
"fmt"
"github.com/hajimehoshi/ebiten/internal/affine"
"github.com/hajimehoshi/ebiten/internal/driver"
"github.com/hajimehoshi/ebiten/internal/graphics"
"github.com/hajimehoshi/ebiten/internal/graphicsdriver"
)
var theGraphicsDriver graphicsdriver.GraphicsDriver
func SetGraphicsDriver(driver graphicsdriver.GraphicsDriver) {
theGraphicsDriver = driver
}
// command represents a drawing command.
//
// A command for drawing that is created when Image functions are called like DrawImage,
@ -167,7 +173,7 @@ func (q *commandQueue) Flush() {
nc++
}
if 0 < ne {
driver.Graphics().SetVertices(vs[:nv], es[:ne])
theGraphicsDriver.SetVertices(vs[:nv], es[:ne])
es = es[ne:]
vs = vs[nv:]
}
@ -187,7 +193,7 @@ func (q *commandQueue) Flush() {
}
if 0 < nc {
// Call glFlush to prevent black flicking (especially on Android (#226) and iOS).
driver.Graphics().Flush()
theGraphicsDriver.Flush()
}
q.commands = q.commands[nc:]
}
@ -233,7 +239,7 @@ func (c *drawImageCommand) Exec(indexOffset int) error {
c.dst.image.SetAsDestination()
c.src.image.SetAsSource()
if err := driver.Graphics().Draw(c.nindices, indexOffset, c.mode, c.color, c.filter, c.address); err != nil {
if err := theGraphicsDriver.Draw(c.nindices, indexOffset, c.mode, c.color, c.filter, c.address); err != nil {
return err
}
return nil
@ -439,7 +445,7 @@ func (c *newImageCommand) String() string {
// Exec executes a newImageCommand.
func (c *newImageCommand) Exec(indexOffset int) error {
i, err := driver.Graphics().NewImage(c.width, c.height)
i, err := theGraphicsDriver.NewImage(c.width, c.height)
if err != nil {
return err
}
@ -479,7 +485,7 @@ func (c *newScreenFramebufferImageCommand) String() string {
// Exec executes a newScreenFramebufferImageCommand.
func (c *newScreenFramebufferImageCommand) Exec(indexOffset int) error {
var err error
c.result.image, err = driver.Graphics().NewScreenFramebufferImage(c.width, c.height)
c.result.image, err = theGraphicsDriver.NewScreenFramebufferImage(c.width, c.height)
return err
}
@ -503,5 +509,5 @@ func (c *newScreenFramebufferImageCommand) CanMerge(dst, src *Image, color *affi
// ResetGraphicsDriverState resets or initializes the current graphics driver state.
func ResetGraphicsDriverState() error {
return driver.Graphics().Reset()
return theGraphicsDriver.Reset()
}

3
run.go
View File

@ -19,7 +19,6 @@ import (
"sync/atomic"
"github.com/hajimehoshi/ebiten/internal/clock"
"github.com/hajimehoshi/ebiten/internal/driver"
"github.com/hajimehoshi/ebiten/internal/ui"
"github.com/hajimehoshi/ebiten/internal/web"
)
@ -97,7 +96,7 @@ func run(width, height int, scale float64, title string, g *graphicsContext, mai
if !web.IsGopherJS() {
defer atomic.StoreInt32(&isRunning, 0)
}
if err := ui.Run(width, height, scale, title, g, mainloop, driver.Graphics()); err != nil {
if err := ui.Run(width, height, scale, title, g, mainloop, graphicsDriver()); err != nil {
if err == ui.RegularTermination {
return nil
}