func (c *Context) bindFramebufferImpl(f Framebuffer) error { if err := c.runOnContextThread(func() error { gl.BindFramebuffer(gl.FRAMEBUFFER, uint32(f)) return nil }); err != nil { return err } return nil }
func (c *Context) SetViewport(f Framebuffer, width, height int) error { gl.Flush() gl.BindFramebuffer(gl.FRAMEBUFFER, uint32(f)) if err := gl.CheckFramebufferStatus(gl.FRAMEBUFFER); err != gl.FRAMEBUFFER_COMPLETE { if e := gl.GetError(); e != 0 { return errors.New(fmt.Sprintf("glBindFramebuffer failed: %d", e)) } return errors.New("glBindFramebuffer failed: the context is different?") } gl.Viewport(0, 0, int32(width), int32(height)) return nil }
func (c *Context) NewFramebuffer(texture Texture) (Framebuffer, error) { var f uint32 gl.GenFramebuffers(1, &f) gl.BindFramebuffer(gl.FRAMEBUFFER, f) gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, uint32(texture), 0) if gl.CheckFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE { return 0, errors.New("creating framebuffer failed") } return Framebuffer(f), nil }
func (c *Context) FramebufferPixels(f Framebuffer, width, height int) ([]uint8, error) { gl.Flush() gl.BindFramebuffer(gl.FRAMEBUFFER, uint32(f)) pixels := make([]uint8, 4*width*height) gl.ReadPixels(0, 0, int32(width), int32(height), gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(pixels)) if e := gl.GetError(); e != gl.NO_ERROR { return nil, errors.New(fmt.Sprintf("glReadPixels: %d", e)) } return pixels, nil }
// BindFramebuffer binds a framebuffer. // // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindFramebuffer.xhtml func BindFramebuffer(target Enum, fb Framebuffer) { gl.BindFramebuffer(uint32(target), fb.Value) }