internal/graphicsdriver/opengl/gl: refactoring

This commit is contained in:
Hajime Hoshi 2022-11-14 02:03:36 +09:00
parent 94291ecb17
commit c9cff69dcb
13 changed files with 35 additions and 42 deletions

View File

@ -41,6 +41,10 @@ func (defaultContext) Init() error {
return nil
}
func (defaultContext) IsES() bool {
return true
}
func (defaultContext) ActiveTexture(texture uint32) {
C.glActiveTexture(C.GLenum(texture))
}

View File

@ -406,6 +406,10 @@ func boolToInt(b bool) int {
return 0
}
func (c *defaultContext) IsES() bool {
return isES
}
func (c *defaultContext) ActiveTexture(texture uint32) {
C.glowActiveTexture(c.gpActiveTexture, (C.GLenum)(texture))
}

View File

@ -107,6 +107,10 @@ func boolToInt(b bool) int {
return 0
}
func (c *defaultContext) IsES() bool {
return isES
}
func (c *defaultContext) ActiveTexture(texture uint32) {
purego.SyscallN(c.gpActiveTexture, uintptr(texture))
}

View File

@ -39,6 +39,10 @@ func (g *gomobileContext) Init() error {
return nil
}
func (g *gomobileContext) IsES() bool {
return true
}
func (g *gomobileContext) ActiveTexture(texture uint32) {
g.ctx.ActiveTexture(gl.Enum(texture))
}

View File

@ -20,6 +20,7 @@ package gl
// See https://pkg.go.dev/golang.org/x/mobile/gl#Context
type Context interface {
Init() error
IsES() bool
ActiveTexture(texture uint32)
AttachShader(program uint32, shader uint32)

View File

@ -18,11 +18,15 @@ import (
"github.com/ebitengine/purego"
)
var opengl uintptr
var (
opengl uintptr
isES bool
)
func init() {
opengl = purego.Dlopen("/System/Library/Frameworks/OpenGLES.framework/Versions/Current/OpenGLES", purego.RTLD_GLOBAL)
if opengl != 0 {
isES = true
return
}
opengl = purego.Dlopen("/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL", purego.RTLD_GLOBAL)

View File

@ -28,6 +28,8 @@ import "C"
import "unsafe"
var isES = false
func getProcAddress(namea string) unsafe.Pointer {
cname := C.CString(namea)
defer C.free(unsafe.Pointer(cname))

View File

@ -35,6 +35,8 @@ import (
"unsafe"
)
var isES = true
func getProcAddress(namea string) unsafe.Pointer {
const ext = "EXT"
if strings.HasSuffix(namea, ext) {

View File

@ -28,6 +28,8 @@ import "C"
import "unsafe"
var isES = false
func getProcAddress(namea string) unsafe.Pointer {
cname := C.CString(namea)
defer C.free(unsafe.Pointer(cname))

View File

@ -24,6 +24,7 @@ import (
var (
opengl32 = windows.NewLazySystemDLL("opengl32")
procWglGetProcAddress = opengl32.NewProc("wglGetProcAddress")
isES = false
)
func getProcAddress(namea string) uintptr {

View File

@ -16,6 +16,7 @@ package opengl
import (
"fmt"
"runtime"
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
@ -265,7 +266,11 @@ func (g *Graphics) SetFullscreen(fullscreen bool) {
}
func (g *Graphics) NeedsRestoring() bool {
return needsRestoring
// Though it is possible to have a logic to restore the graphics data for GPU, do not use it for performance (#1603).
if runtime.GOOS == "js" {
return false
}
return g.context.ctx.IsES()
}
func (g *Graphics) NeedsClearingScreen() bool {

View File

@ -1,21 +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 && !opengles
package opengl
// Though it is possible to have a logic to restore the graphics data for GPU, do not use it for performance (#1603).
const needsRestoring = false

View File

@ -1,19 +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 || opengles
package opengl
const needsRestoring = true