示例#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
}
示例#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)
	}
}
示例#3
0
func (b *Framebuffer) Enter() {
	if b.fborbo == nil {
		maxW := 0
		maxH := 0

		for _, value := range b.Sizes {
			maxW = max(maxW, value.Width)
			maxH = max(maxH, value.Height)
		}
		b.fborbo = getFBORBO(maxW, maxH)
	}

	b.fbo.Bind()
	s := gl.CheckFramebufferStatus(gl.FRAMEBUFFER)
	if s != gl.FRAMEBUFFER_COMPLETE {
		log.Panicf("Incomplete framebuffer, reason: %x (level %d)", s, 0)
	}
}