Skip to content

Commit

Permalink
Simplify two-sided stencil and make it work in Kinc
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Apr 12, 2021
1 parent e020a7f commit 09378c8
Showing 6 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -29,4 +29,4 @@
[submodule "Kinc"]
path = Kinc
url = https://github.com/Kode/Kinc.git
branch = master
branch = twosidedstencil
11 changes: 5 additions & 6 deletions Backends/HTML5/kha/js/graphics4/Graphics.hx
Original file line number Diff line number Diff line change
@@ -493,9 +493,9 @@ class Graphics implements kha.graphics4.Graphics {
setCullMode(pipe.cullMode);
setDepthMode(pipe.depthWrite, pipe.depthMode);
setStencilParameters(true, pipe.stencilFrontMode, pipe.stencilFrontBothPass, pipe.stencilFrontDepthFail, pipe.stencilFrontFail,
pipe.stencilFrontReferenceValue, pipe.stencilFrontReadMask, pipe.stencilFrontWriteMask);
pipe.stencilReferenceValue, pipe.stencilReadMask, pipe.stencilWriteMask);
setStencilParameters(false, pipe.stencilBackMode, pipe.stencilBackBothPass, pipe.stencilBackDepthFail, pipe.stencilBackFail,
pipe.stencilBackReferenceValue, pipe.stencilBackReadMask, pipe.stencilBackWriteMask);
pipe.stencilReferenceValue, pipe.stencilReadMask, pipe.stencilWriteMask);
setBlendingMode(pipe.blendSource, pipe.blendDestination, pipe.blendOperation, pipe.alphaBlendSource, pipe.alphaBlendDestination,
pipe.alphaBlendOperation);
currentPipeline = pipe;
@@ -506,10 +506,9 @@ class Graphics implements kha.graphics4.Graphics {
colorMaskAlpha = pipe.colorWriteMaskAlpha;
}

public function setStencilReferenceValue(front: Bool, value: Int): Void {
SystemImpl.gl.stencilFuncSeparate(front ? GL.FRONT : GL.BACK,
convertCompareMode(front ? currentPipeline.stencilFrontMode : currentPipeline.stencilBackMode), value,
front ? currentPipeline.stencilBackReadMask : currentPipeline.stencilBackReadMask);
public function setStencilReferenceValue(value: Int): Void {
SystemImpl.gl.stencilFuncSeparate(GL.FRONT, convertCompareMode(currentPipeline.stencilFrontMode), value, currentPipeline.stencilReadMask);
SystemImpl.gl.stencilFuncSeparate(GL.BACK, convertCompareMode(currentPipeline.stencilBackMode), value, currentPipeline.stencilReadMask);
}

public function setBool(location: kha.graphics4.ConstantLocation, value: Bool): Void {
24 changes: 15 additions & 9 deletions Backends/Kinc-hxcpp/kha/graphics4/PipelineState.hx
Original file line number Diff line number Diff line change
@@ -165,9 +165,10 @@ class PipelineState extends PipelineStateBase {
case Static(value): value;
default: 0;
}
setStates(cullMode, depthMode, stencilMode, stencilBothPass, stencilDepthFail, stencilFail, depthWrite, stencilReferenceValue,
getBlendFunc(blendSource), getBlendFunc(blendDestination), getBlendFunc(alphaBlendSource), getBlendFunc(alphaBlendDestination),
getDepthBufferBits(depthStencilAttachment), getStencilBufferBits(depthStencilAttachment));
setStates(cullMode, depthMode, stencilFrontMode, stencilFrontBothPass, stencilFrontDepthFail, stencilFrontFail, stencilBackMode, stencilBackBothPass,
stencilBackDepthFail, stencilBackFail, depthWrite, stencilReferenceValue, getBlendFunc(blendSource), getBlendFunc(blendDestination),
getBlendFunc(alphaBlendSource), getBlendFunc(alphaBlendDestination), getDepthBufferBits(depthStencilAttachment),
getStencilBufferBits(depthStencilAttachment));
linkWithStructures2(inputLayout.length > 0 ? inputLayout[0] : null, inputLayout.length > 1 ? inputLayout[1] : null,
inputLayout.length > 2 ? inputLayout[2] : null, inputLayout.length > 3 ? inputLayout[3] : null, inputLayout.length);
}
@@ -233,10 +234,14 @@ class PipelineState extends PipelineStateBase {
pipeline.depth_mode = convertCompareMode(depthMode);
pipeline.depth_write = depthWrite;
pipeline.stencil_mode = convertCompareMode(stencilMode);
pipeline.stencil_both_pass = convertStencilAction(stencilBothPass);
pipeline.stencil_depth_fail = convertStencilAction(stencilDepthFail);
pipeline.stencil_fail = convertStencilAction(stencilFail);
pipeline.stencil_front_mode = convertCompareMode(stencilFrontMode);
pipeline.stencil_front_both_pass = convertStencilAction(stencilFrontBothPass);
pipeline.stencil_front_depth_fail = convertStencilAction(stencilFrontDepthFail);
pipeline.stencil_front_fail = convertStencilAction(stencilFrontFail);
pipeline.stencil_back_mode = convertCompareMode(stencilBackMode);
pipeline.stencil_back_both_pass = convertStencilAction(stencilBackBothPass);
pipeline.stencil_back_depth_fail = convertStencilAction(stencilBackDepthFail);
pipeline.stencil_back_fail = convertStencilAction(stencilBackFail);
pipeline.stencil_reference_value = stencilReferenceValue;
pipeline.stencil_read_mask = stencilReadMask;
pipeline.stencil_write_mask = stencilWriteMask;
@@ -263,8 +268,9 @@ class PipelineState extends PipelineStateBase {
pipeline.conservative_rasterization = conservativeRasterization;
")
function setStates(cullMode: Int, depthMode: Int, stencilMode: Int, stencilBothPass: Int, stencilDepthFail: Int, stencilFail: Int, depthWrite: Bool,
stencilReferenceValue: Int, blendSource: Int, blendDestination: Int, alphaBlendSource: Int, alphaBlendDestination: Int, depthAttachmentBits: Int,
function setStates(cullMode: Int, depthMode: Int, stencilFrontMode: Int, stencilFrontBothPass: Int, stencilFrontDepthFail: Int, stencilFrontFail: Int,
stencilBackMode: Int, stencilBackBothPass: Int, stencilBackDepthFail: Int, stencilBackFail: Int, depthWrite: Bool, stencilReferenceValue: Int,
blendSource: Int, blendDestination: Int, alphaBlendSource: Int, alphaBlendDestination: Int, depthAttachmentBits: Int,
stencilAttachmentBits: Int): Void {}

@:functionCode("kinc_g4_set_pipeline(&pipeline);")
2 changes: 1 addition & 1 deletion Sources/kha/graphics4/Graphics.hx
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ interface Graphics {
function maxBoundTextures(): Int;
// function maxTextureSize(): Int;
// function supportsNonPow2Textures(): Bool;
function setStencilReferenceValue(front: Bool, value: Int): Void;
function setStencilReferenceValue(value: Int): Void;

function instancedRenderingAvailable(): Bool;

20 changes: 8 additions & 12 deletions Sources/kha/graphics4/PipelineStateBase.hx
Original file line number Diff line number Diff line change
@@ -18,17 +18,15 @@ class PipelineStateBase {
stencilFrontBothPass = StencilAction.Keep;
stencilFrontDepthFail = StencilAction.Keep;
stencilFrontFail = StencilAction.Keep;
stencilFrontReferenceValue = Static(0);
stencilFrontReadMask = 0xff;
stencilFrontWriteMask = 0xff;

stencilBackMode = CompareMode.Always;
stencilBackBothPass = StencilAction.Keep;
stencilBackDepthFail = StencilAction.Keep;
stencilBackFail = StencilAction.Keep;
stencilBackReferenceValue = Static(0);
stencilBackReadMask = 0xff;
stencilBackWriteMask = 0xff;

stencilReferenceValue = Static(0);
stencilReadMask = 0xff;
stencilWriteMask = 0xff;

blendSource = BlendingFactor.BlendOne;
blendDestination = BlendingFactor.BlendZero;
@@ -76,17 +74,15 @@ class PipelineStateBase {
public var stencilFrontBothPass: StencilAction;
public var stencilFrontDepthFail: StencilAction;
public var stencilFrontFail: StencilAction;
public var stencilFrontReferenceValue: StencilValue;
public var stencilFrontReadMask: Int;
public var stencilFrontWriteMask: Int;

public var stencilBackMode: CompareMode;
public var stencilBackBothPass: StencilAction;
public var stencilBackDepthFail: StencilAction;
public var stencilBackFail: StencilAction;
public var stencilBackReferenceValue: StencilValue;
public var stencilBackReadMask: Int;
public var stencilBackWriteMask: Int;

public var stencilReferenceValue: StencilValue;
public var stencilReadMask: Int;
public var stencilWriteMask: Int;

// One, Zero deactivates blending
public var blendSource: BlendingFactor;

0 comments on commit 09378c8

Please sign in to comment.