public GLCmdBufferPipelineItem GeneratePipelineItem(IGLGraphicsPipeline pipeline) { GLGraphicsPipelineFlagBits flags = pipeline.Flags; var pipelineItem = new GLCmdBufferPipelineItem { Flags = flags, DepthState = pipeline.DepthState, StencilState = pipeline.StencilState, }; return(pipelineItem); }
private bool ChangesFoundInRasterization( GLGraphicsPipelineFlagBits next) { var mask = GLGraphicsPipelineFlagBits.CullBackFaces | GLGraphicsPipelineFlagBits.CullFrontFaces | GLGraphicsPipelineFlagBits.CullingEnabled | GLGraphicsPipelineFlagBits.ScissorTestEnabled | GLGraphicsPipelineFlagBits.UseCounterClockwiseWindings; var pastFlags = mask & mPastRasterization.Flags; var nextFlags = mask & next; return(pastFlags != nextFlags); }
private void ApplyRasterizationChanges(GLGraphicsPipelineFlagBits previous, GLGraphicsPipelineFlagBits next) { var mask = GLGraphicsPipelineFlagBits.CullingEnabled; if ((previous & mask) != (next & mask)) { if (mRaster.CullingEnabled) { mRaster.DisableCulling(); } else { mRaster.EnableCulling(); } } // culling facing face mask = GLGraphicsPipelineFlagBits.CullFrontFaces | GLGraphicsPipelineFlagBits.CullBackFaces; if ((previous & mask) != (next & mask)) { mRaster.SetCullingMode( (next & GLGraphicsPipelineFlagBits.CullFrontFaces) > 0 , (next & GLGraphicsPipelineFlagBits.CullBackFaces) > 0); } mask = GLGraphicsPipelineFlagBits.ScissorTestEnabled; if ((previous & mask) != (next & mask)) { if (mRaster.ScissorTestEnabled) { mRaster.DisableScissorTest(); } else { mRaster.EnableScissorTest(); } } mask = GLGraphicsPipelineFlagBits.UseCounterClockwiseWindings; var nextMaskValue = (next & mask); if ((previous & mask) != nextMaskValue) { mRaster.SetUsingCounterClockwiseWindings(nextMaskValue > 0); } }
void PopulatePipelineConstants(MgPipelineRasterizationStateCreateInfo rasterization) { // if (rasterization != null) // { GLGraphicsPipelineFlagBits flags = 0; flags |= ((rasterization.CullMode & MgCullModeFlagBits.FRONT_AND_BACK) > 0) ? GLGraphicsPipelineFlagBits.CullingEnabled : 0; flags |= ((rasterization.CullMode & MgCullModeFlagBits.FRONT_BIT) > 0) ? GLGraphicsPipelineFlagBits.CullFrontFaces : 0; flags |= ((rasterization.CullMode & MgCullModeFlagBits.BACK_BIT) > 0) ? GLGraphicsPipelineFlagBits.CullBackFaces : 0; flags |= (rasterization.FrontFace == MgFrontFace.COUNTER_CLOCKWISE) ? GLGraphicsPipelineFlagBits.UseCounterClockwiseWindings : 0; this.PolygonMode = rasterization.PolygonMode; this.RasterizerDiscardEnable = rasterization.RasterizerDiscardEnable; flags |= (rasterization.DepthBiasEnable) ? GLGraphicsPipelineFlagBits.DepthBiasEnabled : 0; this.DepthClampEnable = rasterization.DepthClampEnable; Flags |= flags; // } // else // { // // https://www.opengl.org/sdk/docs/man/html/glPolygonOffset.xhtml // DepthBiasConstantFactor = 0; // DepthBiasSlopeFactor = 0; // // QueueDrawItemBitFlags flags = 0; // flags |= QueueDrawItemBitFlags.CullingEnabled; // // DISABLED flags |= QueueDrawItemBitFlags.CullFrontFaces; // flags |= QueueDrawItemBitFlags.CullBackFaces; // flags |= QueueDrawItemBitFlags.UseCounterClockwiseWindings; // // // https://www.opengl.org/sdk/docs/man/html/glPolygonMode.xhtml // PolygonMode = MgPolygonMode.FILL; // // Flags |= flags; // } }
/// <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; }