示例#1
0
        /// <summary>
        /// Because depthStencilState is optional
        /// </summary>
        /// <param name="depthStencilState">Depth stencil state.</param>
        void PopulateDepthStencilState(MgPipelineDepthStencilStateCreateInfo depthStencilState)
        {
            GLGraphicsPipelineFlagBits flags = 0;

            // VULKAN DOC : The scissor test is always performed.
            //  Applications can effectively disable the scissor test by specifying a
            //  scissor rectangle that encompasses the entire framebuffer.
            flags |= GLGraphicsPipelineFlagBits.ScissorTestEnabled;

            if (depthStencilState != null)
            {
                flags |= (depthStencilState.DepthTestEnable) ? GLGraphicsPipelineFlagBits.DepthBufferEnabled : 0;
                flags |= (depthStencilState.StencilTestEnable) ? GLGraphicsPipelineFlagBits.StencilEnabled : 0;
                flags |= (depthStencilState.DepthWriteEnable) ? GLGraphicsPipelineFlagBits.DepthBufferWriteEnabled : 0;

                flags |= GLGraphicsPipelineFlagBits.TwoSidedStencilMode;

                // SAME STENCIL MODE USED FOR FRONT AND BACK
                Front = new GLGraphicsPipelineStencilMasks {
                    CompareMask = depthStencilState.Front.CompareMask,
                    WriteMask   = depthStencilState.Front.WriteMask,
                    Reference   = (int)depthStencilState.Front.Reference,
                };

                Back = new GLGraphicsPipelineStencilMasks
                {
                    CompareMask = depthStencilState.Back.CompareMask,
                    WriteMask   = depthStencilState.Back.WriteMask,
                    Reference   = (int)depthStencilState.Back.Reference,
                };

                StencilState = new GLGraphicsPipelineStencilState {
                    FrontStencilFunction = depthStencilState.Front.CompareOp,
                    FrontStencilPass     = depthStencilState.Front.PassOp,
                    FrontStencilFail     = depthStencilState.Front.FailOp,
                    FrontDepthBufferFail = depthStencilState.Front.DepthFailOp,

                    BackStencilPass     = depthStencilState.Back.PassOp,
                    BackStencilFail     = depthStencilState.Back.FailOp,
                    BackDepthBufferFail = depthStencilState.Back.DepthFailOp,
                    BackStencilFunction = depthStencilState.Back.CompareOp,
                };

                DepthState = new GLGraphicsPipelineDepthState {
                    DepthBufferFunction = depthStencilState.DepthCompareOp,
                };

                MaxDepthBounds = depthStencilState.MaxDepthBounds;
                MinDepthBounds = depthStencilState.MinDepthBounds;
            }
            else
            {
                flags |= GLGraphicsPipelineFlagBits.DepthBufferEnabled;
                flags |= GLGraphicsPipelineFlagBits.DepthBufferWriteEnabled;

                // Based on OpenGL defaults
                //flags |= (depthStencilState.StencilTestEnable) ? QueueDrawItemBitFlags.StencilEnabled : 0;
                //flags |= QueueDrawItemBitFlags.TwoSidedStencilMode;

                //			DisableStencilBuffer ();
                //			SetStencilWriteMask (~0);
                //			SetStencilFunction (MgCompareOp.ALWAYS, ~0, int.MaxValue);
                //			SetStencilOperation (MgStencilOp.KEEP, MgStencilOp.KEEP, MgStencilOp.KEEP);
                //
                //			void SetStencilFunction(
                //				MgCompareOp stencilFunction,
                //				int referenceStencil,
                //				int stencilMask);

                //			void SetStencilOperation(
                //				MgStencilOp stencilFail,
                //				MgStencilOp stencilDepthBufferFail,
                //				MgStencilOp stencilPass);

                // SAME STENCIL MODE USED FOR FRONT AND BACK
                Front = new GLGraphicsPipelineStencilMasks
                {
                    CompareMask = int.MaxValue,
                    WriteMask   = ~0U,
                    Reference   = ~0,
                };

                Back = new GLGraphicsPipelineStencilMasks
                {
                    CompareMask = int.MaxValue,
                    WriteMask   = ~0U,
                    Reference   = ~0,
                };

                StencilState = new GLGraphicsPipelineStencilState {
                    FrontStencilFunction = MgCompareOp.ALWAYS,
                    FrontStencilPass     = MgStencilOp.KEEP,
                    FrontStencilFail     = MgStencilOp.KEEP,
                    FrontDepthBufferFail = MgStencilOp.KEEP,

                    BackStencilFunction = MgCompareOp.ALWAYS,
                    BackStencilPass     = MgStencilOp.KEEP,
                    BackStencilFail     = MgStencilOp.KEEP,
                    BackDepthBufferFail = MgStencilOp.KEEP,
                };

                DepthState = new GLGraphicsPipelineDepthState {
                    DepthBufferFunction = MgCompareOp.LESS,
                };

                MinDepthBounds = 0f;
                MaxDepthBounds = 1f;
            }

            Flags |= flags;
        }
示例#2
0
        void InitiailizeDepthStateDescriptor(MgPipelineDepthStencilStateCreateInfo depthStencil)
        {
            if (depthStencil != null)
            {
                // VULKAN : If there is no depth framebuffer attachment, it is as if the depth test always passes.
                if (!depthStencil.DepthTestEnable)
                {
                    DepthCompareFunction = MgCompareOp.ALWAYS;
                }
                else
                {
                    DepthCompareFunction = depthStencil.DepthCompareOp;
                }

                DepthWriteEnabled = depthStencil.DepthWriteEnable;

                {
                    var localState = depthStencil.Back;
                    BackStencil = new AmtGraphicsPipelineStencilInfo
                    {
                        WriteMask = localState.WriteMask,
                        ReadMask  = localState.CompareMask,
                        StencilCompareFunction = localState.CompareOp,
                        DepthFailure           = localState.DepthFailOp,
                        DepthStencilPass       = localState.PassOp,
                        StencilFailure         = localState.FailOp,
                    };
                    BackStencilReference = localState.Reference;
                }


                {
                    var localState = depthStencil.Front;
                    BackStencil = new AmtGraphicsPipelineStencilInfo
                    {
                        WriteMask = localState.WriteMask,
                        ReadMask  = localState.CompareMask,
                        StencilCompareFunction = localState.CompareOp,
                        DepthFailure           = localState.DepthFailOp,
                        DepthStencilPass       = localState.PassOp,
                        StencilFailure         = localState.FailOp,
                    };
                    FrontStencilReference = localState.Reference;
                }
            }
            else
            {
                // VULKAN : If there is no depth framebuffer attachment, it is as if the depth test always passes.
                DepthCompareFunction = MgCompareOp.ALWAYS;
                DepthWriteEnabled    = true;

                // USE OPENGL DEFAULTS

                BackStencil = new AmtGraphicsPipelineStencilInfo
                {
                    WriteMask = ~0U,
                    ReadMask  = int.MaxValue,
                    StencilCompareFunction = MgCompareOp.ALWAYS,
                    DepthFailure           = MgStencilOp.KEEP,
                    DepthStencilPass       = MgStencilOp.KEEP,
                    StencilFailure         = MgStencilOp.KEEP,
                };
                BackStencilReference = ~0U;

                FrontStencil = new AmtGraphicsPipelineStencilInfo
                {
                    WriteMask = ~0U,
                    ReadMask  = int.MaxValue,
                    StencilCompareFunction = MgCompareOp.ALWAYS,
                    DepthFailure           = MgStencilOp.KEEP,
                    DepthStencilPass       = MgStencilOp.KEEP,
                    StencilFailure         = MgStencilOp.KEEP,
                };
                FrontStencilReference = ~0U;
            }
        }