internal/graphicsdriver/opengl: add opengles build tag

This enables to use OpenGL ES instead of OpenGL.

Closes #292
This commit is contained in:
Hajime Hoshi 2022-09-12 23:28:43 +09:00
parent f1040d0507
commit 86706c0335
17 changed files with 114 additions and 37 deletions

View File

@ -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: |

2
doc.go
View File

@ -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

View File

@ -85,6 +85,7 @@ const (
CursorNormal = 0x00034001
NoAPI = 0
OpenGLAPI = 0x00030001
OpenGLESAPI = 0x00030002
)
const (

View File

@ -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 (

View File

@ -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

View File

@ -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

View File

@ -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 <GLES2/gl2.h>
// #endif
//
// #if defined(os_ios)
// #if defined(os_darwin)
// #define GLES_SILENCE_DEPRECATION
// #include <OpenGLES/ES2/glext.h>
// #endif
//
// #if defined(os_notdarwin)
// #include <GLES2/gl2.h>
// #endif
//
// #include <stdlib.h>
import "C"

View File

@ -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 {

View File

@ -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 <stdlib.h>

View File

@ -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

View File

@ -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{}
}

View File

@ -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)
}

View File

@ -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

View File

@ -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

View File

@ -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)
}

28
internal/ui/ui_glfw_gl.go Normal file
View File

@ -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)
}

View File

@ -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)
}