opengl: BindTexture no longer returns error

This commit is contained in:
Hajime Hoshi 2017-09-25 00:11:19 +09:00
parent 37d8bd312a
commit ade56f8176
6 changed files with 15 additions and 36 deletions

View File

@ -246,9 +246,7 @@ func (c *drawImageCommand) Exec(indexOffsetInBytes int) error {
} }
_, h := c.dst.Size() _, h := c.dst.Size()
proj := f.projectionMatrix(h) proj := f.projectionMatrix(h)
if err := theOpenGLState.useProgram(proj, c.src.texture.native, c.color); err != nil { theOpenGLState.useProgram(proj, c.src.texture.native, c.color)
return err
}
// TODO: We should call glBindBuffer here? // TODO: We should call glBindBuffer here?
// The buffer is already bound at begin() but it is counterintuitive. // The buffer is already bound at begin() but it is counterintuitive.
opengl.GetContext().DrawElements(opengl.Triangles, 6*n, indexOffsetInBytes) 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. // This also happens when a fillCommand precedes a replacePixelsCommand.
// TODO: Can we have a better way like optimizing commands? // TODO: Can we have a better way like optimizing commands?
opengl.GetContext().Flush() opengl.GetContext().Flush()
if err := opengl.GetContext().BindTexture(c.dst.texture.native); err != nil { opengl.GetContext().BindTexture(c.dst.texture.native)
return err
}
opengl.GetContext().TexSubImage2D(c.pixels, emath.NextPowerOf2Int(c.dst.width), emath.NextPowerOf2Int(c.dst.height)) opengl.GetContext().TexSubImage2D(c.pixels, emath.NextPowerOf2Int(c.dst.width), emath.NextPowerOf2Int(c.dst.height))
return nil return nil
} }

View File

@ -219,7 +219,7 @@ func areSameFloat32Array(a, b []float32) bool {
} }
// useProgram uses the program (programTexture). // 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() c := opengl.GetContext()
program := s.programTexture 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 // 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 // See also: https://www.opengl.org/sdk/docs/man2/xhtml/glActiveTexture.xml
if err := c.BindTexture(texture); err != nil { c.BindTexture(texture)
return err
}
return nil
} }

View File

@ -53,15 +53,12 @@ func GetContext() *Context {
return theContext return theContext
} }
func (c *Context) BindTexture(t Texture) error { func (c *Context) BindTexture(t Texture) {
if c.lastTexture.equals(t) { if c.lastTexture.equals(t) {
return nil return
}
if err := c.bindTextureImpl(t); err != nil {
return err
} }
c.bindTextureImpl(t)
c.lastTexture = t c.lastTexture = t
return nil
} }
func (c *Context) bindFramebuffer(f Framebuffer) error { func (c *Context) bindFramebuffer(f Framebuffer) error {

View File

@ -152,10 +152,8 @@ func (c *Context) NewTexture(width, height int, pixels []uint8, filter Filter) (
}); err != nil { }); err != nil {
return 0, err return 0, err
} }
if err := c.BindTexture(texture); err != nil { c.BindTexture(texture)
return 0, err _ = c.runOnContextThread(func() error {
}
if err := c.runOnContextThread(func() error {
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, int32(filter)) 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_MIN_FILTER, int32(filter))
//gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP) //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)) gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(width), int32(height), 0, gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(p))
return nil return nil
}); err != nil { })
return 0, err
}
return texture, nil return texture, nil
} }
@ -208,12 +204,11 @@ func (c *Context) FramebufferPixels(f Framebuffer, width, height int) ([]uint8,
return pixels, nil return pixels, nil
} }
func (c *Context) bindTextureImpl(t Texture) error { func (c *Context) bindTextureImpl(t Texture) {
_ = c.runOnContextThread(func() error { _ = c.runOnContextThread(func() error {
gl.BindTexture(gl.TEXTURE_2D, uint32(t)) gl.BindTexture(gl.TEXTURE_2D, uint32(t))
return nil return nil
}) })
return nil
} }
func (c *Context) DeleteTexture(t Texture) { func (c *Context) DeleteTexture(t Texture) {

View File

@ -173,9 +173,7 @@ func (c *Context) NewTexture(width, height int, pixels []uint8, filter Filter) (
return Texture{nil}, errors.New("opengl: glGenTexture failed") return Texture{nil}, errors.New("opengl: glGenTexture failed")
} }
gl.PixelStorei(gl.UNPACK_ALIGNMENT, 4) gl.PixelStorei(gl.UNPACK_ALIGNMENT, 4)
if err := c.BindTexture(Texture{t}); err != nil { c.BindTexture(Texture{t})
return Texture{}, err
}
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, int(filter)) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, int(filter))
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_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 return pixels.Interface().([]uint8), nil
} }
func (c *Context) bindTextureImpl(t Texture) error { func (c *Context) bindTextureImpl(t Texture) {
gl := c.gl gl := c.gl
gl.BindTexture(gl.TEXTURE_2D, t.Object) gl.BindTexture(gl.TEXTURE_2D, t.Object)
return nil
} }
func (c *Context) DeleteTexture(t Texture) { func (c *Context) DeleteTexture(t Texture) {

View File

@ -134,9 +134,7 @@ func (c *Context) NewTexture(width, height int, pixels []uint8, filter Filter) (
return Texture{}, errors.New("opengl: creating texture failed") return Texture{}, errors.New("opengl: creating texture failed")
} }
gl.PixelStorei(mgl.UNPACK_ALIGNMENT, 4) gl.PixelStorei(mgl.UNPACK_ALIGNMENT, 4)
if err := c.BindTexture(Texture(t)); err != nil { c.BindTexture(Texture(t))
return Texture{}, err
}
gl.TexParameteri(mgl.TEXTURE_2D, mgl.TEXTURE_MAG_FILTER, int(filter)) gl.TexParameteri(mgl.TEXTURE_2D, mgl.TEXTURE_MAG_FILTER, int(filter))
gl.TexParameteri(mgl.TEXTURE_2D, mgl.TEXTURE_MIN_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 return pixels, nil
} }
func (c *Context) bindTextureImpl(t Texture) error { func (c *Context) bindTextureImpl(t Texture) {
gl := c.gl gl := c.gl
gl.BindTexture(mgl.TEXTURE_2D, mgl.Texture(t)) gl.BindTexture(mgl.TEXTURE_2D, mgl.Texture(t))
return nil
} }
func (c *Context) DeleteTexture(t Texture) { func (c *Context) DeleteTexture(t Texture) {