func (c *Context) NewFramebuffer(texture Texture) (Framebuffer, error) { var framebuffer Framebuffer var f uint32 if err := c.runOnContextThread(func() error { gl.GenFramebuffers(1, &f) // TODO: Use gl.IsFramebuffer if f <= 0 { return errors.New("opengl: creating framebuffer failed: gl.IsFramebuffer returns false") } return nil }); err != nil { return 0, err } if err := c.bindFramebuffer(Framebuffer(f)); err != nil { return 0, err } if err := c.runOnContextThread(func() error { gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, uint32(texture), 0) s := gl.CheckFramebufferStatus(gl.FRAMEBUFFER) if s != gl.FRAMEBUFFER_COMPLETE { if s != 0 { return fmt.Errorf("opengl: creating framebuffer failed: %v", s) } if e := gl.GetError(); e != gl.NO_ERROR { return fmt.Errorf("opengl: creating framebuffer failed: (glGetError) %d", e) } return fmt.Errorf("opengl: creating framebuffer failed: unknown error") } framebuffer = Framebuffer(f) return nil }); err != nil { return 0, err } return framebuffer, 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 (canvas *Canvas) attacheExtra(canvases []*Canvas) { if canvases != nil && len(canvases) > 0 { // Attach the canvas textures to the active FBO and set up MRTs. drawbuffers := []uint32{gl.COLOR_ATTACHMENT0} // Attach the canvas textures to the currently bound framebuffer. for i := 0; i < len(canvases); i++ { buf := gl.COLOR_ATTACHMENT1 + uint32(i) gl.FramebufferTexture2D(gl.FRAMEBUFFER, buf, gl.TEXTURE_2D, canvases[i].getHandle().Value, 0) drawbuffers = append(drawbuffers, buf) } // set up multiple render targets gl.DrawBuffers(int32(len(drawbuffers)), &drawbuffers[0]) } else { // Make sure the FBO is only using a single draw buffer. gl.DrawBuffer(gl.COLOR_ATTACHMENT0) } }
// FramebufferTexture2D attaches the t to the current frame buffer. // // http://www.khronos.org/opengles/sdk/docs/man3/html/glFramebufferTexture2D.xhtml func FramebufferTexture2D(target, attachment, texTarget Enum, t Texture, level int) { gl.FramebufferTexture2D(uint32(target), uint32(attachment), uint32(texTarget), t.Value, int32(level)) }