diff --git a/graphicscontext.go b/graphicscontext.go index b745ce5de..1581180eb 100644 --- a/graphicscontext.go +++ b/graphicscontext.go @@ -84,8 +84,6 @@ func (c *graphicsContext) needsRestoring(context *opengl.Context) (bool, error) } func (c *graphicsContext) initializeIfNeeded(context *opengl.Context) error { - // glViewport must be called at every frame on iOS - context.ResetViewportSize() if !c.initialized { if err := graphics.Initialize(context); err != nil { return err @@ -136,6 +134,8 @@ func (c *graphicsContext) drawToDefaultRenderTarget(context *opengl.Context) err } func (c *graphicsContext) UpdateAndDraw(context *opengl.Context, updateCount int) error { + // glViewport must be called at every frame on iOS + context.ResetViewportSize() if err := c.initializeIfNeeded(context); err != nil { return err } @@ -170,7 +170,6 @@ func (c *graphicsContext) UpdateAndDraw(context *opengl.Context, updateCount int func (c *graphicsContext) restore(context *opengl.Context) error { imageM.Lock() defer imageM.Unlock() - context.Resume() if err := graphics.Initialize(context); err != nil { return err } diff --git a/internal/graphics/program.go b/internal/graphics/program.go index e39ee1044..b60e68563 100644 --- a/internal/graphics/program.go +++ b/internal/graphics/program.go @@ -49,11 +49,13 @@ const ( float32Size = 4 ) -func Initialize(c *opengl.Context) error { - return theOpenGLState.initialize(c) +func Initialize(context *opengl.Context) error { + return theOpenGLState.initialize(context) } -func (s *openGLState) initialize(c *opengl.Context) error { +func (s *openGLState) initialize(context *opengl.Context) error { + // TODO: Rename + context.Resume() s.lastProgram = zeroProgram s.lastProjectionMatrix = nil s.lastModelviewMatrix = nil @@ -61,19 +63,19 @@ func (s *openGLState) initialize(c *opengl.Context) error { s.lastColorMatrixTranslation = nil s.lastTexture = zeroTexture - shaderVertexModelviewNative, err := c.NewShader(opengl.VertexShader, shader(c, shaderVertexModelview)) + shaderVertexModelviewNative, err := context.NewShader(opengl.VertexShader, shader(context, shaderVertexModelview)) if err != nil { panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err)) } - defer c.DeleteShader(shaderVertexModelviewNative) + defer context.DeleteShader(shaderVertexModelviewNative) - shaderFragmentTextureNative, err := c.NewShader(opengl.FragmentShader, shader(c, shaderFragmentTexture)) + shaderFragmentTextureNative, err := context.NewShader(opengl.FragmentShader, shader(context, shaderFragmentTexture)) if err != nil { panic(fmt.Sprintf("graphics: shader compiling error:\n%s", err)) } - defer c.DeleteShader(shaderFragmentTextureNative) + defer context.DeleteShader(shaderFragmentTextureNative) - s.programTexture, err = c.NewProgram([]opengl.Shader{ + s.programTexture, err = context.NewProgram([]opengl.Shader{ shaderVertexModelviewNative, shaderFragmentTextureNative, }) @@ -82,7 +84,7 @@ func (s *openGLState) initialize(c *opengl.Context) error { } const stride = 8 // (2 [vertices] + 2 [texels]) * 2 [sizeof(int16)/bytes] - c.NewBuffer(opengl.ArrayBuffer, 4*stride*MaxQuads, opengl.DynamicDraw) + context.NewBuffer(opengl.ArrayBuffer, 4*stride*MaxQuads, opengl.DynamicDraw) indices := make([]uint16, 6*MaxQuads) for i := uint16(0); i < MaxQuads; i++ { @@ -93,7 +95,7 @@ func (s *openGLState) initialize(c *opengl.Context) error { indices[6*i+4] = 4*i + 2 indices[6*i+5] = 4*i + 3 } - s.indexBufferQuads = c.NewBuffer(opengl.ElementArrayBuffer, indices, opengl.StaticDraw) + s.indexBufferQuads = context.NewBuffer(opengl.ElementArrayBuffer, indices, opengl.StaticDraw) return nil }