mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
opengl: BindTexture no longer returns error
This commit is contained in:
parent
37d8bd312a
commit
ade56f8176
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user