opengl: BindFramebuffer no longer returns error

This commit is contained in:
Hajime Hoshi 2017-09-25 00:14:25 +09:00
parent ade56f8176
commit b590005c7a
5 changed files with 14 additions and 30 deletions

View File

@ -61,21 +61,16 @@ func (c *Context) BindTexture(t Texture) {
c.lastTexture = t
}
func (c *Context) bindFramebuffer(f Framebuffer) error {
func (c *Context) bindFramebuffer(f Framebuffer) {
if c.lastFramebuffer.equals(f) {
return nil
}
if err := c.bindFramebufferImpl(f); err != nil {
return err
return
}
c.bindFramebufferImpl(f)
c.lastFramebuffer = f
return nil
}
func (c *Context) SetViewport(f Framebuffer, width, height int) error {
if err := c.bindFramebuffer(f); err != nil {
return err
}
c.bindFramebuffer(f)
if c.lastViewportWidth != width || c.lastViewportHeight != height {
if err := c.setViewportImpl(width, height); err != nil {
return nil

View File

@ -169,14 +169,11 @@ func (c *Context) NewTexture(width, height int, pixels []uint8, filter Filter) (
return texture, nil
}
func (c *Context) bindFramebufferImpl(f Framebuffer) error {
if err := c.runOnContextThread(func() error {
func (c *Context) bindFramebufferImpl(f Framebuffer) {
_ = c.runOnContextThread(func() error {
gl.BindFramebuffer(gl.FRAMEBUFFER, uint32(f))
return nil
}); err != nil {
return err
}
return nil
})
}
func (c *Context) FramebufferPixels(f Framebuffer, width, height int) ([]uint8, error) {
@ -187,9 +184,7 @@ func (c *Context) FramebufferPixels(f Framebuffer, width, height int) ([]uint8,
}); err != nil {
return nil, err
}
if err := c.bindFramebuffer(f); err != nil {
return nil, err
}
c.bindFramebuffer(f)
if err := c.runOnContextThread(func() error {
pixels = make([]uint8, 4*width*height)
gl.ReadPixels(0, 0, int32(width), int32(height), gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(pixels))
@ -241,8 +236,8 @@ func (c *Context) TexSubImage2D(p []uint8, width, height int) {
})
}
func (c *Context) BindScreenFramebuffer() error {
return c.bindFramebuffer(c.screenFramebuffer)
func (c *Context) BindScreenFramebuffer() {
c.bindFramebuffer(c.screenFramebuffer)
}
func (c *Context) NewFramebuffer(texture Texture) (Framebuffer, error) {
@ -258,9 +253,7 @@ func (c *Context) NewFramebuffer(texture Texture) (Framebuffer, error) {
}); err != nil {
return 0, err
}
if err := c.bindFramebuffer(Framebuffer(f)); err != nil {
return 0, err
}
c.bindFramebuffer(Framebuffer(f))
if err := c.runOnContextThread(func() error {
gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, uint32(texture), 0)
s := gl.CheckFramebufferStatus(gl.FRAMEBUFFER)

View File

@ -192,10 +192,9 @@ func (c *Context) NewTexture(width, height int, pixels []uint8, filter Filter) (
return Texture{t}, nil
}
func (c *Context) bindFramebufferImpl(f Framebuffer) error {
func (c *Context) bindFramebufferImpl(f Framebuffer) {
gl := c.gl
gl.BindFramebuffer(gl.FRAMEBUFFER, f.Object)
return nil
}
func (c *Context) FramebufferPixels(f Framebuffer, width, height int) ([]uint8, error) {

View File

@ -148,10 +148,9 @@ func (c *Context) NewTexture(width, height int, pixels []uint8, filter Filter) (
return Texture(t), nil
}
func (c *Context) bindFramebufferImpl(f Framebuffer) error {
func (c *Context) bindFramebufferImpl(f Framebuffer) {
gl := c.gl
gl.BindFramebuffer(mgl.FRAMEBUFFER, mgl.Framebuffer(f))
return nil
}
func (c *Context) FramebufferPixels(f Framebuffer, width, height int) ([]uint8, error) {

View File

@ -491,9 +491,7 @@ func (u *userInterface) loop(g GraphicsContext) error {
return err
}
// The bound framebuffer must be the default one (0) before swapping buffers.
if err := opengl.GetContext().BindScreenFramebuffer(); err != nil {
return err
}
opengl.GetContext().BindScreenFramebuffer()
_ = u.runOnMainThread(func() error {
u.swapBuffers()
return nil