internal/graphicsdriver/opengl: initialize gl at init()

This changes context_gl.go a little closer to context_gles.go.

Updates #2451
This commit is contained in:
Hajime Hoshi 2022-11-13 04:13:15 +09:00
parent bb30b85d29
commit c4abaa32f5
5 changed files with 13 additions and 14 deletions

View File

@ -83,18 +83,9 @@ func getProgramID(p program) programID {
}
type contextImpl struct {
init bool
}
func (c *context) reset() error {
if !c.init {
// Note that this initialization must be done after Loop is called.
if err := gl.Init(); err != nil {
return fmt.Errorf("opengl: initializing error %v", err)
}
c.init = true
}
c.locationCache = newLocationCache()
c.lastTexture = invalidTexture
c.lastFramebuffer = invalidFramebuffer

View File

@ -30,7 +30,9 @@ func NewGraphics() (graphicsdriver.Graphics, error) {
return nil, fmt.Errorf("opengl: OpenGL is not supported on Xbox")
}
g := &Graphics{}
g.init()
if err := g.init(); err != nil {
return nil, err
}
return g, nil
}

View File

@ -16,6 +16,10 @@
package opengl
func (g *Graphics) init() {
// Do nothing.
import (
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gl"
)
func (g *Graphics) init() error {
return gl.Init()
}

View File

@ -20,6 +20,7 @@ import (
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gles"
)
func (g *Graphics) init() {
func (g *Graphics) init() error {
g.context.ctx = gles.DefaultContext{}
return nil
}

View File

@ -18,8 +18,9 @@ import (
"syscall/js"
)
func (g *Graphics) init() {
func (g *Graphics) init() error {
// Do nothing.
return nil
}
func (g *Graphics) SetCanvas(canvas js.Value) {