mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
internal/graphicsdriver/opengl/gl: reland: refactoring: reduce opengles build tags
This is a reland of c9cff69dcb
.
Updates #292
This commit is contained in:
parent
e87e4ffbd2
commit
e8810495cf
@ -608,3 +608,8 @@ func (c *context) endStencilWithEvenOddRule() {
|
||||
c.gl.stencilOp.Invoke(gl.KEEP, gl.KEEP, gl.KEEP)
|
||||
c.gl.colorMask.Invoke(true, true, true, true)
|
||||
}
|
||||
|
||||
func (c *context) isES() bool {
|
||||
// WebGL is compatible with GLES.
|
||||
return true
|
||||
}
|
||||
|
@ -477,3 +477,7 @@ func (c *context) endStencilWithEvenOddRule() {
|
||||
c.ctx.StencilOp(gl.KEEP, gl.KEEP, gl.KEEP)
|
||||
c.ctx.ColorMask(true, true, true, true)
|
||||
}
|
||||
|
||||
func (c *context) isES() bool {
|
||||
return c.ctx.IsES()
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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))
|
||||
|
@ -35,6 +35,8 @@ import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var isES = true
|
||||
|
||||
func getProcAddress(namea string) unsafe.Pointer {
|
||||
const ext = "EXT"
|
||||
if strings.HasSuffix(namea, ext) {
|
||||
|
@ -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))
|
||||
|
@ -24,6 +24,7 @@ import (
|
||||
var (
|
||||
opengl32 = windows.NewLazySystemDLL("opengl32")
|
||||
procWglGetProcAddress = opengl32.NewProc("wglGetProcAddress")
|
||||
isES = false
|
||||
)
|
||||
|
||||
func getProcAddress(namea string) uintptr {
|
||||
|
@ -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.isES()
|
||||
}
|
||||
|
||||
func (g *Graphics) NeedsClearingScreen() bool {
|
||||
|
@ -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
|
@ -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
|
Loading…
Reference in New Issue
Block a user