private void SetupBlendSettings(IGLGraphicsPipeline pipeline) { if (ChangesFoundInBlend(pipeline.ColorBlendEnums)) { ApplyBlendChanges(pipeline.ColorBlendEnums); mPastColorBlendEnums = pipeline.ColorBlendEnums; } }
public void Initialize() { const int NO_OF_COLOR_ATTACHMENTS = 4; mPastColorBlendEnums = mBlend.Initialize(NO_OF_COLOR_ATTACHMENTS); var initialStencilValue = mStencil.Initialize(); mPastStencilInfo = initialStencilValue; mPastFrontWriteMask = initialStencilValue.Front.WriteMask; mPastBackWriteMask = initialStencilValue.Back.WriteMask; mPastFrontStencilInfo = new GLCmdStencilFunctionInfo { CompareMask = initialStencilValue.Front.CompareMask, ReferenceMask = initialStencilValue.Front.Reference, StencilFunction = initialStencilValue.Enums.FrontStencilFunction, }; mPastBackStencilInfo = new GLCmdStencilFunctionInfo { CompareMask = initialStencilValue.Back.CompareMask, ReferenceMask = initialStencilValue.Back.Reference, StencilFunction = initialStencilValue.Enums.BackStencilFunction, }; var initialDepthValue = mDepth.Initialize(); PreviousPipeline = new GLCmdBufferPipelineItem { DepthState = initialDepthValue, StencilState = initialStencilValue.Enums, }; mPastRasterization = mRaster.Initialize(); mPastClearValues = mClear.Initialize(); }
private bool ChangesFoundInBlend(GLGraphicsPipelineBlendColorState next) { if (mPastColorBlendEnums == null && next != null) { return(true); } if (mPastColorBlendEnums != null && next == null) { return(false); } if (mPastColorBlendEnums.Attachments.Length != next.Attachments.Length) { return(true); } if (mPastColorBlendEnums.LogicOpEnable != next.LogicOpEnable) { return(true); } if (mPastColorBlendEnums.LogicOp != next.LogicOp) { return(true); } for (uint i = 0; i < next.Attachments.Length; ++i) { if (!mPastColorBlendEnums.Attachments[i].Equals(next.Attachments[i])) { return(true); } } return(false); }
private void ApplyBlendChanges(GLGraphicsPipelineBlendColorState current) { if (mPastColorBlendEnums.LogicOpEnable != current.LogicOpEnable || mPastColorBlendEnums.LogicOp != current.LogicOp) { mBlend.EnableLogicOp(current.LogicOpEnable); mBlend.LogicOp(current.LogicOp); } uint leftSize = (uint)mPastColorBlendEnums.Attachments.Length; uint rightSize = (uint)current.Attachments.Length; uint fullLoop = Math.Max(leftSize, rightSize); for (uint i = 0; i < fullLoop; ++i) { bool hasPastValue = (i < leftSize); bool hasNextValue = (i < rightSize); if (hasPastValue && hasNextValue) { var past = mPastColorBlendEnums.Attachments[i]; var next = current.Attachments[i]; // bool blendEnabled = !(next.Value.SrcColorBlendFactor == MgBlendFactor.ONE && // next.Value.DstColorBlendFactor == MgBlendFactor.ZERO && // next.Value.SrcAlphaBlendFactor == MgBlendFactor.ONE && // next.Value.DstAlphaBlendFactor == MgBlendFactor.ZERO); if (past.BlendEnable != next.BlendEnable) { mBlend.EnableBlending(i, next.BlendEnable); } if (next.SrcColorBlendFactor != past.SrcColorBlendFactor || next.DstColorBlendFactor != past.DstColorBlendFactor || next.SrcAlphaBlendFactor != past.SrcAlphaBlendFactor || next.DstAlphaBlendFactor != past.DstAlphaBlendFactor) { mBlend.ApplyBlendSeparateFunction( i, next.SrcColorBlendFactor, next.DstColorBlendFactor, next.SrcAlphaBlendFactor, next.DstAlphaBlendFactor); } if (past.ColorWriteMask != next.ColorWriteMask) { mBlend.SetColorMask(i, next.ColorWriteMask); } } else if (!hasPastValue && hasNextValue) { var next = current.Attachments[i]; // bool blendEnabled = !(next.Value.SrcColorBlendFactor == MgBlendFactor.ONE && // next.Value.DstColorBlendFactor == MgBlendFactor.ZERO && // next.Value.SrcAlphaBlendFactor == MgBlendFactor.ONE && // next.Value.DstAlphaBlendFactor == MgBlendFactor.ZERO); mBlend.EnableBlending(i, next.BlendEnable); mBlend.ApplyBlendSeparateFunction( i, next.SrcColorBlendFactor, next.DstColorBlendFactor, next.SrcAlphaBlendFactor, next.DstAlphaBlendFactor); mBlend.SetColorMask(i, next.ColorWriteMask); } } }