private static void ApplyStencil(StencilFace face, StencilTestFace currentTest, StencilTestFace test) { if ((currentTest.StencilFailOperation != test.StencilFailOperation) || (currentTest.DepthFailStencilPassOperation != test.DepthFailStencilPassOperation) || (currentTest.DepthPassStencilPassOperation != test.DepthPassStencilPassOperation)) { GL.StencilOpSeparate(face, TypeConverterGL3x.To(test.StencilFailOperation), TypeConverterGL3x.To(test.DepthFailStencilPassOperation), TypeConverterGL3x.To(test.DepthPassStencilPassOperation)); currentTest.StencilFailOperation = test.StencilFailOperation; currentTest.DepthFailStencilPassOperation = test.DepthFailStencilPassOperation; currentTest.DepthPassStencilPassOperation = test.DepthPassStencilPassOperation; } if ((currentTest.Function != test.Function) || (currentTest.ReferenceValue != test.ReferenceValue) || (currentTest.Mask != test.Mask)) { GL.StencilFuncSeparate(face, TypeConverterGL3x.To(test.Function), test.ReferenceValue, test.Mask); currentTest.Function = test.Function; currentTest.ReferenceValue = test.ReferenceValue; currentTest.Mask = test.Mask; } }
/// <summary> /// Setup and enable stencil /// See <href>https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glStencilFuncSeparate.xhtml</href> /// See <href>https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glStencilOpSeparate.xhtml</href> /// See <href>https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glStencilMask.xhtml</href> /// </summary> /// <param name="refvalue">Reference value</param> /// <param name="mask">Stencil test mask (ref AND mask) func (stencil AND mask)</param> /// <param name="face">For this face (default front and back) perform stencil operation on</param> /// <param name="stencilactivebits">Which bits are allowed to change when writing V to stencil buffer</param> public GLOperationSetStencil(int refvalue = 1, int mask = 0xff, StencilFace face = StencilFace.FrontAndBack, int stencilactivebits = 0xff) { this.v = refvalue; this.mask = mask; this.face = face; this.stencilactivebits = stencilactivebits; }
/// <summary> /// Setup and enable stencil /// See <href>https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glStencilFuncSeparate.xhtml</href> /// See <href>https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glStencilOpSeparate.xhtml</href> /// See <href>https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glStencilMask.xhtml</href> /// </summary> /// <param name="refvalue">Reference value</param> /// <param name="mask">Stencil test mask (ref AND mask) func (stencil AND mask)</param> /// <param name="face">For this face (default front and back) perform stencil operation on</param> /// <param name="stencilactivebits">Which bits are allowed to change when writing V to stencil buffer</param> static public void SetStencil(int refvalue = 1, int mask = 0xff, StencilFace face = StencilFace.FrontAndBack, int stencilactivebits = 0xff) { // stencil passes always, set stencil[pixel] = v GL.StencilFuncSeparate(face, StencilFunction.Always, refvalue, mask); GL.StencilOpSeparate(face, StencilOp.Keep, //if it fails, keep stencil value StencilOp.Keep, //if depth buffer fails, Set zero StencilOp.Replace); //if passed, replace stencil value with ref value GL.StencilMask(stencilactivebits); GL.Enable(EnableCap.StencilTest); }
private static void ForceApplyRenderStateStencil(StencilFace face, StencilTestFace test) { GL.StencilOpSeparate(face, TypeConverterGL3x.To(test.StencilFailOperation), TypeConverterGL3x.To(test.DepthFailStencilPassOperation), TypeConverterGL3x.To(test.DepthPassStencilPassOperation)); GL.StencilFuncSeparate(face, TypeConverterGL3x.To(test.Function), test.ReferenceValue, test.Mask); }
/// <summary> /// Function to set the comparison type for a stencil operation. /// </summary> /// <param name="face">The face direction for the operation.</param> /// <param name="comparison">The comparison type.</param> /// <returns>The fluent builder interface.</returns> public GorgonDepthStencilStateBuilder StencilComparison(StencilFace face, Comparison comparison) { switch (face) { case StencilFace.Back: WorkingState.BackFaceStencilOp.Comparison = comparison; break; case StencilFace.Front: WorkingState.FrontFaceStencilOp.Comparison = comparison; break; } return(this); }
/// <summary> /// Function to set the operation(s) for the stencil <see cref="StencilComparison"/> result. /// </summary> /// <param name="face">The face direction for the operation.</param> /// <param name="passStencilOp">[Optional] The stencil operation if the comparison passes.</param> /// <param name="failStencilOp">[Optional] The stencil operation if the comparison fails.</param> /// <param name="depthFailOp">[Optional] The stencil operation if the depth comparison fails.</param> /// <returns>The fluent builder interface.</returns> public GorgonDepthStencilStateBuilder StencilOperation(StencilFace face, StencilOperation passStencilOp = Core.StencilOperation.Keep, StencilOperation failStencilOp = Core.StencilOperation.Keep, StencilOperation depthFailOp = Core.StencilOperation.Keep) { switch (face) { case StencilFace.Back: WorkingState.BackFaceStencilOp.PassOperation = passStencilOp; WorkingState.BackFaceStencilOp.FailOperation = failStencilOp; WorkingState.BackFaceStencilOp.DepthFailOperation = depthFailOp; break; case StencilFace.Front: WorkingState.FrontFaceStencilOp.PassOperation = passStencilOp; WorkingState.FrontFaceStencilOp.FailOperation = failStencilOp; WorkingState.FrontFaceStencilOp.DepthFailOperation = depthFailOp; break; } return(this); }
public void Apply(StencilFace face, StencilStateComponent cache) { #if !DISABLE_CACHE if ( (cache.StencilFailOp != StencilFailOp) || (cache.ZFailOp != ZFailOp) || (cache.ZPassOp != ZPassOp) ) #endif { GL.StencilOpSeparate(face, StencilFailOp, ZFailOp, ZPassOp); cache.StencilFailOp = StencilFailOp; cache.ZFailOp = ZFailOp; cache.ZPassOp = ZPassOp; } #if !DISABLE_CACHE if (cache.WriteMask != WriteMask) #endif { GL.StencilMaskSeparate(face, WriteMask); cache.WriteMask = WriteMask; } #if !DISABLE_CACHE if ( (cache.Function != Function) || (cache.Reference != Reference) || (cache.TestMask != TestMask) ) #endif { GL.StencilFuncSeparate((Version20)face, Function, Reference, TestMask); cache.Function = Function; cache.Reference = Reference; cache.TestMask = TestMask; } }
/// <summary> /// Use after drawing, setup for equal function /// </summary> /// <param name="refvalue">Reference value</param> /// <param name="mask">Stencil test mask (ref AND mask) func (stencil AND mask)</param> /// <param name="face">For this face (default front and back) perform stencil operation on</param> static public void OnlyIfEqual(int refvalue = 0, int mask = 0xff, StencilFace face = StencilFace.FrontAndBack) { // stencil passes if V == stencil[pixel] OnlyIf(StencilFunction.Equal, refvalue, mask, face); }
/// <summary> /// Use after drawing, setup for greater function /// </summary> /// <param name="refvalue">Reference value</param> /// <param name="mask">Stencil test mask (ref AND mask) func (stencil AND mask)</param> /// <param name="face">For this face (default front and back) perform stencil operation on</param> static public void OnlyIfGreater(int refvalue = 2, int mask = 0xff, StencilFace face = StencilFace.FrontAndBack) { // stencil passes if V > stencil[pixel] OnlyIf(StencilFunction.Greater, refvalue, mask, face); }
public static void StencilMaskSeparate(StencilFace face, uint mask) { glStencilMaskSeparate deleg = BaseGraphicsContext.Current.Loader.Get<glStencilMaskSeparate>(); if (deleg != null) deleg(face, mask); }
/// <summary> /// Set up the stencil condition, full control. /// See <href>https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glStencilFuncSeparate.xhtml</href> /// See <href>https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glStencilOpSeparate.xhtml</href> /// </summary> /// <param name="function">Stencil function to use</param> /// <param name="refvalue">Reference value</param> /// <param name="mask">Stencil test mask (ref AND mask) func (stencil AND mask)</param> /// <param name="face">For this face (default front and back) perform stencil operation on</param> public GLOperationStencilOnlyIf(StencilFunction function, int refvalue = 1, int mask = 0xff, StencilFace face = StencilFace.FrontAndBack) { this.f = function; this.v = refvalue; this.mask = mask; this.face = face; }
/// <summary> /// Use after drawing, setup for equal function /// See <href>https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glStencilFuncSeparate.xhtml</href> /// See <href>https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glStencilOpSeparate.xhtml</href> /// </summary> /// <param name="refvalue">Reference value</param> /// <param name="mask">Stencil test mask (ref AND mask) func (stencil AND mask)</param> /// <param name="face">For this face (default front and back) perform stencil operation on</param> public GLOperationStencilOnlyIfEqual(int refvalue = 0, int mask = 0xff, StencilFace face = StencilFace.FrontAndBack) { this.v = refvalue; this.mask = mask; this.face = face; }
public static void StencilOpSeparate(StencilFace face, StencilOp sfail, StencilOp dpfail, StencilOp dppass) { glStencilOpSeparate deleg = BaseGraphicsContext.Current.Loader.Get<glStencilOpSeparate>(); if (deleg != null) deleg(face, sfail, dpfail, dppass); }
/// <summary> /// Use after drawing, to set up next draw with stencil conditions /// Set up the stencil condition /// </summary> /// <param name="function">Stencil function</param> /// <param name="refvalue">Reference value</param> /// <param name="mask">Stencil test mask (ref AND mask) func (stencil AND mask)</param> /// <param name="face">For this face (default front and back) perform stencil operation on</param> static public void OnlyIf(StencilFunction function, int refvalue = 1, int mask = 0xff, StencilFace face = StencilFace.FrontAndBack) { // stencil passes if V op stencil[pixel] GL.StencilFuncSeparate(face, function, refvalue, mask); GL.StencilOpSeparate(face, StencilOp.Keep, //if it fails, keep stencil value StencilOp.Keep, //if depth buffer fails, keep stencil value StencilOp.Keep); //if passed, keep stencil value }
internal void ApplyState(GraphicsDevice device) { if (!this.DepthBufferEnable) { GL.Disable(EnableCap.DepthTest); } else { GL.Enable(EnableCap.DepthTest); DepthFunction func; switch (this.DepthBufferFunction) { case CompareFunction.Never: func = DepthFunction.Never; break; case CompareFunction.Less: func = DepthFunction.Less; break; case CompareFunction.LessEqual: func = DepthFunction.Lequal; break; case CompareFunction.Equal: func = DepthFunction.Equal; break; case CompareFunction.GreaterEqual: func = DepthFunction.Gequal; break; case CompareFunction.Greater: func = DepthFunction.Greater; break; case CompareFunction.NotEqual: func = DepthFunction.Notequal; break; default: func = DepthFunction.Always; break; } GL.DepthFunc(func); } GL.DepthMask(this.DepthBufferWriteEnable); if (!this.StencilEnable) { GL.Disable(EnableCap.StencilTest); } else { GL.Enable(EnableCap.StencilTest); if (this.TwoSidedStencilMode) { Version20 face1 = (Version20)1028; Version20 face2 = (Version20)1029; StencilFace face3 = StencilFace.Front; StencilFace face4 = StencilFace.Back; GL.StencilFuncSeparate(face1, DepthStencilState.GetStencilFunc(this.StencilFunction), this.ReferenceStencil, this.StencilMask); GL.StencilFuncSeparate(face2, DepthStencilState.GetStencilFunc(this.CounterClockwiseStencilFunction), this.ReferenceStencil, this.StencilMask); GL.StencilOpSeparate(face3, DepthStencilState.GetStencilOp(this.StencilFail), DepthStencilState.GetStencilOp(this.StencilDepthBufferFail), DepthStencilState.GetStencilOp(this.StencilPass)); GL.StencilOpSeparate(face4, DepthStencilState.GetStencilOp(this.CounterClockwiseStencilFail), DepthStencilState.GetStencilOp(this.CounterClockwiseStencilDepthBufferFail), DepthStencilState.GetStencilOp(this.CounterClockwiseStencilPass)); } else { GL.StencilFunc(DepthStencilState.GetStencilFunc(this.StencilFunction), this.ReferenceStencil, this.StencilMask); GL.StencilOp(DepthStencilState.GetStencilOp(this.StencilFail), DepthStencilState.GetStencilOp(this.StencilDepthBufferFail), DepthStencilState.GetStencilOp(this.StencilPass)); } } }
public static void StencilFuncSeparate(StencilFace face, StencilFunction func, int reference, uint mask) { glStencilFuncSeparate deleg = BaseGraphicsContext.Current.Loader.Get<glStencilFuncSeparate>(); if (deleg != null) deleg(face, func, reference, mask); }