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 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 ./... 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) - name: go test (Windows 386)
if: ${{ startsWith(matrix.os, 'windows-') }} if: ${{ startsWith(matrix.os, 'windows-') }}
run: | run: |

2
doc.go
View File

@ -99,4 +99,6 @@
// `microsoftgdk` is for Microsoft GDK (e.g. Xbox). // `microsoftgdk` is for Microsoft GDK (e.g. Xbox).
// //
// `nintendosdk` is for NintendoSDK (e.g. Nintendo Switch). // `nintendosdk` is for NintendoSDK (e.g. Nintendo Switch).
//
// `opengles` uses OpenGL ES (2) instead of OpenGL.
package ebiten package ebiten

View File

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

View File

@ -12,9 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//go:build android || ios
// +build android ios
package opengl package opengl
import ( import (

View File

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//go:build !android && !ios && !js //go:build !android && !ios && !js && !opengles
// +build !android,!ios,!js // +build !android,!ios,!js,!opengles
package opengl package opengl

View File

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//go:build android || ios //go:build android || ios || opengles
// +build android ios // +build android ios opengles
package opengl package opengl

View File

@ -12,25 +12,26 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//go:build android || ios //go:build android || ios || opengles
// +build android ios // +build android ios opengles
package gles package gles
// #cgo android CFLAGS: -Dos_android // #cgo !darwin CFLAGS: -Dos_notdarwin
// #cgo android LDFLAGS: -lGLESv2 // #cgo darwin CFLAGS: -Dos_darwin
// #cgo ios CFLAGS: -Dos_ios // #cgo !android,!darwin pkg-config: glesv2
// #cgo ios LDFLAGS: -framework OpenGLES // #cgo android LDFLAGS: -lGLESv2
// #cgo darwin LDFLAGS: -framework OpenGLES
// //
// #if defined(os_android) // #if defined(os_darwin)
// #include <GLES2/gl2.h>
// #endif
//
// #if defined(os_ios)
// #define GLES_SILENCE_DEPRECATION // #define GLES_SILENCE_DEPRECATION
// #include <OpenGLES/ES2/glext.h> // #include <OpenGLES/ES2/glext.h>
// #endif // #endif
// //
// #if defined(os_notdarwin)
// #include <GLES2/gl2.h>
// #endif
//
// #include <stdlib.h> // #include <stdlib.h>
import "C" import "C"

View File

@ -12,9 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//go:build android || ios
// +build android ios
package gles package gles
type Context interface { type Context interface {

View File

@ -12,9 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//go:build android || ios
// +build android ios
package gles package gles
// #include <stdlib.h> // #include <stdlib.h>

View File

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//go:build !android && !ios //go:build !android && !ios && !opengles
// +build !android,!ios // +build !android,!ios,!opengles
package opengl 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" "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) { func (g *Graphics) SetGomobileGLContext(context gl.Context) {
g.context.ctx = gles.NewGomobileContext(context) g.context.ctx = gles.NewGomobileContext(context)
} }

View File

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//go:build !android && !ios && !js //go:build !android && !ios && !js && !opengles
// +build !android,!ios,!js // +build !android,!ios,!js,!opengles
package opengl package opengl

View File

@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
//go:build android || ios //go:build android || ios || opengles
// +build android ios // +build android ios opengles
package opengl package opengl

View File

@ -896,9 +896,7 @@ func (u *userInterfaceImpl) init() error {
u.graphicsDriver.SetTransparent(u.isInitScreenTransparent()) u.graphicsDriver.SetTransparent(u.isInitScreenTransparent())
if u.graphicsDriver.IsGL() { if u.graphicsDriver.IsGL() {
glfw.WindowHint(glfw.ClientAPI, glfw.OpenGLAPI) setGLFWClientAPI()
glfw.WindowHint(glfw.ContextVersionMajor, 2)
glfw.WindowHint(glfw.ContextVersionMinor, 1)
} else { } else {
glfw.WindowHint(glfw.ClientAPI, glfw.NoAPI) 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)
}