all: drop the support of gomobile-build

Closes #2741
This commit is contained in:
Hajime Hoshi 2024-01-08 00:18:03 +09:00
parent 9240372368
commit 9539a87b17
7 changed files with 14 additions and 756 deletions

View File

@ -26,8 +26,6 @@ import (
"strconv"
"strings"
"text/template"
"golang.org/x/mobile/event/key"
)
var (
@ -35,7 +33,6 @@ var (
uiKeyNameToGLFWKeyName map[string]string
androidKeyToUIKeyName map[int]string
iosKeyToUIKeyName map[int]string
gbuildKeyToUIKeyName map[key.Code]string
uiKeyNameToJSKey map[string]string
oldEbitengineKeyNameToUIKeyName map[string]string
)
@ -280,58 +277,6 @@ func init() {
0x2B: "Tab",
}
gbuildKeyToUIKeyName = map[key.Code]string{
key.CodeComma: "Comma",
key.CodeFullStop: "Period",
key.CodeLeftAlt: "AltLeft",
key.CodeRightAlt: "AltRight",
key.CodeCapsLock: "CapsLock",
key.CodeLeftControl: "ControlLeft",
key.CodeRightControl: "ControlRight",
key.CodeLeftShift: "ShiftLeft",
key.CodeRightShift: "ShiftRight",
key.CodeReturnEnter: "Enter",
key.CodeSpacebar: "Space",
key.CodeTab: "Tab",
key.CodeDeleteForward: "Delete",
key.CodeEnd: "End",
key.CodeHome: "Home",
key.CodeInsert: "Insert",
key.CodePageDown: "PageDown",
key.CodePageUp: "PageUp",
key.CodeDownArrow: "ArrowDown",
key.CodeLeftArrow: "ArrowLeft",
key.CodeRightArrow: "ArrowRight",
key.CodeUpArrow: "ArrowUp",
key.CodeEscape: "Escape",
key.CodeDeleteBackspace: "Backspace",
key.CodeApostrophe: "Quote",
key.CodeHyphenMinus: "Minus",
key.CodeSlash: "Slash",
key.CodeSemicolon: "Semicolon",
key.CodeEqualSign: "Equal",
key.CodeLeftSquareBracket: "BracketLeft",
key.CodeBackslash: "Backslash",
key.CodeRightSquareBracket: "BracketRight",
key.CodeGraveAccent: "Backquote",
key.CodeKeypadNumLock: "NumLock",
key.CodePause: "Pause",
key.CodeKeypadPlusSign: "NumpadAdd",
key.CodeKeypadFullStop: "NumpadDecimal",
key.CodeKeypadSlash: "NumpadDivide",
key.CodeKeypadAsterisk: "NumpadMultiply",
key.CodeKeypadHyphenMinus: "NumpadSubtract",
key.CodeKeypadEnter: "NumpadEnter",
key.CodeKeypadEqualSign: "NumpadEqual",
key.CodeLeftGUI: "MetaLeft",
key.CodeRightGUI: "MetaRight",
// Missing keys:
// ui.KeyPrintScreen
// ui.KeyScrollLock
// ui.KeyMenu
}
// The UI key and JS key are almost same but very slightly different (e.g., 'A' vs 'KeyA').
uiKeyNameToJSKey = map[string]string{
"Comma": "Comma",
@ -400,10 +345,8 @@ func init() {
// in this order. Same for iOS.
if c == '0' {
iosKeyToUIKeyName[0x27] = name
gbuildKeyToUIKeyName[key.Code0] = name
} else {
iosKeyToUIKeyName[0x1E+int(c)-'1'] = name
gbuildKeyToUIKeyName[key.Code1+key.Code(c)-'1'] = name
}
uiKeyNameToJSKey[name] = name
@ -414,7 +357,6 @@ func init() {
uiKeyNameToGLFWKeyName[string(c)] = string(c)
androidKeyToUIKeyName[29+int(c)-'A'] = string(c)
iosKeyToUIKeyName[0x04+int(c)-'A'] = string(c)
gbuildKeyToUIKeyName[key.CodeA+key.Code(c)-'A'] = string(c)
uiKeyNameToJSKey[string(c)] = "Key" + string(c)
}
// Function keys
@ -432,10 +374,8 @@ func init() {
}
if i <= 12 {
iosKeyToUIKeyName[0x3A+i-1] = name
gbuildKeyToUIKeyName[key.CodeF1+key.Code(i)-1] = name
} else {
iosKeyToUIKeyName[0x68+i-13] = name
gbuildKeyToUIKeyName[key.CodeF13+key.Code(i)-13] = name
}
uiKeyNameToJSKey[name] = name
}
@ -450,10 +390,8 @@ func init() {
// in this order. Same for iOS.
if c == '0' {
iosKeyToUIKeyName[0x62] = name
gbuildKeyToUIKeyName[key.CodeKeypad0] = name
} else {
iosKeyToUIKeyName[0x59+int(c)-'1'] = name
gbuildKeyToUIKeyName[key.CodeKeypad1+key.Code(c)-'1'] = name
}
uiKeyNameToJSKey[name] = name
}
@ -711,24 +649,6 @@ var iosKeyToUIKey = map[int]ui.Key{
}
`
const uiMobileKeysTmpl = `{{.License}}
{{.DoNotEdit}}
{{.BuildTag}}
package ui
import (
"golang.org/x/mobile/event/key"
)
var gbuildKeyToUIKey = map[key.Code]Key{
{{range $key, $name := .GBuildKeyToUIKeyName}}key.{{$key}}: Key{{$name}},
{{end}}
}
`
func digitKey(name string) int {
if len(name) != 1 {
return -1
@ -849,7 +769,6 @@ func main() {
filepath.Join("internal", "glfw", "keys.go"): glfwKeysTmpl,
filepath.Join("internal", "ui", "keys.go"): uiKeysTmpl,
filepath.Join("internal", "ui", "keys_glfw.go"): uiGLFWKeysTmpl,
filepath.Join("internal", "ui", "keys_mobile.go"): uiMobileKeysTmpl,
filepath.Join("internal", "ui", "keys_js.go"): uiJSKeysTmpl,
filepath.Join("keys.go"): ebitengineKeysTmpl,
filepath.Join("mobile", "ebitenmobileview", "keys_android.go"): mobileAndroidKeysTmpl,
@ -894,7 +813,6 @@ func main() {
UIKeyNameToGLFWKeyName map[string]string
AndroidKeyToUIKeyName map[int]string
IOSKeyToUIKeyName map[int]string
GBuildKeyToUIKeyName map[key.Code]string
OldEbitengineKeyNameToUIKeyName map[string]string
}{
License: license,
@ -909,7 +827,6 @@ func main() {
UIKeyNameToGLFWKeyName: uiKeyNameToGLFWKeyName,
AndroidKeyToUIKeyName: androidKeyToUIKeyName,
IOSKeyToUIKeyName: iosKeyToUIKeyName,
GBuildKeyToUIKeyName: gbuildKeyToUIKeyName,
OldEbitengineKeyNameToUIKeyName: oldEbitengineKeyNameToUIKeyName,
}); err != nil {
log.Fatal(err)

View File

@ -1,344 +0,0 @@
// Copyright 2020 The Ebiten Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build android || ios
package gl
import (
"golang.org/x/mobile/gl"
)
type gomobileContext struct {
ctx gl.Context
}
func gmProgram(program uint32) gl.Program {
return gl.Program{
Init: true,
Value: program,
}
}
func NewGomobileContext(ctx gl.Context) Context {
return &gomobileContext{ctx}
}
func (g *gomobileContext) LoadFunctions() error {
return nil
}
func (g *gomobileContext) IsES() bool {
return true
}
func (g *gomobileContext) ActiveTexture(texture uint32) {
g.ctx.ActiveTexture(gl.Enum(texture))
}
func (g *gomobileContext) AttachShader(program uint32, shader uint32) {
g.ctx.AttachShader(gmProgram(program), gl.Shader{Value: shader})
}
func (g *gomobileContext) BindAttribLocation(program uint32, index uint32, name string) {
g.ctx.BindAttribLocation(gmProgram(program), gl.Attrib{Value: uint(index)}, name)
}
func (g *gomobileContext) BindBuffer(target uint32, buffer uint32) {
g.ctx.BindBuffer(gl.Enum(target), gl.Buffer{Value: buffer})
}
func (g *gomobileContext) BindFramebuffer(target uint32, framebuffer uint32) {
g.ctx.BindFramebuffer(gl.Enum(target), gl.Framebuffer{Value: framebuffer})
}
func (g *gomobileContext) BindRenderbuffer(target uint32, renderbuffer uint32) {
g.ctx.BindRenderbuffer(gl.Enum(target), gl.Renderbuffer{Value: renderbuffer})
}
func (g *gomobileContext) BindTexture(target uint32, texture uint32) {
g.ctx.BindTexture(gl.Enum(target), gl.Texture{Value: texture})
}
func (g *gomobileContext) BindVertexArray(array uint32) {
g.ctx.BindVertexArray(gl.VertexArray{Value: array})
}
func (g *gomobileContext) BlendEquationSeparate(modeRGB uint32, modeAlpha uint32) {
g.ctx.BlendEquationSeparate(gl.Enum(modeRGB), gl.Enum(modeAlpha))
}
func (g *gomobileContext) BlendFuncSeparate(srcRGB uint32, dstRGB uint32, srcAlpha uint32, dstAlpha uint32) {
g.ctx.BlendFuncSeparate(gl.Enum(srcRGB), gl.Enum(dstRGB), gl.Enum(srcAlpha), gl.Enum(dstAlpha))
}
func (g *gomobileContext) BufferInit(target uint32, size int, usage uint32) {
g.ctx.BufferInit(gl.Enum(target), size, gl.Enum(usage))
}
func (g *gomobileContext) BufferSubData(target uint32, offset int, data []byte) {
g.ctx.BufferSubData(gl.Enum(target), offset, data)
}
func (g *gomobileContext) CheckFramebufferStatus(target uint32) uint32 {
return uint32(g.ctx.CheckFramebufferStatus(gl.Enum(target)))
}
func (g *gomobileContext) Clear(mask uint32) {
g.ctx.Clear(gl.Enum(mask))
}
func (g *gomobileContext) ColorMask(red, green, blue, alpha bool) {
g.ctx.ColorMask(red, green, blue, alpha)
}
func (g *gomobileContext) CompileShader(shader uint32) {
g.ctx.CompileShader(gl.Shader{Value: shader})
}
func (g *gomobileContext) CreateBuffer() uint32 {
return g.ctx.CreateBuffer().Value
}
func (g *gomobileContext) CreateFramebuffer() uint32 {
return g.ctx.CreateFramebuffer().Value
}
func (g *gomobileContext) CreateProgram() uint32 {
return g.ctx.CreateProgram().Value
}
func (g *gomobileContext) CreateRenderbuffer() uint32 {
return g.ctx.CreateRenderbuffer().Value
}
func (g *gomobileContext) CreateShader(xtype uint32) uint32 {
return g.ctx.CreateShader(gl.Enum(xtype)).Value
}
func (g *gomobileContext) CreateTexture() uint32 {
return g.ctx.CreateTexture().Value
}
func (g *gomobileContext) CreateVertexArray() uint32 {
return g.ctx.CreateVertexArray().Value
}
func (g *gomobileContext) DeleteBuffer(buffer uint32) {
g.ctx.DeleteBuffer(gl.Buffer{Value: buffer})
}
func (g *gomobileContext) DeleteFramebuffer(framebuffer uint32) {
g.ctx.DeleteFramebuffer(gl.Framebuffer{Value: framebuffer})
}
func (g *gomobileContext) DeleteProgram(program uint32) {
g.ctx.DeleteProgram(gmProgram(program))
}
func (g *gomobileContext) DeleteRenderbuffer(renderbuffer uint32) {
g.ctx.DeleteRenderbuffer(gl.Renderbuffer{Value: renderbuffer})
}
func (g *gomobileContext) DeleteShader(shader uint32) {
g.ctx.DeleteShader(gl.Shader{Value: shader})
}
func (g *gomobileContext) DeleteTexture(texture uint32) {
g.ctx.DeleteTexture(gl.Texture{Value: texture})
}
func (g *gomobileContext) DeleteVertexArray(texture uint32) {
g.ctx.DeleteVertexArray(gl.VertexArray{Value: texture})
}
func (g *gomobileContext) Disable(cap uint32) {
g.ctx.Disable(gl.Enum(cap))
}
func (g *gomobileContext) DisableVertexAttribArray(index uint32) {
g.ctx.DisableVertexAttribArray(gl.Attrib{Value: uint(index)})
}
func (g *gomobileContext) DrawElements(mode uint32, count int32, xtype uint32, offset int) {
g.ctx.DrawElements(gl.Enum(mode), int(count), gl.Enum(xtype), offset)
}
func (g *gomobileContext) Enable(cap uint32) {
g.ctx.Enable(gl.Enum(cap))
}
func (g *gomobileContext) EnableVertexAttribArray(index uint32) {
g.ctx.EnableVertexAttribArray(gl.Attrib{Value: uint(index)})
}
func (g *gomobileContext) Flush() {
g.ctx.Flush()
}
func (g *gomobileContext) FramebufferRenderbuffer(target uint32, attachment uint32, renderbuffertarget uint32, renderbuffer uint32) {
g.ctx.FramebufferRenderbuffer(gl.Enum(target), gl.Enum(attachment), gl.Enum(renderbuffertarget), gl.Renderbuffer{Value: renderbuffer})
}
func (g *gomobileContext) FramebufferTexture2D(target uint32, attachment uint32, textarget uint32, texture uint32, level int32) {
g.ctx.FramebufferTexture2D(gl.Enum(target), gl.Enum(attachment), gl.Enum(textarget), gl.Texture{Value: texture}, int(level))
}
func (g *gomobileContext) GetError() uint32 {
return uint32(g.ctx.GetError())
}
func (g *gomobileContext) GetInteger(pname uint32) int {
return g.ctx.GetInteger(gl.Enum(pname))
}
func (g *gomobileContext) GetProgramInfoLog(program uint32) string {
return g.ctx.GetProgramInfoLog(gmProgram(program))
}
func (g *gomobileContext) GetProgrami(program uint32, pname uint32) int {
return g.ctx.GetProgrami(gmProgram(program), gl.Enum(pname))
}
func (g *gomobileContext) GetShaderInfoLog(shader uint32) string {
return g.ctx.GetShaderInfoLog(gl.Shader{Value: shader})
}
func (g *gomobileContext) GetShaderi(shader uint32, pname uint32) int {
return g.ctx.GetShaderi(gl.Shader{Value: shader}, gl.Enum(pname))
}
func (g *gomobileContext) GetUniformLocation(program uint32, name string) int32 {
return g.ctx.GetUniformLocation(gmProgram(program), name).Value
}
func (g *gomobileContext) IsFramebuffer(framebuffer uint32) bool {
return g.ctx.IsFramebuffer(gl.Framebuffer{Value: framebuffer})
}
func (g *gomobileContext) IsProgram(program uint32) bool {
return g.ctx.IsProgram(gmProgram(program))
}
func (g *gomobileContext) IsRenderbuffer(renderbuffer uint32) bool {
return g.ctx.IsRenderbuffer(gl.Renderbuffer{Value: renderbuffer})
}
func (g *gomobileContext) IsTexture(texture uint32) bool {
return g.ctx.IsTexture(gl.Texture{Value: texture})
}
func (g *gomobileContext) LinkProgram(program uint32) {
g.ctx.LinkProgram(gmProgram(program))
}
func (g *gomobileContext) PixelStorei(pname uint32, param int32) {
g.ctx.PixelStorei(gl.Enum(pname), param)
}
func (g *gomobileContext) ReadPixels(dst []byte, x int32, y int32, width int32, height int32, format uint32, xtype uint32) {
g.ctx.ReadPixels(dst, int(x), int(y), int(width), int(height), gl.Enum(format), gl.Enum(xtype))
}
func (g *gomobileContext) RenderbufferStorage(target uint32, internalFormat uint32, width int32, height int32) {
g.ctx.RenderbufferStorage(gl.Enum(target), gl.Enum(internalFormat), int(width), int(height))
}
func (g *gomobileContext) Scissor(x, y, width, height int32) {
g.ctx.Scissor(x, y, width, height)
}
func (g *gomobileContext) ShaderSource(shader uint32, xstring string) {
g.ctx.ShaderSource(gl.Shader{Value: shader}, xstring)
}
func (g *gomobileContext) StencilFunc(func_ uint32, ref int32, mask uint32) {
g.ctx.StencilFunc(gl.Enum(func_), int(ref), mask)
}
func (g *gomobileContext) StencilOpSeparate(face, sfail, dpfail, dppass uint32) {
g.ctx.StencilOpSeparate(gl.Enum(face), gl.Enum(sfail), gl.Enum(dpfail), gl.Enum(dppass))
}
func (g *gomobileContext) TexImage2D(target uint32, level int32, internalformat int32, width int32, height int32, format uint32, xtype uint32, pixels []byte) {
g.ctx.TexImage2D(gl.Enum(target), int(level), int(internalformat), int(width), int(height), gl.Enum(format), gl.Enum(xtype), pixels)
}
func (g *gomobileContext) TexParameteri(target uint32, pname uint32, param int32) {
g.ctx.TexParameteri(gl.Enum(target), gl.Enum(pname), int(param))
}
func (g *gomobileContext) TexSubImage2D(target uint32, level int32, xoffset int32, yoffset int32, width int32, height int32, format uint32, xtype uint32, pixels []byte) {
g.ctx.TexSubImage2D(gl.Enum(target), int(level), int(xoffset), int(yoffset), int(width), int(height), gl.Enum(format), gl.Enum(xtype), pixels)
}
func (g *gomobileContext) Uniform1fv(location int32, value []float32) {
g.ctx.Uniform1fv(gl.Uniform{Value: location}, value)
}
func (g *gomobileContext) Uniform1i(location int32, v0 int32) {
g.ctx.Uniform1i(gl.Uniform{Value: location}, int(v0))
}
func (g *gomobileContext) Uniform1iv(location int32, value []int32) {
g.ctx.Uniform1iv(gl.Uniform{Value: location}, value)
}
func (g *gomobileContext) Uniform2fv(location int32, value []float32) {
g.ctx.Uniform2fv(gl.Uniform{Value: location}, value)
}
func (g *gomobileContext) Uniform2iv(location int32, value []int32) {
g.ctx.Uniform2iv(gl.Uniform{Value: location}, value)
}
func (g *gomobileContext) Uniform3fv(location int32, value []float32) {
g.ctx.Uniform3fv(gl.Uniform{Value: location}, value)
}
func (g *gomobileContext) Uniform3iv(location int32, value []int32) {
g.ctx.Uniform3iv(gl.Uniform{Value: location}, value)
}
func (g *gomobileContext) Uniform4fv(location int32, value []float32) {
g.ctx.Uniform4fv(gl.Uniform{Value: location}, value)
}
func (g *gomobileContext) Uniform4iv(location int32, value []int32) {
g.ctx.Uniform4iv(gl.Uniform{Value: location}, value)
}
func (g *gomobileContext) UniformMatrix2fv(location int32, value []float32) {
g.ctx.UniformMatrix2fv(gl.Uniform{Value: location}, value)
}
func (g *gomobileContext) UniformMatrix3fv(location int32, value []float32) {
g.ctx.UniformMatrix3fv(gl.Uniform{Value: location}, value)
}
func (g *gomobileContext) UniformMatrix4fv(location int32, value []float32) {
g.ctx.UniformMatrix4fv(gl.Uniform{Value: location}, value)
}
func (g *gomobileContext) UseProgram(program uint32) {
g.ctx.UseProgram(gmProgram(program))
}
func (g *gomobileContext) VertexAttribPointer(index uint32, size int32, xtype uint32, normalized bool, stride int32, offset int) {
g.ctx.VertexAttribPointer(gl.Attrib{Value: uint(index)}, int(size), gl.Enum(xtype), normalized, int(stride), int(offset))
}
func (g *gomobileContext) Viewport(x int32, y int32, width int32, height int32) {
g.ctx.Viewport(int(x), int(y), int(width), int(height))
}

View File

@ -17,8 +17,6 @@
package opengl
import (
mgl "golang.org/x/mobile/gl"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gl"
)
@ -28,18 +26,11 @@ type graphicsPlatform struct {
// NewGraphics creates an implementation of graphicsdriver.Graphics for OpenGL.
// The returned graphics value is nil iff the error is not nil.
func NewGraphics(context mgl.Context) (graphicsdriver.Graphics, error) {
var ctx gl.Context
if context != nil {
ctx = gl.NewGomobileContext(context.(mgl.Context))
} else {
var err error
ctx, err = gl.NewDefaultContext()
if err != nil {
return nil, err
}
func NewGraphics() (graphicsdriver.Graphics, error) {
ctx, err := gl.NewDefaultContext()
if err != nil {
return nil, err
}
return newGraphics(ctx), nil
}

View File

@ -1,140 +0,0 @@
// Copyright 2013 The Ebitengine Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Code generated by genkeys.go using 'go generate'. DO NOT EDIT.
//go:build android || ios
package ui
import (
"golang.org/x/mobile/event/key"
)
var gbuildKeyToUIKey = map[key.Code]Key{
key.CodeA: KeyA,
key.CodeB: KeyB,
key.CodeC: KeyC,
key.CodeD: KeyD,
key.CodeE: KeyE,
key.CodeF: KeyF,
key.CodeG: KeyG,
key.CodeH: KeyH,
key.CodeI: KeyI,
key.CodeJ: KeyJ,
key.CodeK: KeyK,
key.CodeL: KeyL,
key.CodeM: KeyM,
key.CodeN: KeyN,
key.CodeO: KeyO,
key.CodeP: KeyP,
key.CodeQ: KeyQ,
key.CodeR: KeyR,
key.CodeS: KeyS,
key.CodeT: KeyT,
key.CodeU: KeyU,
key.CodeV: KeyV,
key.CodeW: KeyW,
key.CodeX: KeyX,
key.CodeY: KeyY,
key.CodeZ: KeyZ,
key.Code1: KeyDigit1,
key.Code2: KeyDigit2,
key.Code3: KeyDigit3,
key.Code4: KeyDigit4,
key.Code5: KeyDigit5,
key.Code6: KeyDigit6,
key.Code7: KeyDigit7,
key.Code8: KeyDigit8,
key.Code9: KeyDigit9,
key.Code0: KeyDigit0,
key.CodeReturnEnter: KeyEnter,
key.CodeEscape: KeyEscape,
key.CodeDeleteBackspace: KeyBackspace,
key.CodeTab: KeyTab,
key.CodeSpacebar: KeySpace,
key.CodeHyphenMinus: KeyMinus,
key.CodeEqualSign: KeyEqual,
key.CodeLeftSquareBracket: KeyBracketLeft,
key.CodeRightSquareBracket: KeyBracketRight,
key.CodeBackslash: KeyBackslash,
key.CodeSemicolon: KeySemicolon,
key.CodeApostrophe: KeyQuote,
key.CodeGraveAccent: KeyBackquote,
key.CodeComma: KeyComma,
key.CodeFullStop: KeyPeriod,
key.CodeSlash: KeySlash,
key.CodeCapsLock: KeyCapsLock,
key.CodeF1: KeyF1,
key.CodeF2: KeyF2,
key.CodeF3: KeyF3,
key.CodeF4: KeyF4,
key.CodeF5: KeyF5,
key.CodeF6: KeyF6,
key.CodeF7: KeyF7,
key.CodeF8: KeyF8,
key.CodeF9: KeyF9,
key.CodeF10: KeyF10,
key.CodeF11: KeyF11,
key.CodeF12: KeyF12,
key.CodePause: KeyPause,
key.CodeInsert: KeyInsert,
key.CodeHome: KeyHome,
key.CodePageUp: KeyPageUp,
key.CodeDeleteForward: KeyDelete,
key.CodeEnd: KeyEnd,
key.CodePageDown: KeyPageDown,
key.CodeRightArrow: KeyArrowRight,
key.CodeLeftArrow: KeyArrowLeft,
key.CodeDownArrow: KeyArrowDown,
key.CodeUpArrow: KeyArrowUp,
key.CodeKeypadNumLock: KeyNumLock,
key.CodeKeypadSlash: KeyNumpadDivide,
key.CodeKeypadAsterisk: KeyNumpadMultiply,
key.CodeKeypadHyphenMinus: KeyNumpadSubtract,
key.CodeKeypadPlusSign: KeyNumpadAdd,
key.CodeKeypadEnter: KeyNumpadEnter,
key.CodeKeypad1: KeyNumpad1,
key.CodeKeypad2: KeyNumpad2,
key.CodeKeypad3: KeyNumpad3,
key.CodeKeypad4: KeyNumpad4,
key.CodeKeypad5: KeyNumpad5,
key.CodeKeypad6: KeyNumpad6,
key.CodeKeypad7: KeyNumpad7,
key.CodeKeypad8: KeyNumpad8,
key.CodeKeypad9: KeyNumpad9,
key.CodeKeypad0: KeyNumpad0,
key.CodeKeypadFullStop: KeyNumpadDecimal,
key.CodeKeypadEqualSign: KeyNumpadEqual,
key.CodeF13: KeyF13,
key.CodeF14: KeyF14,
key.CodeF15: KeyF15,
key.CodeF16: KeyF16,
key.CodeF17: KeyF17,
key.CodeF18: KeyF18,
key.CodeF19: KeyF19,
key.CodeF20: KeyF20,
key.CodeF21: KeyF21,
key.CodeF22: KeyF22,
key.CodeF23: KeyF23,
key.CodeF24: KeyF24,
key.CodeLeftControl: KeyControlLeft,
key.CodeLeftShift: KeyShiftLeft,
key.CodeLeftAlt: KeyAltLeft,
key.CodeLeftGUI: KeyMetaLeft,
key.CodeRightControl: KeyControlRight,
key.CodeRightShift: KeyShiftRight,
key.CodeRightAlt: KeyAltRight,
key.CodeRightGUI: KeyMetaRight,
}

View File

@ -89,14 +89,12 @@ import (
"fmt"
"golang.org/x/mobile/app"
"golang.org/x/mobile/gl"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl"
)
type graphicsDriverCreatorImpl struct {
gomobileContext gl.Context
}
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, GraphicsLibrary, error) {
@ -105,7 +103,7 @@ func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, Graphics
}
func (g *graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {
return opengl.NewGraphics(g.gomobileContext)
return opengl.NewGraphics()
}
func (*graphicsDriverCreatorImpl) newDirectX() (graphicsdriver.Graphics, error) {

View File

@ -28,15 +28,12 @@ import (
"errors"
"fmt"
"golang.org/x/mobile/gl"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl"
)
type graphicsDriverCreatorImpl struct {
gomobileContext gl.Context
}
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, GraphicsLibrary, error) {
@ -52,7 +49,7 @@ func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, Graphics
}
func (g *graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {
return opengl.NewGraphics(g.gomobileContext)
return opengl.NewGraphics()
}
func (*graphicsDriverCreatorImpl) newDirectX() (graphicsdriver.Graphics, error) {
@ -60,9 +57,6 @@ func (*graphicsDriverCreatorImpl) newDirectX() (graphicsdriver.Graphics, error)
}
func (g *graphicsDriverCreatorImpl) newMetal() (graphicsdriver.Graphics, error) {
if g.gomobileContext != nil {
return nil, errors.New("ui: Metal is not available with gomobile-build")
}
return metal.NewGraphics()
}

View File

@ -20,29 +20,18 @@ import (
stdcontext "context"
"fmt"
"image"
"runtime"
"runtime/debug"
"sync"
"sync/atomic"
"unicode"
"golang.org/x/mobile/app"
"golang.org/x/mobile/event/key"
"golang.org/x/mobile/event/lifecycle"
"golang.org/x/mobile/event/paint"
"golang.org/x/mobile/event/size"
"golang.org/x/mobile/event/touch"
"golang.org/x/mobile/gl"
"github.com/hajimehoshi/ebiten/v2/internal/gamepad"
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
"github.com/hajimehoshi/ebiten/v2/internal/hook"
"github.com/hajimehoshi/ebiten/v2/internal/restorable"
)
var (
glContextCh = make(chan gl.Context, 1)
// renderCh receives when updating starts.
renderCh = make(chan struct{})
@ -107,12 +96,6 @@ type userInterfaceImpl struct {
foreground int32
errCh chan error
// Used for gomobile-build
gbuildWidthPx int
gbuildHeightPx int
setGBuildSizeCh chan struct{}
once sync.Once
context *context
inputState InputState
@ -124,103 +107,6 @@ type userInterfaceImpl struct {
m sync.RWMutex
}
// appMain is the main routine for gomobile-build mode.
func (u *UserInterface) appMain(a app.App) {
var glctx gl.Context
var sizeInited bool
touches := map[touch.Sequence]TouchForInput{}
keys := map[Key]struct{}{}
for e := range a.Events() {
var updateInput bool
var runes []rune
switch e := a.Filter(e).(type) {
case lifecycle.Event:
switch e.Crosses(lifecycle.StageVisible) {
case lifecycle.CrossOn:
if err := u.SetForeground(true); err != nil {
// There are no other ways than panicking here.
panic(err)
}
restorable.OnContextLost()
glctx, _ = e.DrawContext.(gl.Context)
// Assume that glctx is always a same instance.
// Then, only once initializing should be enough.
if glContextCh != nil {
glContextCh <- glctx
glContextCh = nil
}
a.Send(paint.Event{})
case lifecycle.CrossOff:
if err := u.SetForeground(false); err != nil {
// There are no other ways than panicking here.
panic(err)
}
glctx = nil
}
case size.Event:
u.setGBuildSize(e.WidthPx, e.HeightPx)
sizeInited = true
case paint.Event:
if !sizeInited {
a.Send(paint.Event{})
continue
}
if glctx == nil || e.External {
continue
}
renderCh <- struct{}{}
<-renderEndCh
a.Publish()
a.Send(paint.Event{})
case touch.Event:
if !sizeInited {
continue
}
switch e.Type {
case touch.TypeBegin, touch.TypeMove:
s := u.DeviceScaleFactor()
touches[e.Sequence] = TouchForInput{
ID: TouchID(e.Sequence),
X: float64(e.X) / s,
Y: float64(e.Y) / s,
}
case touch.TypeEnd:
delete(touches, e.Sequence)
}
updateInput = true
case key.Event:
k, ok := gbuildKeyToUIKey[e.Code]
if ok {
switch e.Direction {
case key.DirPress, key.DirNone:
keys[k] = struct{}{}
case key.DirRelease:
delete(keys, k)
}
}
switch e.Direction {
case key.DirPress, key.DirNone:
if e.Rune != -1 && unicode.IsPrint(e.Rune) {
runes = []rune{e.Rune}
}
}
updateInput = true
}
if updateInput {
var ts []TouchForInput
for _, t := range touches {
ts = append(ts, t)
}
u.updateInputStateFromOutside(keys, runes, ts)
}
}
}
func (u *UserInterface) SetForeground(foreground bool) error {
var v int32
if foreground {
@ -236,26 +122,18 @@ func (u *UserInterface) SetForeground(foreground bool) error {
}
func (u *UserInterface) Run(game Game, options *RunOptions) error {
u.setGBuildSizeCh = make(chan struct{})
go func() {
if err := u.runMobile(game, true, options); err != nil {
// As mobile apps never ends, Loop can't return. Just panic here.
panic(err)
}
}()
app.Main(u.appMain)
return nil
return fmt.Errorf("internal/ui: Run is not implemented for GOOS=%s", runtime.GOOS)
}
func (u *UserInterface) RunWithoutMainLoop(game Game, options *RunOptions) {
go func() {
if err := u.runMobile(game, false, options); err != nil {
if err := u.runMobile(game, options); err != nil {
u.errCh <- err
}
}()
}
func (u *UserInterface) runMobile(game Game, mainloop bool, options *RunOptions) (err error) {
func (u *UserInterface) runMobile(game Game, options *RunOptions) (err error) {
// Convert the panic to a regular error so that Java/Objective-C layer can treat this easily e.g., for
// Crashlytics. A panic is treated as SIGABRT, and there is no way to handle this on Java/Objective-C layer
// unfortunately.
@ -266,23 +144,14 @@ func (u *UserInterface) runMobile(game Game, mainloop bool, options *RunOptions)
}
}()
var mgl gl.Context
if mainloop {
// When gomobile-build is used, GL functions must be called via
// gl.Context so that they are called on the appropriate thread.
mgl = <-glContextCh
} else {
graphicscommand.SetOSThreadAsRenderThread()
}
graphicscommand.SetOSThreadAsRenderThread()
u.setRunning(true)
defer u.setRunning(false)
u.context = newContext(game)
g, lib, err := newGraphicsDriver(&graphicsDriverCreatorImpl{
gomobileContext: mgl,
}, options.GraphicsLibrary)
g, lib, err := newGraphicsDriver(&graphicsDriverCreatorImpl{}, options.GraphicsLibrary)
if err != nil {
return err
}
@ -290,11 +159,6 @@ func (u *UserInterface) runMobile(game Game, mainloop bool, options *RunOptions)
u.setGraphicsLibrary(lib)
close(u.graphicsLibraryInitCh)
// If gomobile-build is used, wait for the outside size fixed.
if u.setGBuildSizeCh != nil {
<-u.setGBuildSizeCh
}
for {
if err := u.update(); err != nil {
return err
@ -304,21 +168,10 @@ func (u *UserInterface) runMobile(game Game, mainloop bool, options *RunOptions)
// outsideSize must be called on the same goroutine as update().
func (u *UserInterface) outsideSize() (float64, float64) {
var outsideWidth, outsideHeight float64
u.m.RLock()
if u.gbuildWidthPx == 0 || u.gbuildHeightPx == 0 {
outsideWidth = u.outsideWidth
outsideHeight = u.outsideHeight
} else {
// gomobile build
d := u.DeviceScaleFactor()
outsideWidth = float64(u.gbuildWidthPx) / d
outsideHeight = float64(u.gbuildHeightPx) / d
}
u.m.RUnlock()
defer u.m.RUnlock()
return outsideWidth, outsideHeight
return u.outsideWidth, u.outsideHeight
}
func (u *UserInterface) update() error {
@ -352,17 +205,6 @@ func (u *UserInterface) SetOutsideSize(outsideWidth, outsideHeight float64) {
u.m.Unlock()
}
func (u *UserInterface) setGBuildSize(widthPx, heightPx int) {
u.m.Lock()
u.gbuildWidthPx = widthPx
u.gbuildHeightPx = heightPx
u.m.Unlock()
u.once.Do(func() {
close(u.setGBuildSizeCh)
})
}
func (u *UserInterface) CursorMode() CursorMode {
return CursorModeHidden
}