ebiten: refactoring: move the caller of SetGraphicsDriver to the package ui

This commit is contained in:
Hajime Hoshi 2022-02-06 22:01:25 +09:00
parent df60c4c92d
commit f18aef2b08
2 changed files with 12 additions and 10 deletions

View File

@ -34,6 +34,8 @@ package ui
import "C"
import (
"sync"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal/mtl"
@ -56,14 +58,15 @@ func supportsMetal() bool {
return true
}
func init() {
if supportsMetal() {
graphics = metal.Get()
return
}
graphics = opengl.Get()
}
var graphicsOnce sync.Once
func Graphics() graphicsdriver.Graphics {
graphicsOnce.Do(func() {
if supportsMetal() {
graphics = metal.Get()
return
}
graphics = opengl.Get()
})
return graphics
}

View File

@ -12,13 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package ebiten
package ui
import (
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
"github.com/hajimehoshi/ebiten/v2/internal/ui"
)
func init() {
graphicscommand.SetGraphicsDriver(ui.Graphics())
graphicscommand.SetGraphicsDriver(Graphics())
}