Exemple #1
0
func (s *StencilOp) Disable() *StencilOp {
	gl.Disable(gl.STENCIL_TEST)
	s.Draw()
	s.Depth()
	s.DepthMask()
	s.DepthLT()
	return s
}
Exemple #2
0
func (s *StencilOp) NoDepth() *StencilOp {
	gl.Disable(gl.DEPTH_TEST)
	return s
}
Exemple #3
0
func (r *Receiver) DrawPortalScene(mv glm.Mat4d, stencilLevel int, depth int) {
	s := gtk.Stencil
	if depth == 0 {
		if stencilLevel > 0 {
			gl.Enable(gl.CLIP_DISTANCE0)
		}
		s.Enable().Mask(stencilLevel)
		r.DrawModel(mv, r.Data.Scene, false)
		s.Disable()
		gl.Disable(gl.CLIP_DISTANCE0)
	} else {
		s.Enable().Mask(stencilLevel).NoDraw()
		r.DrawModel(mv, r.Data.Scene, false)
		s.DepthLE().Increment()
		gl.Enable(gl.CULL_FACE)
		r.DrawModel(mv, r.Data.Portal, false)

		if r.Constants.Debug {
			r.DrawModel(mv, r.Data.Portal, true)
		}

		gl.Disable(gl.CULL_FACE)
		s.Draw().Keep()

		if stencilLevel > 0 {
			gl.Enable(gl.CLIP_DISTANCE0)
		}
		r.DrawModel(mv, r.Data.Scene, false)

		if r.Constants.Debug {
			gl.Uniform1f(r.SceneLoc.Glow, 1)
			s.Mask(stencilLevel + 1)
			r.DrawModel(mv, r.Data.Portal, true)
			gl.Uniform1f(r.SceneLoc.Glow, 0)
		}

		gl.Disable(gl.CLIP_DISTANCE0)

		//scene drawn at stencil level
		//portal are at level 1
		r.StepDown(stencilLevel + 1)
		r.Shaders.UseProgram(PROGRAM_SCENE)
		s.Enable().Depth().DepthLE().Mask(stencilLevel)
		//scene is at stencil level

		for i, portal := range r.Portals {
			s.NoDraw().Increment()
			gl.UniformMatrix4fv(r.SceneLoc.Worldview, 1, gl.FALSE, gtk.MatArray(mv))
			gl.Enable(gl.CULL_FACE)
			r.DrawGeometry(r.Data.Portal.Geometry[i], r.SceneLoc.Position, false)
			gl.Disable(gl.CULL_FACE)
			s.Draw().Keep()

			//need to clear the depth buffer on stencil level1
			r.Shaders.UseProgram(PROGRAM_FILL)
			s.NoDraw().DepthAlways().Mask(stencilLevel + 1)
			// color := gtk.DebugPallet.Pick(i)
			// gl.Uniform4fv(r.FillLoc.Color, 1, &color[0])
			r.DrawGeometry(r.Data.Fill, r.FillLoc.Position, false)
			r.Shaders.UseProgram(PROGRAM_SCENE)
			s.Enable().Depth().DepthLE().Mask(stencilLevel)

			gl.UniformMatrix4fv(r.SceneLoc.Portalview, 1, gl.FALSE, gtk.MatArray(portal.Portalview))
			w1 := mv.Mul4(portal.Transform)
			r.DrawPortalScene(w1, stencilLevel+1, depth-1)

			r.StepDown(stencilLevel + 1)
			r.Shaders.UseProgram(PROGRAM_SCENE)
			s.Enable().Depth().DepthLE().Mask(stencilLevel)
		}
		s.Disable()
	}
}