Пример #1
0
        public override void Execute()
        {
#if !DISABLE_CACHE
            if (last == this)
            {
                return;
            }
#endif
            if (Enabled)
            {
#if !DISABLE_CACHE
                if (stateCache.Enabled == false)
#endif
                {
                    GL.Enable(EnableCap.StencilTest);
                    stateCache.Enabled = true;
                }
                if (Separate)
                {
                    Front.Apply(StencilFace.Front, stateCache.Front);
                    Back.Apply(StencilFace.Back, stateCache.Back);
                    stateCache.Separate = true;
                }
                else
                {
#if !DISABLE_CACHE
                    if (stateCache.Separate == false)
                    {
                        //  Cache already in shared state
                        Front.Apply(StencilFace.FrontAndBack, stateCache.Front);
                    }
                    else
#endif
                    {
                        //  Cache not yet in shared state - make it shared
                        Front.ApplyShared(stateCache);
                        stateCache.Separate = false;
                    }
                }
            }
            else
            {
#if !DISABLE_CACHE
                if (stateCache.Enabled == true)
#endif
                {
                    GL.Disable(EnableCap.StencilTest);
                    stateCache.Enabled = false;
                }
            }
            last = this;
        }
Пример #2
0
        public void ApplyShared(StencilState cache)
        {
#if !DISABLE_CACHE
            if (
                (cache.Front.StencilFailOp != StencilFailOp) ||
                (cache.Front.ZFailOp != ZFailOp) ||
                (cache.Front.ZPassOp != ZPassOp) ||
                (cache.Back.StencilFailOp != StencilFailOp) ||
                (cache.Back.ZFailOp != ZFailOp) ||
                (cache.Back.ZPassOp != ZPassOp)
                )
#endif
            {
                GL.StencilOp(StencilFailOp, ZFailOp, ZPassOp);
                cache.Front.StencilFailOp = cache.Back.StencilFailOp = StencilFailOp;
                cache.Front.ZFailOp       = cache.Back.ZFailOp = ZFailOp;
                cache.Front.ZPassOp       = cache.Back.ZPassOp = ZPassOp;
            }

#if !DISABLE_CACHE
            if (
                (cache.Front.WriteMask != WriteMask) ||
                (cache.Back.WriteMask != WriteMask)
                )
#endif
            {
                GL.StencilMask(WriteMask);
                cache.Front.WriteMask = cache.Back.WriteMask = WriteMask;
            }

#if !DISABLE_CACHE
            if (
                (cache.Front.Function != Function) ||
                (cache.Front.Reference != Reference) ||
                (cache.Front.TestMask != TestMask) ||
                (cache.Back.Function != Function) ||
                (cache.Back.Reference != Reference) ||
                (cache.Back.TestMask != TestMask)
                )
#endif
            {
                GL.StencilFunc(Function, Reference, TestMask);
                cache.Front.Function  = cache.Back.Function = Function;
                cache.Front.Reference = cache.Back.Reference = Reference;
                cache.Front.TestMask  = cache.Back.TestMask = TestMask;
            }
        }
Пример #3
0
        public static void ResetState()
        {
            GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Keep);
            stateCache.Front.StencilFailOp = stateCache.Back.StencilFailOp = StencilOp.Keep;
            stateCache.Front.ZFailOp       = stateCache.Back.ZFailOp = StencilOp.Keep;
            stateCache.Front.ZPassOp       = stateCache.Back.ZPassOp = StencilOp.Keep;

            GL.StencilMask(0xffff);
            stateCache.Front.WriteMask = stateCache.Back.WriteMask = 0xffff;

            GL.StencilFunc(StencilFunction.Always, 0, 0xffff);
            stateCache.Front.Function  = stateCache.Back.Function = StencilFunction.Always;
            stateCache.Front.Reference = stateCache.Back.Reference = 0;
            stateCache.Front.TestMask  = stateCache.Back.TestMask = 0xffff;

            last = null;
        }