Esempio n. 1
0
 private void BindStencilState(bool force)
 {
     stencilStateDirty |= force;
     if (!stencilStateDirty)
     {
         return;
     }
     if (force || stencilState.Enable != boundStencilState.Enable)
     {
         if (stencilState.Enable)
         {
             GL.Enable(EnableCap.StencilTest);
             GLHelper.CheckGLErrors();
         }
         else
         {
             GL.Disable(EnableCap.StencilTest);
             GLHelper.CheckGLErrors();
         }
         boundStencilState.Enable = stencilState.Enable;
     }
     if (force || stencilState.Enable)
     {
         if (force || stencilState.WriteMask != boundStencilState.WriteMask)
         {
             GL.StencilMask(stencilState.WriteMask);
             GLHelper.CheckGLErrors();
             boundStencilState.WriteMask = stencilState.WriteMask;
         }
         var funcDirty = force ||
                         stencilState.ReferenceValue != boundStencilState.ReferenceValue ||
                         stencilState.ReadMask != boundStencilState.ReadMask;
         if (funcDirty || stencilState.FrontFaceComparison != boundStencilState.FrontFaceComparison)
         {
             GL.StencilFuncSeparate(StencilFace.Front,
                                    (StencilFunction)GLHelper.GetGLCompareFunc(stencilState.FrontFaceComparison), stencilState.ReferenceValue, stencilState.ReadMask);
             GLHelper.CheckGLErrors();
             boundStencilState.FrontFaceComparison = stencilState.FrontFaceComparison;
         }
         if (funcDirty || stencilState.BackFaceComparison != boundStencilState.BackFaceComparison)
         {
             GL.StencilFuncSeparate(StencilFace.Back,
                                    (StencilFunction)GLHelper.GetGLCompareFunc(stencilState.BackFaceComparison), stencilState.ReferenceValue, stencilState.ReadMask);
             GLHelper.CheckGLErrors();
             boundStencilState.BackFaceComparison = stencilState.BackFaceComparison;
         }
         boundStencilState.ReferenceValue = stencilState.ReferenceValue;
         boundStencilState.ReadMask       = stencilState.ReadMask;
         if (force ||
             stencilState.FrontFaceFail != boundStencilState.FrontFaceFail ||
             stencilState.FrontFaceDepthFail != boundStencilState.FrontFaceDepthFail ||
             stencilState.FrontFacePass != boundStencilState.FrontFacePass
             )
         {
             GL.StencilOpSeparate(StencilFace.Front,
                                  (GLStencilOp)GLHelper.GetGLStencilOp(stencilState.FrontFaceFail),
                                  (GLStencilOp)GLHelper.GetGLStencilOp(stencilState.FrontFaceDepthFail),
                                  (GLStencilOp)GLHelper.GetGLStencilOp(stencilState.FrontFacePass));
             GLHelper.CheckGLErrors();
             boundStencilState.FrontFaceFail      = stencilState.FrontFaceFail;
             boundStencilState.FrontFaceDepthFail = stencilState.FrontFaceDepthFail;
             boundStencilState.FrontFacePass      = stencilState.FrontFacePass;
         }
         if (force ||
             stencilState.BackFaceFail != boundStencilState.BackFaceFail ||
             stencilState.BackFaceDepthFail != boundStencilState.BackFaceDepthFail ||
             stencilState.BackFacePass != boundStencilState.BackFacePass
             )
         {
             GL.StencilOpSeparate(StencilFace.Back,
                                  (GLStencilOp)GLHelper.GetGLStencilOp(stencilState.BackFaceFail),
                                  (GLStencilOp)GLHelper.GetGLStencilOp(stencilState.BackFaceDepthFail),
                                  (GLStencilOp)GLHelper.GetGLStencilOp(stencilState.BackFacePass));
             GLHelper.CheckGLErrors();
             boundStencilState.BackFaceFail      = stencilState.BackFaceFail;
             boundStencilState.BackFaceDepthFail = stencilState.BackFaceDepthFail;
             boundStencilState.BackFacePass      = stencilState.BackFacePass;
         }
     }
     stencilStateDirty = false;
 }