diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 381925657..52e439340 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -143,6 +143,12 @@ jobs: sudo apt-get install libasound2-dev:i386 libgl1-mesa-dev:i386 libxcursor-dev:i386 libxi-dev:i386 libxinerama-dev:i386 libxrandr-dev:i386 libxxf86vm-dev:i386 env CGO_ENABLED=1 GOARCH=386 go test -tags=example ${{ !startsWith(matrix.go, '1.16.') && '-shuffle=on' || '' }} -v ./... + - name: go test (Linux OpenGL ES) + if: ${{ startsWith(matrix.os, 'ubuntu-') }} + run: | + sudo apt-get install libgles2-mesa-dev + env EBITENGINE_GRAPHICS_LIBRARY=opengl go test -tags=example,opengles ${{ !startsWith(matrix.go, '1.16.') && '-shuffle=on' || '' }} -v ./... + - name: go test (Windows 386) if: ${{ startsWith(matrix.os, 'windows-') }} run: | diff --git a/doc.go b/doc.go index 5ac46efa3..f9acfab66 100644 --- a/doc.go +++ b/doc.go @@ -99,4 +99,6 @@ // `microsoftgdk` is for Microsoft GDK (e.g. Xbox). // // `nintendosdk` is for NintendoSDK (e.g. Nintendo Switch). +// +// `opengles` uses OpenGL ES (2) instead of OpenGL. package ebiten diff --git a/internal/glfw/const.go b/internal/glfw/const.go index 74fb82a1c..968add24b 100644 --- a/internal/glfw/const.go +++ b/internal/glfw/const.go @@ -85,6 +85,7 @@ const ( CursorNormal = 0x00034001 NoAPI = 0 OpenGLAPI = 0x00030001 + OpenGLESAPI = 0x00030002 ) const ( diff --git a/internal/graphicsdriver/opengl/bytes.go b/internal/graphicsdriver/opengl/bytes.go index ba1be200d..88105a9c4 100644 --- a/internal/graphicsdriver/opengl/bytes.go +++ b/internal/graphicsdriver/opengl/bytes.go @@ -12,9 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build android || ios -// +build android ios - package opengl import ( diff --git a/internal/graphicsdriver/opengl/context_gl.go b/internal/graphicsdriver/opengl/context_gl.go index a19c0163f..a4e492d9c 100644 --- a/internal/graphicsdriver/opengl/context_gl.go +++ b/internal/graphicsdriver/opengl/context_gl.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !android && !ios && !js -// +build !android,!ios,!js +//go:build !android && !ios && !js && !opengles +// +build !android,!ios,!js,!opengles package opengl diff --git a/internal/graphicsdriver/opengl/context_gles.go b/internal/graphicsdriver/opengl/context_gles.go index 5d5212a1a..69ce5018d 100644 --- a/internal/graphicsdriver/opengl/context_gles.go +++ b/internal/graphicsdriver/opengl/context_gles.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build android || ios -// +build android ios +//go:build android || ios || opengles +// +build android ios opengles package opengl diff --git a/internal/graphicsdriver/opengl/gles/default.go b/internal/graphicsdriver/opengl/gles/default.go index 2bd7d8b2b..ba57fb96b 100644 --- a/internal/graphicsdriver/opengl/gles/default.go +++ b/internal/graphicsdriver/opengl/gles/default.go @@ -12,25 +12,26 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build android || ios -// +build android ios +//go:build android || ios || opengles +// +build android ios opengles package gles -// #cgo android CFLAGS: -Dos_android -// #cgo android LDFLAGS: -lGLESv2 -// #cgo ios CFLAGS: -Dos_ios -// #cgo ios LDFLAGS: -framework OpenGLES +// #cgo !darwin CFLAGS: -Dos_notdarwin +// #cgo darwin CFLAGS: -Dos_darwin +// #cgo !android,!darwin pkg-config: glesv2 +// #cgo android LDFLAGS: -lGLESv2 +// #cgo darwin LDFLAGS: -framework OpenGLES // -// #if defined(os_android) -// #include -// #endif -// -// #if defined(os_ios) +// #if defined(os_darwin) // #define GLES_SILENCE_DEPRECATION // #include // #endif // +// #if defined(os_notdarwin) +// #include +// #endif +// // #include import "C" diff --git a/internal/graphicsdriver/opengl/gles/interface.go b/internal/graphicsdriver/opengl/gles/interface.go index 6ee40ac30..6258fe625 100644 --- a/internal/graphicsdriver/opengl/gles/interface.go +++ b/internal/graphicsdriver/opengl/gles/interface.go @@ -12,9 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build android || ios -// +build android ios - package gles type Context interface { diff --git a/internal/graphicsdriver/opengl/gles/str.go b/internal/graphicsdriver/opengl/gles/str.go index 3ec6be9ea..aeaa26a0e 100644 --- a/internal/graphicsdriver/opengl/gles/str.go +++ b/internal/graphicsdriver/opengl/gles/str.go @@ -12,9 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build android || ios -// +build android ios - package gles // #include diff --git a/internal/graphicsdriver/opengl/graphics_notmobile.go b/internal/graphicsdriver/opengl/graphics_gl.go similarity index 89% rename from internal/graphicsdriver/opengl/graphics_notmobile.go rename to internal/graphicsdriver/opengl/graphics_gl.go index b943ffda1..a52b26ca3 100644 --- a/internal/graphicsdriver/opengl/graphics_notmobile.go +++ b/internal/graphicsdriver/opengl/graphics_gl.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !android && !ios -// +build !android,!ios +//go:build !android && !ios && !opengles +// +build !android,!ios,!opengles package opengl diff --git a/internal/graphicsdriver/opengl/graphics_gles.go b/internal/graphicsdriver/opengl/graphics_gles.go new file mode 100644 index 000000000..967784374 --- /dev/null +++ b/internal/graphicsdriver/opengl/graphics_gles.go @@ -0,0 +1,26 @@ +// Copyright 2022 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. + +//go:build android || ios || opengles +// +build android ios opengles + +package opengl + +import ( + "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gles" +) + +func (g *Graphics) init() { + g.context.ctx = gles.DefaultContext{} +} diff --git a/internal/graphicsdriver/opengl/graphics_mobile.go b/internal/graphicsdriver/opengl/graphics_mobile.go index 849636f21..baf631da5 100644 --- a/internal/graphicsdriver/opengl/graphics_mobile.go +++ b/internal/graphicsdriver/opengl/graphics_mobile.go @@ -23,10 +23,6 @@ import ( "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gles" ) -func (g *Graphics) init() { - g.context.ctx = gles.DefaultContext{} -} - func (g *Graphics) SetGomobileGLContext(context gl.Context) { g.context.ctx = gles.NewGomobileContext(context) } diff --git a/internal/graphicsdriver/opengl/shader_desktop.go b/internal/graphicsdriver/opengl/shader_gl.go similarity index 89% rename from internal/graphicsdriver/opengl/shader_desktop.go rename to internal/graphicsdriver/opengl/shader_gl.go index 540ca5cbf..e964927aa 100644 --- a/internal/graphicsdriver/opengl/shader_desktop.go +++ b/internal/graphicsdriver/opengl/shader_gl.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !android && !ios && !js -// +build !android,!ios,!js +//go:build !android && !ios && !js && !opengles +// +build !android,!ios,!js,!opengles package opengl diff --git a/internal/graphicsdriver/opengl/shader_mobile.go b/internal/graphicsdriver/opengl/shader_gles.go similarity index 91% rename from internal/graphicsdriver/opengl/shader_mobile.go rename to internal/graphicsdriver/opengl/shader_gles.go index d75482918..77cce3c2a 100644 --- a/internal/graphicsdriver/opengl/shader_mobile.go +++ b/internal/graphicsdriver/opengl/shader_gles.go @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build android || ios -// +build android ios +//go:build android || ios || opengles +// +build android ios opengles package opengl diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index dad11c5df..b86c1103f 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -896,9 +896,7 @@ func (u *userInterfaceImpl) init() error { u.graphicsDriver.SetTransparent(u.isInitScreenTransparent()) if u.graphicsDriver.IsGL() { - glfw.WindowHint(glfw.ClientAPI, glfw.OpenGLAPI) - glfw.WindowHint(glfw.ContextVersionMajor, 2) - glfw.WindowHint(glfw.ContextVersionMinor, 1) + setGLFWClientAPI() } else { glfw.WindowHint(glfw.ClientAPI, glfw.NoAPI) } diff --git a/internal/ui/ui_glfw_gl.go b/internal/ui/ui_glfw_gl.go new file mode 100644 index 000000000..a2c7a1409 --- /dev/null +++ b/internal/ui/ui_glfw_gl.go @@ -0,0 +1,28 @@ +// Copyright 2022 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. + +//go:build !android && !ios && !js && !nintendosdk && !opengles +// +build !android,!ios,!js,!nintendosdk,!opengles + +package ui + +import ( + "github.com/hajimehoshi/ebiten/v2/internal/glfw" +) + +func setGLFWClientAPI() { + glfw.WindowHint(glfw.ClientAPI, glfw.OpenGLAPI) + glfw.WindowHint(glfw.ContextVersionMajor, 2) + glfw.WindowHint(glfw.ContextVersionMinor, 1) +} diff --git a/internal/ui/ui_glfw_gles.go b/internal/ui/ui_glfw_gles.go new file mode 100644 index 000000000..a7338552d --- /dev/null +++ b/internal/ui/ui_glfw_gles.go @@ -0,0 +1,28 @@ +// Copyright 2022 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. + +//go:build !android && !ios && !js && !nintendosdk && opengles +// +build !android,!ios,!js,!nintendosdk,opengles + +package ui + +import ( + "github.com/hajimehoshi/ebiten/v2/internal/glfw" +) + +func setGLFWClientAPI() { + glfw.WindowHint(glfw.ClientAPI, glfw.OpenGLESAPI) + glfw.WindowHint(glfw.ContextVersionMajor, 2) + glfw.WindowHint(glfw.ContextVersionMinor, 0) +}