From 1e86e7fa18f20c94aba54c8682267acd57028c97 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 14 Nov 2022 02:46:09 +0900 Subject: [PATCH] internal/ui: refactoring: reduce opengles build tags Updates #292 --- .../opengl/graphics_glfw.go} | 14 ++++++++-- internal/ui/ui_glfw.go | 2 +- internal/ui/ui_glfw_gles.go | 28 ------------------- 3 files changed, 12 insertions(+), 32 deletions(-) rename internal/{ui/ui_glfw_gl.go => graphicsdriver/opengl/graphics_glfw.go} (69%) delete mode 100644 internal/ui/ui_glfw_gles.go diff --git a/internal/ui/ui_glfw_gl.go b/internal/graphicsdriver/opengl/graphics_glfw.go similarity index 69% rename from internal/ui/ui_glfw_gl.go rename to internal/graphicsdriver/opengl/graphics_glfw.go index b5f10a193..0b34343a9 100644 --- a/internal/ui/ui_glfw_gl.go +++ b/internal/graphicsdriver/opengl/graphics_glfw.go @@ -12,15 +12,23 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !android && !ios && !js && !nintendosdk && !opengles +//go:build !android && !ios && !js && !nintendosdk -package ui +package opengl import ( "github.com/hajimehoshi/ebiten/v2/internal/glfw" ) -func setGLFWClientAPI() { +func (g *Graphics) SetGLFWClientAPI() { + if g.context.isES() { + glfw.WindowHint(glfw.ClientAPI, glfw.OpenGLESAPI) + glfw.WindowHint(glfw.ContextVersionMajor, 2) + glfw.WindowHint(glfw.ContextVersionMinor, 0) + glfw.WindowHint(glfw.ContextCreationAPI, glfw.EGLContextAPI) + return + } + glfw.WindowHint(glfw.ClientAPI, glfw.OpenGLAPI) glfw.WindowHint(glfw.ContextVersionMajor, 2) glfw.WindowHint(glfw.ContextVersionMinor, 1) diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 4d0ab786d..fca9f2e35 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -906,7 +906,7 @@ func (u *userInterfaceImpl) init() error { u.graphicsDriver.SetTransparent(u.isInitScreenTransparent()) if u.graphicsDriver.IsGL() { - setGLFWClientAPI() + u.graphicsDriver.(interface{ SetGLFWClientAPI() }).SetGLFWClientAPI() } else { glfw.WindowHint(glfw.ClientAPI, glfw.NoAPI) } diff --git a/internal/ui/ui_glfw_gles.go b/internal/ui/ui_glfw_gles.go deleted file mode 100644 index eeee30b48..000000000 --- a/internal/ui/ui_glfw_gles.go +++ /dev/null @@ -1,28 +0,0 @@ -// 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 - -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) - glfw.WindowHint(glfw.ContextCreationAPI, glfw.EGLContextAPI) -}