Ejemplo n.º 1
0
// Creates a new Framebuffer.
func NewFramebuffer(w int, h int) (fb *Framebuffer, err error) {
	var (
		buffer  gl.Framebuffer
		texture gl.Texture
	)
	buffer = gl.GenFramebuffer()
	buffer.Bind()
	texture = gl.GenTexture()
	texture.Bind(gl.TEXTURE_2D)
	gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, w, h, 0, gl.RGBA, gl.UNSIGNED_BYTE, nil)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
	gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0)
	gl.DrawBuffer(gl.COLOR_ATTACHMENT0)
	if gl.CheckFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE {
		err = fmt.Errorf("Framebuffer could not be set up")
		return
	}
	fb = &Framebuffer{
		Buffer:  buffer,
		Texture: texture,
		Width:   w,
		Height:  h,
	}
	return
}
Ejemplo n.º 2
0
func (b *Framebuffer) Enter() {
	if b.fborbo == nil {
		b.fborbo = getFBORBO(b.Texture)
	}

	b.fbo.Bind()

	gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D,
		b.Texture.Texture, b.Level)

	s := gl.CheckFramebufferStatus(gl.FRAMEBUFFER)
	if s != gl.FRAMEBUFFER_COMPLETE {
		log.Panicf("Incomplete framebuffer, reason: %x", s)
	}
}
Ejemplo n.º 3
0
func (b *Framebuffer) UpdateTextures() {
	for key, value := range b.Outputs {
		gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.GLenum(int(gl.COLOR_ATTACHMENT0)+key), gl.TEXTURE_2D, value, 0)
	}

}