コード例 #1
0
ファイル: canvas.go プロジェクト: tanema/amore
// unLoadVolatile will release the texture, framebuffer and depth buffer
func (canvas *Canvas) unLoadVolatile() {
	if gl_state.currentCanvas == canvas {
		canvas.stopGrab(false)
	}
	gl.DeleteFramebuffer(canvas.fbo)
	gl.DeleteRenderbuffer(canvas.depth_stencil)

	canvas.fbo = gl.Framebuffer{}
	canvas.depth_stencil = gl.Renderbuffer{}

	canvas.attachedCanvases = []*Canvas{}
	canvas.Texture.Release()
}
コード例 #2
0
ファイル: canvas.go プロジェクト: tanema/amore
// checkCreateStencil if a stencil is set on a canvas then we need to create
// some buffers to handle this.
func (canvas *Canvas) checkCreateStencil() bool {
	// Do nothing if we've already created the stencil buffer.
	if canvas.depth_stencil.Valid() {
		return true
	}

	if gl_state.currentCanvas != canvas {
		gl.BindFramebuffer(gl.FRAMEBUFFER, canvas.fbo)
	}

	format := gl.STENCIL_INDEX8
	attachment := gl.STENCIL_ATTACHMENT

	canvas.depth_stencil = gl.CreateRenderbuffer()
	gl.BindRenderbuffer(gl.RENDERBUFFER, canvas.depth_stencil)
	gl.RenderbufferStorage(gl.RENDERBUFFER, gl.Enum(format), int(canvas.width), int(canvas.height))

	// Attach the stencil buffer to the framebuffer object.
	gl.FramebufferRenderbuffer(gl.FRAMEBUFFER, gl.Enum(attachment), gl.RENDERBUFFER, canvas.depth_stencil)
	gl.BindRenderbuffer(gl.RENDERBUFFER, gl.Renderbuffer{})

	success := (gl.CheckFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE)

	// We don't want the stencil buffer filled with garbage.
	if success {
		gl.Clear(gl.STENCIL_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	} else {
		gl.DeleteRenderbuffer(canvas.depth_stencil)
		canvas.depth_stencil = gl.Renderbuffer{}
	}

	if gl_state.currentCanvas != nil && gl_state.currentCanvas != canvas {
		gl.BindFramebuffer(gl.FRAMEBUFFER, gl_state.currentCanvas.fbo)
	} else if gl_state.currentCanvas == nil {
		gl.BindFramebuffer(gl.FRAMEBUFFER, getDefaultFBO())
	}

	return success
}