mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +01:00
driver: Move getting actual drivers to ebiten package
This commit is contained in:
parent
f2e42c3ea1
commit
747d1be54e
@ -15,7 +15,7 @@
|
|||||||
// +build darwin,!ios
|
// +build darwin,!ios
|
||||||
// +build !js
|
// +build !js
|
||||||
|
|
||||||
package driver
|
package ebiten
|
||||||
|
|
||||||
// #cgo CFLAGS: -x objective-c
|
// #cgo CFLAGS: -x objective-c
|
||||||
// #cgo LDFLAGS: -framework Foundation
|
// #cgo LDFLAGS: -framework Foundation
|
||||||
@ -52,7 +52,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Graphics() graphicsdriver.GraphicsDriver {
|
func graphicsDriver() graphicsdriver.GraphicsDriver {
|
||||||
if isMetalSupported {
|
if isMetalSupported {
|
||||||
return metal.Get()
|
return metal.Get()
|
||||||
}
|
}
|
@ -14,13 +14,13 @@
|
|||||||
|
|
||||||
// +build !darwin ios js
|
// +build !darwin ios js
|
||||||
|
|
||||||
package driver
|
package ebiten
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphicsdriver"
|
"github.com/hajimehoshi/ebiten/internal/graphicsdriver"
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/opengl"
|
"github.com/hajimehoshi/ebiten/internal/graphicsdriver/opengl"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Graphics() graphicsdriver.GraphicsDriver {
|
func graphicsDriver() graphicsdriver.GraphicsDriver {
|
||||||
return opengl.Get()
|
return opengl.Get()
|
||||||
}
|
}
|
@ -19,13 +19,17 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/clock"
|
"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/graphicsdriver"
|
||||||
"github.com/hajimehoshi/ebiten/internal/hooks"
|
"github.com/hajimehoshi/ebiten/internal/hooks"
|
||||||
"github.com/hajimehoshi/ebiten/internal/shareable"
|
"github.com/hajimehoshi/ebiten/internal/shareable"
|
||||||
"github.com/hajimehoshi/ebiten/internal/ui"
|
"github.com/hajimehoshi/ebiten/internal/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
graphicscommand.SetGraphicsDriver(graphicsDriver())
|
||||||
|
}
|
||||||
|
|
||||||
func newGraphicsContext(f func(*Image) error) *graphicsContext {
|
func newGraphicsContext(f func(*Image) error) *graphicsContext {
|
||||||
return &graphicsContext{
|
return &graphicsContext{
|
||||||
f: f,
|
f: f,
|
||||||
@ -123,7 +127,7 @@ func (c *graphicsContext) Update(afterFrameUpdate func()) error {
|
|||||||
|
|
||||||
op := &DrawImageOptions{}
|
op := &DrawImageOptions{}
|
||||||
|
|
||||||
switch vd := driver.Graphics().VDirection(); vd {
|
switch vd := graphicsDriver().VDirection(); vd {
|
||||||
case graphicsdriver.VDownward:
|
case graphicsdriver.VDownward:
|
||||||
// c.screen is special: its Y axis is down to up,
|
// c.screen is special: its Y axis is down to up,
|
||||||
// and the origin point is lower left.
|
// and the origin point is lower left.
|
||||||
|
@ -18,10 +18,16 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
"github.com/hajimehoshi/ebiten/internal/affine"
|
||||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
"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.
|
// command represents a drawing command.
|
||||||
//
|
//
|
||||||
// A command for drawing that is created when Image functions are called like DrawImage,
|
// A command for drawing that is created when Image functions are called like DrawImage,
|
||||||
@ -167,7 +173,7 @@ func (q *commandQueue) Flush() {
|
|||||||
nc++
|
nc++
|
||||||
}
|
}
|
||||||
if 0 < ne {
|
if 0 < ne {
|
||||||
driver.Graphics().SetVertices(vs[:nv], es[:ne])
|
theGraphicsDriver.SetVertices(vs[:nv], es[:ne])
|
||||||
es = es[ne:]
|
es = es[ne:]
|
||||||
vs = vs[nv:]
|
vs = vs[nv:]
|
||||||
}
|
}
|
||||||
@ -187,7 +193,7 @@ func (q *commandQueue) Flush() {
|
|||||||
}
|
}
|
||||||
if 0 < nc {
|
if 0 < nc {
|
||||||
// Call glFlush to prevent black flicking (especially on Android (#226) and iOS).
|
// Call glFlush to prevent black flicking (especially on Android (#226) and iOS).
|
||||||
driver.Graphics().Flush()
|
theGraphicsDriver.Flush()
|
||||||
}
|
}
|
||||||
q.commands = q.commands[nc:]
|
q.commands = q.commands[nc:]
|
||||||
}
|
}
|
||||||
@ -233,7 +239,7 @@ func (c *drawImageCommand) Exec(indexOffset int) error {
|
|||||||
|
|
||||||
c.dst.image.SetAsDestination()
|
c.dst.image.SetAsDestination()
|
||||||
c.src.image.SetAsSource()
|
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 err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -439,7 +445,7 @@ func (c *newImageCommand) String() string {
|
|||||||
|
|
||||||
// Exec executes a newImageCommand.
|
// Exec executes a newImageCommand.
|
||||||
func (c *newImageCommand) Exec(indexOffset int) error {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -479,7 +485,7 @@ func (c *newScreenFramebufferImageCommand) String() string {
|
|||||||
// Exec executes a newScreenFramebufferImageCommand.
|
// Exec executes a newScreenFramebufferImageCommand.
|
||||||
func (c *newScreenFramebufferImageCommand) Exec(indexOffset int) error {
|
func (c *newScreenFramebufferImageCommand) Exec(indexOffset int) error {
|
||||||
var err 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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -503,5 +509,5 @@ func (c *newScreenFramebufferImageCommand) CanMerge(dst, src *Image, color *affi
|
|||||||
|
|
||||||
// ResetGraphicsDriverState resets or initializes the current graphics driver state.
|
// ResetGraphicsDriverState resets or initializes the current graphics driver state.
|
||||||
func ResetGraphicsDriverState() error {
|
func ResetGraphicsDriverState() error {
|
||||||
return driver.Graphics().Reset()
|
return theGraphicsDriver.Reset()
|
||||||
}
|
}
|
||||||
|
3
run.go
3
run.go
@ -19,7 +19,6 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/clock"
|
"github.com/hajimehoshi/ebiten/internal/clock"
|
||||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/ui"
|
"github.com/hajimehoshi/ebiten/internal/ui"
|
||||||
"github.com/hajimehoshi/ebiten/internal/web"
|
"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() {
|
if !web.IsGopherJS() {
|
||||||
defer atomic.StoreInt32(&isRunning, 0)
|
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 {
|
if err == ui.RegularTermination {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user