From c4abaa32f5363dd6355897b785c6dcad217f5939 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 13 Nov 2022 04:13:15 +0900 Subject: [PATCH] internal/graphicsdriver/opengl: initialize gl at init() This changes context_gl.go a little closer to context_gles.go. Updates #2451 --- internal/graphicsdriver/opengl/context_gl.go | 9 --------- internal/graphicsdriver/opengl/graphics.go | 4 +++- internal/graphicsdriver/opengl/graphics_gl.go | 8 ++++++-- internal/graphicsdriver/opengl/graphics_gles.go | 3 ++- internal/graphicsdriver/opengl/graphics_js.go | 3 ++- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/internal/graphicsdriver/opengl/context_gl.go b/internal/graphicsdriver/opengl/context_gl.go index 1e98633df..dc950607e 100644 --- a/internal/graphicsdriver/opengl/context_gl.go +++ b/internal/graphicsdriver/opengl/context_gl.go @@ -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 diff --git a/internal/graphicsdriver/opengl/graphics.go b/internal/graphicsdriver/opengl/graphics.go index da2bc89c0..410d9df3d 100644 --- a/internal/graphicsdriver/opengl/graphics.go +++ b/internal/graphicsdriver/opengl/graphics.go @@ -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 } diff --git a/internal/graphicsdriver/opengl/graphics_gl.go b/internal/graphicsdriver/opengl/graphics_gl.go index 5977ca58d..f4a792da5 100644 --- a/internal/graphicsdriver/opengl/graphics_gl.go +++ b/internal/graphicsdriver/opengl/graphics_gl.go @@ -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() } diff --git a/internal/graphicsdriver/opengl/graphics_gles.go b/internal/graphicsdriver/opengl/graphics_gles.go index cf18ca117..355f1701e 100644 --- a/internal/graphicsdriver/opengl/graphics_gles.go +++ b/internal/graphicsdriver/opengl/graphics_gles.go @@ -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 } diff --git a/internal/graphicsdriver/opengl/graphics_js.go b/internal/graphicsdriver/opengl/graphics_js.go index 5db692eae..46b7f964d 100644 --- a/internal/graphicsdriver/opengl/graphics_js.go +++ b/internal/graphicsdriver/opengl/graphics_js.go @@ -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) {