diff --git a/internal/graphics/command.go b/internal/graphics/command.go index 5ba00aee8..cc633c588 100644 --- a/internal/graphics/command.go +++ b/internal/graphics/command.go @@ -246,9 +246,7 @@ func (c *drawImageCommand) Exec(indexOffsetInBytes int) error { } _, h := c.dst.Size() proj := f.projectionMatrix(h) - if err := theOpenGLState.useProgram(proj, c.src.texture.native, c.color); err != nil { - return err - } + theOpenGLState.useProgram(proj, c.src.texture.native, c.color) // TODO: We should call glBindBuffer here? // The buffer is already bound at begin() but it is counterintuitive. opengl.GetContext().DrawElements(opengl.Triangles, 6*n, indexOffsetInBytes) @@ -318,9 +316,7 @@ func (c *replacePixelsCommand) Exec(indexOffsetInBytes int) error { // This also happens when a fillCommand precedes a replacePixelsCommand. // TODO: Can we have a better way like optimizing commands? opengl.GetContext().Flush() - if err := opengl.GetContext().BindTexture(c.dst.texture.native); err != nil { - return err - } + opengl.GetContext().BindTexture(c.dst.texture.native) opengl.GetContext().TexSubImage2D(c.pixels, emath.NextPowerOf2Int(c.dst.width), emath.NextPowerOf2Int(c.dst.height)) return nil } diff --git a/internal/graphics/program.go b/internal/graphics/program.go index 0b184fcfb..5718ca41e 100644 --- a/internal/graphics/program.go +++ b/internal/graphics/program.go @@ -219,7 +219,7 @@ func areSameFloat32Array(a, b []float32) bool { } // useProgram uses the program (programTexture). -func (s *openGLState) useProgram(proj []float32, texture opengl.Texture, colorM affine.ColorM) error { +func (s *openGLState) useProgram(proj []float32, texture opengl.Texture, colorM affine.ColorM) { c := opengl.GetContext() program := s.programTexture @@ -280,8 +280,5 @@ func (s *openGLState) useProgram(proj []float32, texture opengl.Texture, colorM // We don't have to call gl.ActiveTexture here: GL_TEXTURE0 is the default active texture // See also: https://www.opengl.org/sdk/docs/man2/xhtml/glActiveTexture.xml - if err := c.BindTexture(texture); err != nil { - return err - } - return nil + c.BindTexture(texture) } diff --git a/internal/opengl/context.go b/internal/opengl/context.go index 8c96ce4d4..abe2f5f49 100644 --- a/internal/opengl/context.go +++ b/internal/opengl/context.go @@ -53,15 +53,12 @@ func GetContext() *Context { return theContext } -func (c *Context) BindTexture(t Texture) error { +func (c *Context) BindTexture(t Texture) { if c.lastTexture.equals(t) { - return nil - } - if err := c.bindTextureImpl(t); err != nil { - return err + return } + c.bindTextureImpl(t) c.lastTexture = t - return nil } func (c *Context) bindFramebuffer(f Framebuffer) error { diff --git a/internal/opengl/context_desktop.go b/internal/opengl/context_desktop.go index 501489e53..29cfa12b4 100644 --- a/internal/opengl/context_desktop.go +++ b/internal/opengl/context_desktop.go @@ -152,10 +152,8 @@ func (c *Context) NewTexture(width, height int, pixels []uint8, filter Filter) ( }); err != nil { return 0, err } - if err := c.BindTexture(texture); err != nil { - return 0, err - } - if err := c.runOnContextThread(func() error { + c.BindTexture(texture) + _ = c.runOnContextThread(func() error { gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, int32(filter)) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, int32(filter)) //gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP) @@ -167,9 +165,7 @@ func (c *Context) NewTexture(width, height int, pixels []uint8, filter Filter) ( } gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(width), int32(height), 0, gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(p)) return nil - }); err != nil { - return 0, err - } + }) return texture, nil } @@ -208,12 +204,11 @@ func (c *Context) FramebufferPixels(f Framebuffer, width, height int) ([]uint8, return pixels, nil } -func (c *Context) bindTextureImpl(t Texture) error { +func (c *Context) bindTextureImpl(t Texture) { _ = c.runOnContextThread(func() error { gl.BindTexture(gl.TEXTURE_2D, uint32(t)) return nil }) - return nil } func (c *Context) DeleteTexture(t Texture) { diff --git a/internal/opengl/context_js.go b/internal/opengl/context_js.go index 573831225..c64c180b0 100644 --- a/internal/opengl/context_js.go +++ b/internal/opengl/context_js.go @@ -173,9 +173,7 @@ func (c *Context) NewTexture(width, height int, pixels []uint8, filter Filter) ( return Texture{nil}, errors.New("opengl: glGenTexture failed") } gl.PixelStorei(gl.UNPACK_ALIGNMENT, 4) - if err := c.BindTexture(Texture{t}); err != nil { - return Texture{}, err - } + c.BindTexture(Texture{t}) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, int(filter)) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, int(filter)) @@ -213,10 +211,9 @@ func (c *Context) FramebufferPixels(f Framebuffer, width, height int) ([]uint8, return pixels.Interface().([]uint8), nil } -func (c *Context) bindTextureImpl(t Texture) error { +func (c *Context) bindTextureImpl(t Texture) { gl := c.gl gl.BindTexture(gl.TEXTURE_2D, t.Object) - return nil } func (c *Context) DeleteTexture(t Texture) { diff --git a/internal/opengl/context_mobile.go b/internal/opengl/context_mobile.go index cbb2a471d..ddd51a4b5 100644 --- a/internal/opengl/context_mobile.go +++ b/internal/opengl/context_mobile.go @@ -134,9 +134,7 @@ func (c *Context) NewTexture(width, height int, pixels []uint8, filter Filter) ( return Texture{}, errors.New("opengl: creating texture failed") } gl.PixelStorei(mgl.UNPACK_ALIGNMENT, 4) - if err := c.BindTexture(Texture(t)); err != nil { - return Texture{}, err - } + c.BindTexture(Texture(t)) gl.TexParameteri(mgl.TEXTURE_2D, mgl.TEXTURE_MAG_FILTER, int(filter)) gl.TexParameteri(mgl.TEXTURE_2D, mgl.TEXTURE_MIN_FILTER, int(filter)) @@ -170,10 +168,9 @@ func (c *Context) FramebufferPixels(f Framebuffer, width, height int) ([]uint8, return pixels, nil } -func (c *Context) bindTextureImpl(t Texture) error { +func (c *Context) bindTextureImpl(t Texture) { gl := c.gl gl.BindTexture(mgl.TEXTURE_2D, mgl.Texture(t)) - return nil } func (c *Context) DeleteTexture(t Texture) {