mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-24 09:52:03 +01:00
internal/graphicsdriver/opengl: move egl
to the package opengl
Updates #2714
This commit is contained in:
parent
425b4dd99a
commit
6fd18150d8
@ -14,8 +14,11 @@
|
|||||||
|
|
||||||
//go:build nintendosdk
|
//go:build nintendosdk
|
||||||
|
|
||||||
package ui
|
package opengl
|
||||||
|
|
||||||
|
// #cgo !darwin LDFLAGS: -Wl,-unresolved-symbols=ignore-all
|
||||||
|
// #cgo darwin LDFLAGS: -Wl,-undefined,dynamic_lookup
|
||||||
|
//
|
||||||
// #include <EGL/egl.h>
|
// #include <EGL/egl.h>
|
||||||
// #include <EGL/eglext.h>
|
// #include <EGL/eglext.h>
|
||||||
import "C"
|
import "C"
|
||||||
@ -30,7 +33,7 @@ type egl struct {
|
|||||||
context C.EGLContext
|
context C.EGLContext
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *egl) init(nativeWindowHandle C.NativeWindowType) error {
|
func (e *egl) init(nativeWindowHandle uintptr) error {
|
||||||
// Initialize EGL
|
// Initialize EGL
|
||||||
e.display = C.eglGetDisplay(C.NativeDisplayType(C.EGL_DEFAULT_DISPLAY))
|
e.display = C.eglGetDisplay(C.NativeDisplayType(C.EGL_DEFAULT_DISPLAY))
|
||||||
if e.display == 0 {
|
if e.display == 0 {
|
||||||
@ -58,7 +61,7 @@ func (e *egl) init(nativeWindowHandle C.NativeWindowType) error {
|
|||||||
return fmt.Errorf("ui: eglChooseConfig failed: numConfigs must be 1 but %d", numConfigs)
|
return fmt.Errorf("ui: eglChooseConfig failed: numConfigs must be 1 but %d", numConfigs)
|
||||||
}
|
}
|
||||||
|
|
||||||
e.surface = C.eglCreateWindowSurface(e.display, config, nativeWindowHandle, nil)
|
e.surface = C.eglCreateWindowSurface(e.display, config, C.NativeWindowType(nativeWindowHandle), nil)
|
||||||
if e.surface == C.EGLSurface(C.EGL_NO_SURFACE) {
|
if e.surface == C.EGLSurface(C.EGL_NO_SURFACE) {
|
||||||
return fmt.Errorf("ui: eglCreateWindowSurface failed")
|
return fmt.Errorf("ui: eglCreateWindowSurface failed")
|
||||||
}
|
}
|
@ -76,7 +76,9 @@ func (g *Graphics) End(present bool) error {
|
|||||||
// The last uniforms must be reset before swapping the buffer (#2517).
|
// The last uniforms must be reset before swapping the buffer (#2517).
|
||||||
if present {
|
if present {
|
||||||
g.state.resetLastUniforms()
|
g.state.resetLastUniforms()
|
||||||
|
g.swapBuffers()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +159,11 @@ func (g *Graphics) removeImage(img *Image) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *Graphics) Initialize() error {
|
func (g *Graphics) Initialize() error {
|
||||||
return g.state.reset(&g.context)
|
g.makeContextCurrent()
|
||||||
|
if err := g.state.reset(&g.context); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset resets or initializes the current OpenGL state.
|
// Reset resets or initializes the current OpenGL state.
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
// 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 && !nintendosdk
|
||||||
|
|
||||||
package opengl
|
package opengl
|
||||||
|
|
||||||
@ -38,3 +38,11 @@ func NewGraphics() (graphicsdriver.Graphics, error) {
|
|||||||
|
|
||||||
return newGraphics(ctx), nil
|
return newGraphics(ctx), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *Graphics) makeContextCurrent() {
|
||||||
|
// TODO: Implement this (#2714).
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Graphics) swapBuffers() {
|
||||||
|
// TODO: Implement this (#2714).
|
||||||
|
}
|
||||||
|
@ -45,3 +45,9 @@ func NewGraphics(canvas js.Value) (graphicsdriver.Graphics, error) {
|
|||||||
|
|
||||||
return newGraphics(ctx), nil
|
return newGraphics(ctx), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *Graphics) makeContextCurrent() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Graphics) swapBuffers() {
|
||||||
|
}
|
||||||
|
@ -39,3 +39,11 @@ func NewGraphics(context mgl.Context) (graphicsdriver.Graphics, error) {
|
|||||||
|
|
||||||
return newGraphics(ctx), nil
|
return newGraphics(ctx), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *Graphics) makeContextCurrent() {
|
||||||
|
// TODO: Implement this (#2714).
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Graphics) swapBuffers() {
|
||||||
|
// TODO: Implement this (#2714).
|
||||||
|
}
|
||||||
|
44
internal/graphicsdriver/opengl/graphics_nintendosdk.go
Normal file
44
internal/graphicsdriver/opengl/graphics_nintendosdk.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// Copyright 2023 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 nintendosdk
|
||||||
|
|
||||||
|
package opengl
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||||
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gl"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
theEGL egl
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewGraphics(nativeWindowType uintptr) (graphicsdriver.Graphics, error) {
|
||||||
|
theEGL.init(nativeWindowType)
|
||||||
|
|
||||||
|
ctx, err := gl.NewDefaultContext()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return newGraphics(ctx), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Graphics) makeContextCurrent() {
|
||||||
|
theEGL.makeContextCurrent()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Graphics) swapBuffers() {
|
||||||
|
theEGL.swapBuffers()
|
||||||
|
}
|
@ -30,15 +30,17 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl"
|
||||||
)
|
)
|
||||||
|
|
||||||
type graphicsDriverCreatorImpl struct{}
|
type graphicsDriverCreatorImpl struct {
|
||||||
|
nativeWindow C.NativeWindowType
|
||||||
|
}
|
||||||
|
|
||||||
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, GraphicsLibrary, error) {
|
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, GraphicsLibrary, error) {
|
||||||
graphics, err := g.newOpenGL()
|
graphics, err := g.newOpenGL()
|
||||||
return graphics, GraphicsLibraryOpenGL, err
|
return graphics, GraphicsLibraryOpenGL, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {
|
func (g *graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {
|
||||||
return opengl.NewGraphics()
|
return opengl.NewGraphics(uintptr(g.nativeWindow))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*graphicsDriverCreatorImpl) newDirectX() (graphicsdriver.Graphics, error) {
|
func (*graphicsDriverCreatorImpl) newDirectX() (graphicsdriver.Graphics, error) {
|
||||||
@ -66,8 +68,6 @@ type userInterfaceImpl struct {
|
|||||||
inputState InputState
|
inputState InputState
|
||||||
nativeTouches []C.struct_Touch
|
nativeTouches []C.struct_Touch
|
||||||
|
|
||||||
egl egl
|
|
||||||
|
|
||||||
m sync.Mutex
|
m sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,34 +76,26 @@ func (u *UserInterface) init() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) initOnMainThread(options *RunOptions) error {
|
func (u *UserInterface) initOnMainThread(options *RunOptions) error {
|
||||||
g, lib, err := newGraphicsDriver(&graphicsDriverCreatorImpl{}, options.GraphicsLibrary)
|
n := C.ebitengine_Initialize()
|
||||||
|
g, lib, err := newGraphicsDriver(&graphicsDriverCreatorImpl{
|
||||||
|
nativeWindow: n,
|
||||||
|
}, options.GraphicsLibrary)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
u.graphicsDriver = g
|
u.graphicsDriver = g
|
||||||
u.setGraphicsLibrary(lib)
|
u.setGraphicsLibrary(lib)
|
||||||
|
|
||||||
n := C.ebitengine_Initialize()
|
|
||||||
if err := u.egl.init(n); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
initializeProfiler()
|
initializeProfiler()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) loopGame() error {
|
func (u *UserInterface) loopGame() error {
|
||||||
u.renderThread.Call(func() {
|
|
||||||
u.egl.makeContextCurrent()
|
|
||||||
})
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
recordProfilerHeartbeat()
|
recordProfilerHeartbeat()
|
||||||
|
|
||||||
if err := u.context.updateFrame(u.graphicsDriver, float64(C.kScreenWidth), float64(C.kScreenHeight), deviceScaleFactor, u, func() {
|
if err := u.context.updateFrame(u.graphicsDriver, float64(C.kScreenWidth), float64(C.kScreenHeight), deviceScaleFactor, u, nil); err != nil {
|
||||||
u.egl.swapBuffers()
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user