diff --git a/internal/graphicsdriver/opengl/context.go b/internal/graphicsdriver/opengl/context.go index 23df2e56b..d4799e023 100644 --- a/internal/graphicsdriver/opengl/context.go +++ b/internal/graphicsdriver/opengl/context.go @@ -124,7 +124,6 @@ type context struct { maxTextureSizeOnce sync.Once highp bool highpOnce sync.Once - initOnce sync.Once contextPlatform } @@ -191,25 +190,14 @@ func (c *context) getMaxTextureSize() int { return c.maxTextureSize } -func (c *context) reset() error { - var err1 error - c.initOnce.Do(func() { - // Load OpenGL functions after WGL is initialized especially for Windows (#2452). - if err := c.ctx.LoadFunctions(); err != nil { - err1 = err - return - } - }) - if err1 != nil { - return err1 +func (c *context) init() error { + // Load OpenGL functions after WGL is initialized especially for Windows (#2452). + if err := c.ctx.LoadFunctions(); err != nil { + return err } c.locationCache = newLocationCache() - c.lastTexture = 0 c.lastFramebuffer = invalidFramebuffer - c.lastViewportWidth = 0 - c.lastViewportHeight = 0 - c.lastBlend = graphicsdriver.Blend{} c.ctx.Enable(gl.BLEND) c.ctx.Enable(gl.SCISSOR_TEST) diff --git a/internal/graphicsdriver/opengl/graphics.go b/internal/graphicsdriver/opengl/graphics.go index 15d1774ff..72fcbb648 100644 --- a/internal/graphicsdriver/opengl/graphics.go +++ b/internal/graphicsdriver/opengl/graphics.go @@ -146,12 +146,7 @@ func (g *Graphics) removeImage(img *Image) { } func (g *Graphics) Initialize() error { - return g.state.reset(&g.context) -} - -// Reset resets or initializes the current OpenGL state. -func (g *Graphics) Reset() error { - return g.state.reset(&g.context) + return g.context.init() } func (g *Graphics) SetVertices(vertices []float32, indices []uint16) error { diff --git a/internal/graphicsdriver/opengl/program.go b/internal/graphicsdriver/opengl/program.go index 99fe7da0d..69f19adc2 100644 --- a/internal/graphicsdriver/opengl/program.go +++ b/internal/graphicsdriver/opengl/program.go @@ -16,7 +16,6 @@ package opengl import ( "fmt" - "runtime" "unsafe" "github.com/hajimehoshi/ebiten/v2/internal/graphics" @@ -122,34 +121,6 @@ type openGLState struct { lastActiveTexture int } -// reset resets or initializes the OpenGL state. -func (s *openGLState) reset(context *context) error { - if err := context.reset(); err != nil { - return err - } - - s.lastProgram = 0 - context.ctx.UseProgram(0) - for key := range s.lastUniforms { - delete(s.lastUniforms, key) - } - - // On browsers (at least Chrome), buffers are already detached from the context - // and must not be deleted by DeleteBuffer. - if runtime.GOOS != "js" { - if s.arrayBuffer != 0 { - context.ctx.DeleteBuffer(uint32(s.arrayBuffer)) - } - if s.elementArrayBuffer != 0 { - context.ctx.DeleteBuffer(uint32(s.elementArrayBuffer)) - } - } - s.arrayBuffer = 0 - s.elementArrayBuffer = 0 - - return nil -} - func (s *openGLState) setVertices(context *context, vertices []float32, indices []uint16) { if s.arrayBuffer == 0 { s.arrayBuffer = context.newArrayBuffer(graphics.IndicesCount * graphics.VertexFloatCount * floatSizeInBytes)