Exemple #1
0
// Internal function to generate a framebuffer/renderbuffer of the correct
// dimensions exactly once per execution
func getFBORBO(width, height int) *fborbo {
	p := image.Point{width, height}
	result, ok := framebuffers[p]
	if ok {
		return result
	}

	result = &fborbo{}

	result.rbo = gl.GenRenderbuffer()
	result.fbo = gl.GenFramebuffer()

	result.fbo.Bind()

	result.rbo.Bind()
	gl.RenderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT, p.X, p.Y)
	result.rbo.Unbind()

	result.rbo.FramebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT,
		gl.RENDERBUFFER)

	result.fbo.Unbind()

	framebuffers[p] = result
	return result
}
Exemple #2
0
// Internal function to generate a framebuffer/renderbuffer of the correct
// dimensions exactly once per execution
func getFBORBO(t *Texture) *fborbo {
	p := image.Point{t.W, t.H}
	result, ok := framebuffers[p]
	if ok {
		return result
	}

	result = &fborbo{}

	result.rbo = gl.GenRenderbuffer()
	OpenGLSentinel()
	result.fbo = gl.GenFramebuffer()
	OpenGLSentinel()

	result.fbo.Bind()

	result.rbo.Bind()
	gl.RenderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT, t.W, t.H)
	result.rbo.Unbind()

	result.rbo.FramebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT,
		gl.RENDERBUFFER)

	result.fbo.Unbind()

	framebuffers[image.Point{t.W, t.H}] = result
	return result
}
Exemple #3
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
}