mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/graphicsdriver/opengl: refactoring
This commit is contained in:
parent
01a4e29c5b
commit
ee2ca6d20c
@ -37,11 +37,11 @@ func (e *egl) init(nativeWindowHandle uintptr) error {
|
||||
// Initialize EGL
|
||||
e.display = C.eglGetDisplay(C.NativeDisplayType(C.EGL_DEFAULT_DISPLAY))
|
||||
if e.display == 0 {
|
||||
return fmt.Errorf("ui: eglGetDisplay failed")
|
||||
return fmt.Errorf("opengl: eglGetDisplay failed")
|
||||
}
|
||||
|
||||
if r := C.eglInitialize(e.display, nil, nil); r == 0 {
|
||||
return fmt.Errorf("ui: eglInitialize failed")
|
||||
return fmt.Errorf("opengl: eglInitialize failed")
|
||||
}
|
||||
|
||||
configAttribs := []C.EGLint{
|
||||
@ -55,20 +55,20 @@ func (e *egl) init(nativeWindowHandle uintptr) error {
|
||||
var numConfigs C.EGLint
|
||||
var config C.EGLConfig
|
||||
if r := C.eglChooseConfig(e.display, &configAttribs[0], &config, 1, &numConfigs); r == 0 {
|
||||
return fmt.Errorf("ui: eglChooseConfig failed")
|
||||
return fmt.Errorf("opengl: eglChooseConfig failed")
|
||||
}
|
||||
if numConfigs != 1 {
|
||||
return fmt.Errorf("ui: eglChooseConfig failed: numConfigs must be 1 but %d", numConfigs)
|
||||
return fmt.Errorf("opengl: eglChooseConfig failed: numConfigs must be 1 but %d", numConfigs)
|
||||
}
|
||||
|
||||
e.surface = C.eglCreateWindowSurface(e.display, config, C.NativeWindowType(nativeWindowHandle), nil)
|
||||
if e.surface == C.EGLSurface(C.EGL_NO_SURFACE) {
|
||||
return fmt.Errorf("ui: eglCreateWindowSurface failed")
|
||||
return fmt.Errorf("opengl: eglCreateWindowSurface failed")
|
||||
}
|
||||
|
||||
// Set the current rendering API.
|
||||
if r := C.eglBindAPI(C.EGL_OPENGL_API); r == 0 {
|
||||
return fmt.Errorf("ui: eglBindAPI failed")
|
||||
return fmt.Errorf("opengl: eglBindAPI failed")
|
||||
}
|
||||
|
||||
// Create new context and set it as current.
|
||||
@ -81,7 +81,7 @@ func (e *egl) init(nativeWindowHandle uintptr) error {
|
||||
C.EGL_NONE}
|
||||
e.context = C.eglCreateContext(e.display, config, C.EGLContext(C.EGL_NO_CONTEXT), &contextAttribs[0])
|
||||
if e.context == C.EGLContext(C.EGL_NO_CONTEXT) {
|
||||
return fmt.Errorf("ui: eglCreateContext failed: error: %d", C.eglGetError())
|
||||
return fmt.Errorf("opengl: eglCreateContext failed: error: %d", C.eglGetError())
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -89,7 +89,7 @@ func (e *egl) init(nativeWindowHandle uintptr) error {
|
||||
|
||||
func (e *egl) makeContextCurrent() error {
|
||||
if r := C.eglMakeCurrent(e.display, e.surface, e.surface, e.context); r == 0 {
|
||||
return fmt.Errorf("ui: eglMakeCurrent failed")
|
||||
return fmt.Errorf("opengl: eglMakeCurrent failed")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -166,7 +166,9 @@ func (g *Graphics) removeImage(img *Image) {
|
||||
}
|
||||
|
||||
func (g *Graphics) Initialize() error {
|
||||
g.makeContextCurrent()
|
||||
if err := g.makeContextCurrent(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := g.state.reset(&g.context); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -83,8 +83,9 @@ func setGLFWClientAPI(isES bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *Graphics) makeContextCurrent() {
|
||||
func (g *Graphics) makeContextCurrent() error {
|
||||
// TODO: Implement this (#2714).
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *Graphics) swapBuffers() error {
|
||||
|
@ -46,7 +46,8 @@ func NewGraphics(canvas js.Value) (graphicsdriver.Graphics, error) {
|
||||
return newGraphics(ctx), nil
|
||||
}
|
||||
|
||||
func (g *Graphics) makeContextCurrent() {
|
||||
func (g *Graphics) makeContextCurrent() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *Graphics) swapBuffers() error {
|
||||
|
@ -40,7 +40,8 @@ func NewGraphics(context mgl.Context) (graphicsdriver.Graphics, error) {
|
||||
return newGraphics(ctx), nil
|
||||
}
|
||||
|
||||
func (g *Graphics) makeContextCurrent() {
|
||||
func (g *Graphics) makeContextCurrent() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *Graphics) swapBuffers() error {
|
||||
|
@ -35,8 +35,8 @@ func NewGraphics(nativeWindowType uintptr) (graphicsdriver.Graphics, error) {
|
||||
return newGraphics(ctx), nil
|
||||
}
|
||||
|
||||
func (g *Graphics) makeContextCurrent() {
|
||||
theEGL.makeContextCurrent()
|
||||
func (g *Graphics) makeContextCurrent() error {
|
||||
return theEGL.makeContextCurrent()
|
||||
}
|
||||
|
||||
func (g *Graphics) swapBuffers() error {
|
||||
|
Loading…
Reference in New Issue
Block a user